Updated April 7 2018: Updated with Github link
Updated February 4 2018: Updated the working demo video below with the posted code.

While I was working on the Automated Aquarium Water Changer, I wanted to design the system so that user can program and change some of the parameters without having to connect to a computer with USB. I also wanted the code to be simple enough that it should be directly imbedded into the Arduino sketch without the use of external library.

What I came up with is a number based menu system to be used with a digital rotary encoder. A digital rotary encoder is a device that can rotate indefinitely in both directions, like the volume knob used in most in-car infotainment system. Most digital rotary encoders also has a clicking button integrated.

The sketch below illustrate the menu tree system.

 Figure 1: Conceptual menu tree

Figure 1: Conceptual menu tree

A number is used to represent the location within the menu tree. When you turn the rotary encoder left or right, the number is incrementally reduced or increased. When you click the rotary encoder to make a selection, the number is multiplied by 10, which takes it to a sub menu.

The Sketch above shows that while your current position is 4, clicking would take it to the 41 submenu. Rotating the encoder 1 increment to the right takes you to 42 position. Clicking again would take you to the next submenu 421, and so on.

The menu positions that end with 0 are reserved for backing out of the submenu. For example if you are at position 420, click once takes you to 42. (The number is simply divided by 10, instead of multiplied by 10 as in the case of other positions that don't end with a 0).

The video below illustrate the working prototype.

The code (which is still work-in-progress) being developed for my aquarium project is posted below. Standard Wire.h and LiquidCrystal_I2C.h libraries used here are for the LCD display on I2C. First half of the code is mostly there to handle the digital encoder. The menu structure is in the second half.

Github link.

5 Comments