Lithium ION
Published © GPL3+

Simple LCD MENU Using Arduino

I made my first LCD menu which can toggle 4 channel LEDs. It has a 16x2 LCD user interface and 3 tactile selection buttons.

IntermediateFull instructions provided1.5 hours14,996
Simple LCD MENU Using Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1

Software apps and online services

Pcbway
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Breadboard, 400 Pin
Breadboard, 400 Pin
10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long

Story

Read more

Schematics

Circuit diagram

Connect Led as per defined pins in code.

Circuit diagram all info with leds.

Code

Arduino Code for LED Toggle

Arduino
/* 
 *  MADE BY Lithium Ion
 */

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

int upButton = 10;
int downButton = 11;
int selectButton = 12;
int menu = 1;
int LedOut1 = 3;
int LedOut2 = 4;
int LedOut3 = 5;
int LedOut4 = 6;
int Timer = 0;
int Timer_1 = 0;
int Timer2 = 0;
int Timer3 = 0;


void setup() {
  lcd.init();
  lcd.backlight();
  pinMode(upButton, INPUT_PULLUP);
  pinMode(downButton, INPUT_PULLUP);
  pinMode(selectButton, INPUT_PULLUP);
  pinMode(LedOut1, OUTPUT);
  pinMode(LedOut2, OUTPUT);
  pinMode(LedOut3, OUTPUT);
  pinMode(LedOut4, OUTPUT);
       
  updateMenu();
}

void loop() {
  if (!digitalRead(downButton)){
    menu++;
    updateMenu();
    delay(100);
    while (!digitalRead(downButton));
  }
  if (!digitalRead(upButton)){
    menu--;
    updateMenu();
    delay(100);
    while(!digitalRead(upButton));
  }
  if (!digitalRead(selectButton)){
    executeAction();
    updateMenu();
    delay(100);
    while (!digitalRead(selectButton));
  }
}

void updateMenu() {
  switch (menu) {
    case 0:
      menu = 1;
      break;
    case 1:
      lcd.clear();
      lcd.print(">LED1");
      lcd.setCursor(0, 1);
      lcd.print(" LED2");
      break;
    case 2:
      lcd.clear();
      lcd.print(" LED1");
      lcd.setCursor(0, 1);
      lcd.print(">LED2");
      break;
    case 3:
      lcd.clear();
      lcd.print(">LED3");
      lcd.setCursor(0, 1);
      lcd.print(" LED4");
      break;
    case 4:
      lcd.clear();
      lcd.print(" LED3");
      lcd.setCursor(0, 1);
      lcd.print(">LED4");
      break;
    case 5:
      menu = 4;
      break;
  }
}

void executeAction() {
  switch (menu) {
    case 1:
      action1();
      break;
    case 2:
      action2();
      break;
    case 3:
      action3();
      break;
    case 4:
      action4();
      break;
  }
}

void action1() {
  lcd.clear();
  lcd.print(">Toggle Led #1");
  digitalWrite(LedOut1,HIGH);
  Timer++;
  if(Timer ==2){
    digitalWrite(LedOut1,LOW);
  Timer=0;
  }
  else{
    digitalWrite(LedOut1,HIGH);
  }
  delay(1500);
}
void action2() {
  lcd.clear();
  lcd.print(">Toggle Led #2");
  digitalWrite(LedOut2, HIGH);
    Timer_1++;
  if(Timer_1 ==2){
    digitalWrite(LedOut2,LOW);
  Timer_1=0;
  }
  else{
    digitalWrite(LedOut2,HIGH);
  }
  delay(1500);
}
void action3() {
  lcd.clear();
  lcd.print(">Toggle Led #3");
  digitalWrite(LedOut3, HIGH);
    Timer2++;
  if(Timer2 ==2){
    digitalWrite(LedOut3,LOW);
  Timer2=0;
  }
  else{
    digitalWrite(LedOut3,HIGH);
  }
  delay(1500);
}
void action4() {
  lcd.clear();
  lcd.print(">Toggle Led #4");
  digitalWrite(LedOut4,HIGH);
    Timer3++;
  if(Timer3 ==2){
    digitalWrite(LedOut4,LOW);
  Timer3=0;
  }
  else{
    digitalWrite(LedOut4,HIGH);
  }
  delay(1500);
}

Simple Menu

Arduino
you can modify this sketch as per needs.
/* Sketch for Tutorial 14
Author: Maximilian Hentsch
Sketch zu Arduino Tutorial 14 - Displaymen
https://www.youtube.com/watch?v=DuAG98P9Seo
*/

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

int upButton = 10;
int downButton = 11;
int selectButton = 12;
int menu = 1;

void setup() {
  lcd.begin();
  lcd.backlight();
  pinMode(upButton, INPUT_PULLUP);
  pinMode(downButton, INPUT_PULLUP);
  pinMode(selectButton, INPUT_PULLUP);
  updateMenu();
}

void loop() {
  if (!digitalRead(downButton)){
    menu++;
    updateMenu();
    delay(100);
    while (!digitalRead(downButton));
  }
  if (!digitalRead(upButton)){
    menu--;
    updateMenu();
    delay(100);
    while(!digitalRead(upButton));
  }
  if (!digitalRead(selectButton)){
    executeAction();
    updateMenu();
    delay(100);
    while (!digitalRead(selectButton));
  }
}

void updateMenu() {
  switch (menu) {
    case 0:
      menu = 1;
      break;
    case 1:
      lcd.clear();
      lcd.print(">MenuItem1");
      lcd.setCursor(0, 1);
      lcd.print(" MenuItem2");
      break;
    case 2:
      lcd.clear();
      lcd.print(" MenuItem1");
      lcd.setCursor(0, 1);
      lcd.print(">MenuItem2");
      break;
    case 3:
      lcd.clear();
      lcd.print(">MenuItem3");
      lcd.setCursor(0, 1);
      lcd.print(" MenuItem4");
      break;
    case 4:
      lcd.clear();
      lcd.print(" MenuItem3");
      lcd.setCursor(0, 1);
      lcd.print(">MenuItem4");
      break;
    case 5:
      menu = 4;
      break;
  }
}

void executeAction() {
  switch (menu) {
    case 1:
      action1();
      break;
    case 2:
      action2();
      break;
    case 3:
      action3();
      break;
    case 4:
      action4();
      break;
  }
}

void action1() {
  lcd.clear();
  lcd.print(">Executing #1");
  delay(1500);
}
void action2() {
  lcd.clear();
  lcd.print(">Executing #2");
  delay(1500);
}
void action3() {
  lcd.clear();
  lcd.print(">Executing #3");
  delay(1500);
}
void action4() {
  lcd.clear();
  lcd.print(">Executing #4");
  delay(1500);
}

Credits

Lithium ION

Lithium ION

51 projects • 33 followers
A passionate electronics DIY boy. Currently improving in Embedded systems, soldering and programming.

Comments