Arduino – NOKIA 5110 LCD MENU to control LEDS or RELAYS

Hello world! Long time ago! Im sorry.. busy days..

Today i made a Menu to control LEDS or RELAYS on a nokia 5110 LCD screen. You can use leds or relays no need to change the code, i added 2 Schematics 1 with leds and one with relays. Follow the next step for the schematics, Code & parts list!

You need these 2 Libraries:

Adafruit_GFX.h
Adafruit_PCD8544.h

Schematic for Relays:

Nokia 5110 lcd menu

Schematic for Leds:

NOKIA 5110 LCD

Just wire it up like one of the schematics (depends on what you want to use), Leds? or Relays?… no need to change the code for this!

Parts list:

  • Arduino uno! I used the robotdyn Uno!
  • 3 relays KY-019 or 3 Leds.
  • Nokia 5110 LCD screen (Very cheap!)
  • 3 x Push Button
  • Jumper wire set
  • Breadboard (optional, you can solder something to if you like)
    Good luck! Check out our website! Arduinosensors.nl

Code:

/*
Hello world! Today i made a simple menu to control some leds or relays on a nokia 5110 LCD Screen.
You can simply add or change the menu functions, You can use leds instead of relays and visa versa,
no need to change the code.
Danny van den brande, BlueCore Tech, Arduinosensors.nl.

 */
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

boolean backlight = true;
boolean Lamp1 = true;
boolean Lamp2 = true;
boolean Lamp3 = true;
int contrast=60;

int menuitem = 1;
int page = 1;

volatile boolean up = false;
volatile boolean down = false;
volatile boolean middle = false;

int downButtonState = 0;
int upButtonState = 0;  
int selectButtonState = 0;          
int lastDownButtonState = 0;
int lastSelectButtonState = 0;
int lastUpButtonState = 0;

Adafruit_PCD8544 display = Adafruit_PCD8544( 5, 4, 3);

void setup() {

  pinMode(2, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(7,OUTPUT);
  pinMode(9,OUTPUT);//led1
  pinMode(10,OUTPUT);//led2
  pinMode(12,OUTPUT);//led3

  digitalWrite(7,HIGH); //Turn Backlight ON
  digitalWrite(9,LOW); //led1
  digitalWrite(10,LOW); //Led2
  digitalWrite(12,LOW); //Led3
  
  Serial.begin(9600);
  
  display.begin();      
  display.setContrast(contrast); //Set contrast to 50
  display.clearDisplay(); 
  display.display();   
}

void loop() {
  
  drawMenu();

  downButtonState = digitalRead(2);
  selectButtonState = digitalRead(1);
  upButtonState =   digitalRead(0);
 
  checkIfDownButtonIsPressed();
  checkIfUpButtonIsPressed();
  checkIfSelectButtonIsPressed();

  if (up && page == 1 ) {
    up = false;
    menuitem--;
    if (menuitem==0)
    {
      menuitem=4; //change to 4 or more if adding menuitems
    }      
  }else if (up && page == 2 ) {
    up = false;
    contrast--;
    setContrast();
  }


  if (down && page == 1) {
    down = false;
    menuitem++;
    if (menuitem==5) //change to 5 or more if adding a new menuitem
    {
      menuitem=1;
    }      
  }else if (down && page == 2 ) {
    down = false;
    contrast++;
    setContrast();
  }


  if (middle) {
    middle = false;
    
    if (page == 1 && menuitem==2) 
    {
      if (Lamp2) // In the example video i added a relay to void led2off and void led2on in the bottom of code.
      {
        Lamp2 = false;
        Led2Off();
        }
      else 
      {
        Lamp2 = true; 
        Led2On();
       }
    }

    if (page == 1 && menuitem==4) 
    {
      if (Lamp3) 
      {
        Lamp3 = false;
        Led3Off();
        }
      else 
      {
        Lamp3 = true; 
        Led3On();
       }
    }
//////////////////////////////////////////////////////////////////////////////////
    if(page == 1 && menuitem ==3)
    {
      if (Lamp1) 
      {
        Lamp1 = false;
        Led1Off();
        }
      else 
      {
        Lamp1 = true; 
        Led1On();
       }
    }
////////////////////////////////////////////////////////////////////////////////////////

else if (page == 1 && menuitem==1) {
      page=2;
     }
else if (page == 2) {
      page=1;
     }
   }
   
  }

  void checkIfDownButtonIsPressed()
  {
    if (downButtonState != lastDownButtonState) 
  {
    if (downButtonState == 0) 
    {
      down=true;
    }
    delay(50);
  }
   lastDownButtonState = downButtonState;
  }

void checkIfUpButtonIsPressed()
{
  if (upButtonState != lastUpButtonState) 
  {
    if (upButtonState == 0) {
      up=true;
    }
    delay(50);
  }
   lastUpButtonState = upButtonState;
}

void checkIfSelectButtonIsPressed()
{
   if (selectButtonState != lastSelectButtonState) 
  {
    if (selectButtonState == 0) {
      middle=true;
    }
    delay(50);
  }
   lastSelectButtonState = selectButtonState;
}

  
  void drawMenu()
  {
    
  if (page==1) 
  {    
    display.setTextSize(1);
    display.clearDisplay();
    display.setTextColor(BLACK, WHITE);
    display.setCursor(4, 0);
    display.print("BLUECORE TECH");
    display.drawFastHLine(0,8,83,BLACK);
    display.setCursor(0, 10);
///////////////////////////////////////   
    if (menuitem==1) 
    { 
      display.setTextColor(WHITE, BLACK);
    }
    else 
    {
      display.setTextColor(BLACK, WHITE);
    }
    display.print(">Contrast");
    display.setCursor(7, 20);
///////////////////////////////////////    
    if (menuitem==2) 
    {
      display.setTextColor(WHITE, BLACK);
    }
    else 
    {
      display.setTextColor(BLACK, WHITE);
    }    
    display.print("RELAY: ");
    
    if (Lamp2) 
    {
      display.print("ON");
    }
    else 
    {
      display.print("OFF");
    }
/////////////////////////////////////

    if (menuitem==3) 
    {
      display.setTextColor(WHITE, BLACK);
    }
    else 
    {
      display.setTextColor(BLACK, WHITE);
    }    
    display.setCursor(7, 30);
    display.print("RED: ");
    
    if (Lamp1) 
    {
      display.print("ON");
    }
    else 
    {
      display.print("OFF");
    }
/////////////////////
    if (menuitem==4) 
    {
      display.setTextColor(WHITE, BLACK);
    }
    else 
    {
      display.setTextColor(BLACK, WHITE);
    }    
    display.setCursor(7, 40);
    display.print("BLUE: ");
    
    if (Lamp3) 
    {
      display.print("ON");
    }
    else 
    {
      display.print("OFF");
    }
    display.display();
    
  }
    
 
  else if (page==2) 
  {
    
    display.setTextSize(1);
    display.clearDisplay();
    display.setTextColor(BLACK, WHITE);
    display.setCursor(15, 0);
    display.print("CONTRAST");
    display.drawFastHLine(0,10,83,BLACK);
    display.setCursor(5, 15);
    display.print("Value");
    display.setTextSize(2);
    display.setCursor(5, 25);
    display.print(contrast);
 
    display.setTextSize(2);
    display.display();
  }
  
  }
  
  void setContrast()
  {
    display.setContrast(contrast);
    display.display();
  }
/////////////////////////////////////////////////////////////////////////////
  void Led1On()// You can easily change the Led1On to Relay1On and so on
  {               //or Simply add relays instead of Leds no need to change the code for that!
    digitalWrite(9,LOW);
  }

    void Led1Off()
  {
    digitalWrite(9,HIGH);
  }
//////////////////////////////////////////////////////////////////////////////////
  void Led2On()//in the video i added a relay to this led
  {
    digitalWrite(10,LOW);
  }

    void Led2Off()
  {
    digitalWrite(10,HIGH);
  }
///////////////////////////////////////////////////////////////////////////////
    void Led3On()
  {
    digitalWrite(12,LOW);
  }

    void Led3Off()
  {
    digitalWrite(12,HIGH);
  }
Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *