Projects / Knob menu selector

Knob menu selector

Beginner2.5 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Wire the knob

    G, V and S to GND, 5V and A0.

  2. NANO

    Wire the button

    D2 to GND.

  3. NANO

    Wire the display

    SDA to A4 and SCL to A5, with 5V and GND.

  4. NANO19.8 mASSD1306

    Install the libraries

    Adafruit SSD1306 and Adafruit GFX.

  5. NANO

    Upload the sketch

    The menu appears with one row highlighted.

  6. NANO

    Turn the knob

    The highlight moves down the list.

  7. NANO

    Press the button

    The action runs.

  8. NANO

    Add an item

    Change ITEMS and the menu list.

In short

How do you build a knob menu selector?

A knob module picks one of five menu items shown on an OLED, and a button runs the chosen action. You need Arduino Nano, Rotary potentiometer module (KY-style), Tactile push button 6 mm, SSD1306 OLED Display, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 150 minutes.

Level
Beginner
Time
About 150 min
Parts
6

Parts list

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

Wiring

FromToWhy
Knob module G (GND)Nano GNDCommon ground
Knob module V (5V)Nano 5VKnob power
Knob module S (signal)Nano A0Analog knob position
Select buttonNano D2 and GNDPressed pulls D2 low
OLED SDANano A4I2C data
OLED SCLNano A5I2C clock
OLED VCC and GNDNano 5V and GNDPower (check your OLED accepts 5 V)

Code

A menu on a tiny screen needs two controls: one to move and one to choose. A knob module is an ordinary pot on a small board, with ground, 5 volts and a signal pin that gives a voltage between 0 and 5 volts, which the analog input reads as a number from 0 to 1023. Dividing that range into five equal zones gives five menu positions, and the selected row is shown highlighted on the OLED. A pot signal is never perfectly steady, so a reading right at the edge of two zones would flicker between them. The sketch adds hysteresis: the selection changes only when the knob has moved a little way into the next zone, which keeps the highlight steady. A separate select button then runs the chosen action: blinking the on-board LED, counting on the display, rolling a die, showing the uptime, or an about message. Reading the knob through the analog input and the button with the internal pull-up is a pattern used in many instruments. You can add more items by changing the ITEMS value and extending the text list.

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 <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);

const int KNOB = A0, SELECT_BTN = 2;
const int ITEMS = 5;
const char *MENU[ITEMS] = {"Blink the LED", "Count to ten", "Roll a die", "Show uptime", "About"};

int selected = 0;
bool wasPressed = false;
unsigned long lastPress = 0;

void drawMenu() {
  oled.clearDisplay();
  oled.setTextSize(1);
  for (int i = 0; i < ITEMS; i++) {
    oled.setCursor(0, i * 11);
    if (i == selected) oled.setTextColor(SSD1306_BLACK, SSD1306_WHITE);   // highlighted row
    else               oled.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
    oled.print(" "); oled.print(MENU[i]); oled.print("          ");
  }
  oled.display();
}

void message(const char *a, const char *b) {
  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setCursor(0, 8);  oled.println(a);
  oled.setCursor(0, 28); oled.println(b);
  oled.display();
  delay(1500);
}

void runAction(int i) {
  char buf[24];
  if (i == 0) {
    for (int k = 0; k < 5; k++) { digitalWrite(LED_BUILTIN, HIGH); delay(150); digitalWrite(LED_BUILTIN, LOW); delay(150); }
    message("Blink done", "5 flashes");
  } else if (i == 1) {
    for (int n = 1; n <= 10; n++) {
      snprintf(buf, sizeof(buf), "%d", n);
      oled.clearDisplay(); oled.setTextSize(3); oled.setTextColor(SSD1306_WHITE);
      oled.setCursor(40, 20); oled.print(buf); oled.display();
      delay(300);
    }
  } else if (i == 2) {
    snprintf(buf, sizeof(buf), "You rolled %d", (int)random(1, 7));
    message("Dice", buf);
  } else if (i == 3) {
    snprintf(buf, sizeof(buf), "%lu seconds", millis() / 1000UL);
    message("Uptime", buf);
  } else {
    message("Knob menu", "Turn, then press");
  }
  oled.setTextSize(1);
}

void setup() {
  pinMode(SELECT_BTN, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  randomSeed(analogRead(A1));                // floating pin gives some noise
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
  drawMenu();
}

void loop() {
  int raw = analogRead(KNOB);
  int candidate = constrain(raw * ITEMS / 1024, 0, ITEMS - 1);
  // hysteresis: only change when the knob is clearly inside another zone
  int zoneCentre = selected * 1024 / ITEMS + 1024 / (2 * ITEMS);
  if (candidate != selected && abs(raw - zoneCentre) > 1024 / (2 * ITEMS) + 20) {
    selected = candidate;
    drawMenu();
  }

  bool pressed = (digitalRead(SELECT_BTN) == LOW);
  if (pressed && !wasPressed && millis() - lastPress > 40) {
    lastPress = millis();
    runAction(selected);
    drawMenu();
  }
  wasPressed = pressed;
}

Test checklist

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

CheckExpected
Power onFive menu rows, first row highlighted
Turn the knob slowlyHighlight steps through five rows without flicker
Press on Blink the LEDThe built-in LED flashes five times
Press on Roll a dieA number from 1 to 6
Press on Show uptimeSeconds since power-up

If it does not work

Blank screen

Check A4 and A5 and the OLED address.

Highlight flickers

Increase the 20 count margin in the sketch.

Knob moves the wrong way

Swap the V and G connections.

Button runs twice

Increase the 40 millisecond lockout.

Top row never highlights

Check the S pin is on A0.

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

Ask Lark AI

Common questions

What parts do I need for the knob menu selector?

Arduino Nano, Rotary potentiometer module (KY-style), Tactile push button 6 mm, SSD1306 OLED Display, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.

How long does the knob menu selector take to build?

About 150 minutes for a beginner maker, in 8 steps.

How do I know the knob menu selector works?

Power on: Five menu rows, first row highlighted. Turn the knob slowly: Highlight steps through five rows without flicker. Press on Blink the LED: The built-in LED flashes five times.

Blank screen: what should I check?

Check A4 and A5 and the OLED address.

Highlight flickers: what should I check?

Increase the 20 count margin in the sketch.

Knob moves the wrong way: what should I check?

Swap the V and G connections.

Button runs twice: what should I check?

Increase the 40 millisecond lockout.