Projects / LCD menu system

LCD menu system

Beginner2 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. NANOHelloPCF8574

    Wire the LCD and encoder

    LCD on A4 and A5, encoder CLK to D2, DT to D3 and SW to D4.

  2. NANO

    Upload the sketch

    The first menu item appears.

  3. NANO

    Browse

    Turn the encoder to move between items.

  4. NANO

    Edit

    Press the encoder button to edit the value, turn to change it, then press to confirm and save.

  5. NANOUSB

    Test saving

    Change a value, unplug the USB and plug it back in. The value should remain.

  6. NANO

    Add your own item

    Add a row to the items table and a line of code that uses its value.

In short

How do you build an LCD menu system?

A reusable menu on a 16 × 2 LCD with an encoder: settings, values edited in place and saved to EEPROM. You need Arduino Nano, 16x2 LCD with I2C backpack (PCF8574), Rotary encoder module (KY-040), Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data). It takes 6 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
LCD SDA and SCLNano A4 and A5I2C display
LCD VCC and GNDNano 5V and GNDSupply
Encoder CLKNano D2Rotation A
Encoder DTNano D3Rotation B
Encoder SWNano D4Push button, LOW when pressed
Encoder + and GNDNano 5V and GNDSupply

Code

Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "LiquidCrystal I2C" (Frank de Brabander). Add or rename items in the table to reuse the menu in other projects. Values are saved to EEPROM when you leave edit mode. Most LCD backpacks use address 0x27, some 0x3F.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte CLK = 2, DT = 3, SW = 4;

struct Item { const char *label; int minV, maxV, value; };
Item items[] = {
  {"Brightness", 0, 10, 5},
  {"Alarm min", 1, 60, 10},
  {"Volume", 0, 20, 8},
  {"Sound on", 0, 1, 1}
};
const byte N = sizeof(items) / sizeof(items[0]);
byte cursor = 0;
bool editing = false;
byte lastClk;

void load() { for (byte i = 0; i < N; i++) { int v = EEPROM.read(i); if (v >= items[i].minV && v <= items[i].maxV) items[i].value = v; } }
void save() { for (byte i = 0; i < N; i++) EEPROM.update(i, items[i].value); }

void draw() {
  lcd.clear();
  lcd.setCursor(0, 0);
  if (editing) lcd.print("Edit value");
  else { lcd.print("Menu "); lcd.print(cursor + 1); lcd.print("/"); lcd.print(N); }
  lcd.setCursor(0, 1); lcd.print(items[cursor].label); lcd.print(": ");
  if (editing) lcd.print("<");
  lcd.print(items[cursor].value);
  if (editing) lcd.print(">");
}

void setup() {
  pinMode(CLK, INPUT_PULLUP); pinMode(DT, INPUT_PULLUP); pinMode(SW, INPUT_PULLUP);
  lcd.init(); lcd.backlight();
  load();
  lastClk = digitalRead(CLK);
  draw();
}

void loop() {
  byte clk = digitalRead(CLK);
  if (clk != lastClk && clk == LOW) {                 // one step of rotation
    int dir = digitalRead(DT) == HIGH ? 1 : -1;
    if (editing) {
      Item &it = items[cursor];
      it.value = constrain(it.value + dir, it.minV, it.maxV);
    } else {
      cursor = (cursor + N + dir) % N;
    }
    draw();
  }
  lastClk = clk;

  if (digitalRead(SW) == LOW) {                       // press toggles between browsing and editing
    delay(30);
    while (digitalRead(SW) == LOW) {}
    editing = !editing;
    if (!editing) save();                             // save when you finish editing
    draw();
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Turn without pressingMoves up and down the items and wraps
Press then turnThe value changes within its limits
Press againReturns to browsing
Power cycleValues restored

If it does not work

Menu moves two steps per click

Some encoders give two edges per detent. Use only the falling edge as in the code.

Direction reversed

Swap the CLK and DT wires.

Values do not save

Press the button to finish editing. Saving happens on exit.

LCD blank

Check the address and the contrast trimmer.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the LCD menu system?

Arduino Nano, 16x2 LCD with I2C backpack (PCF8574), Rotary encoder module (KY-040), Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data).

How long does the LCD menu system take to build?

About 120 minutes for a beginner maker, in 6 steps.

How do I know the LCD menu system works?

Turn without pressing: Moves up and down the items and wraps. Press then turn: The value changes within its limits. Press again: Returns to browsing.

Menu moves two steps per click: what should I check?

Some encoders give two edges per detent. Use only the falling edge as in the code.

Direction reversed: what should I check?

Swap the CLK and DT wires.

Values do not save: what should I check?

Press the button to finish editing. Saving happens on exit.

LCD blank: what should I check?

Check the address and the contrast trimmer.