PROJECT 1 – “Hello World” ON LCD

Arduino LCD Keypad Shield or navigation shield which come with 6 momentary push button for menu navigation and also a 2x16 LCD. It only required to plug and use with Arduino main board and there no soldering or fly-wiring are required.

PROJECT 1

“Hello World” ON LCD

Back to Project 0                                                                                                       Go to Project 2

Arduino LCD Keypad Shield or navigation shield which come with 6 momentary push button for menu navigation and also a 2×16 LCD. It only required to plug and use with Arduino main board and there no soldering or fly-wiring are required.

———————————————————————————————————————————————————-

COMPONENT NEEDED

———————————————————————————————————————————————————-

ARDUINO LCD-KEYPAD SHIELD

———————————————————————————————————————————————————-

CONNECTION

———————————————————————————————————————————————————-
For the LCD Keypad Shield, it use total of 6-pins to control the LCD display which is pin-4,5,6,7,8,9. For LCD data, it use pin-4,5,6,7, while for the RS and Enable pin, it use pin-8 and 9. The Arduino-LCD Keypad Shield are only required to plug into the Arduino main board and there was no soldering are required such as shown in figure below.

Arduino LCD 2×16 Schematic

Arduino Keypad Schematic

———————————————————————————————————————————————————-

ADDITIONAL INFORMATION

———————————————————————————————————————————————————-
The Arduino-LCD Keypad Shield are operate in 4-bits mode. To ease user, Arduino Team have prepared the <LiquidCrystal.h> file which we only require to modified and change the pin using only. For more information please check the Arduino LCD keypad Shield schematic.

For more example of the Arduino LCD Keypad coding, please refer to this webpage.

———————————————————————————————————————————————————-

CODE OVERVIEW

———————————————————————————————————————————————————-

#include <LiquidCrystal.h>
Include the LiquidCrystal header file which is already prepared inside the Arduino libraries.

LiquidCrystal.lcd(8, 9, 4, 5, 6, 7);
In here, we set the pin using for LCD 4-bit mode by refer to Arduino Liquid Crystal webpage which is LiquidCrystal(rs, enable, d4, d5, d6, d7).

Int analogPin = A0;
Define the A0 as analogPin while assign a space to it as an integer.

Int adc_key_val[5] = {30 , 150 , 360, 535, 760};
Define the adc_key_val from 0 to 4 which contain the number inside the bracket. E.g: adc_key_val[1] = 150;

char msgs [5][15] = {“Right Key OK”,
                            “Up Key OK      ”,
                            “Down Key OK ”,
                            “Left Key OK    ”,
                            “Select Key OK”};
Define the each ASCII value in char which content of total 5 string and there was 15 ASCII value for each string.

lcd.begin(16,2);
Specified the dimension (width and height)of the LCD display.

lcd.clear();
Clear the screen of the LCD display.

lcd.print(“ CYTRON TECH.”);
Send the ASCII code to the LCD display according to the text enter.

lcd.setCursor(0,1);
Position the LCD cursor,that is set the location at which subsequent text written to the LCD will be displayed.

adc_key_in = analogRead(analogPin);
Read the value from the specified pin (analogPin) and store the value in the adc_key_in.

adc_key_in = get_key(adc_key_in);
Send the adc_key_in value to the get_key subroutine.

lcd.print(msgs[adc_key_in]);
Print the text on the msgs[] to the LCD display according to the adc_key_in.

for(k = 0; k < NUM_KEYS; k++)
Loop from k=0 to k=4.

If(input < adc_key_val[k])
Check of the value from the analogPin are less than adc_key_val[k].

return k;
Replace the original k value with the number of k from 0 to 4.

If (k >= NUM_KEYS)
k = -1;
If detected the k value are large, assign k = -1.

Back to Project 0                                                                                                        Go to Project 2

———————————————————————————————————————————————————-

ATTACHMENT

1. P1 User Manual.pdf
2. Project_1_code.zip

BUY

4 thoughts on “PROJECT 1 – “Hello World” ON LCD”

  1. #include

    //LCD pin to Arduino
    const int pin_RS = 8;
    const int pin_EN = 9;
    const int pin_d4 = 4;
    const int pin_d5 = 5;
    const int pin_d6 = 6;
    const int pin_d7 = 7;

    const int pin_BL = 10;

    LiquidCrystal lcd( pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7);

    void setup() {

    lcd.begin(16, 2);

    lcd.setCursor(0,0);

    lcd.print(“By ~ Desmond P”);
    lcd.setCursor(0,1);
    lcd.print(“Press Key:”);
    }

    void loop() {
    int x;
    x = analogRead (0);
    lcd.setCursor(10,1);
    if (x < 60) {
    lcd.print ("Right ");
    }
    else if (x < 200) {
    lcd.print ("Up ");
    }
    else if (x < 400){
    lcd.print ("Down ");
    }
    else if (x < 600){
    lcd.print ("Left ");
    }
    else if (x < 800){
    lcd.print ("Select");
    }
    }

  2. /*Testing Sample*/
    #include

    //LCD pin to Arduino
    const int pin_RS = 8;
    const int pin_EN = 9;
    const int pin_d4 = 4;
    const int pin_d5 = 5;
    const int pin_d6 = 6;
    const int pin_d7 = 7;

    const int pin_BL = 10;

    LiquidCrystal lcd( pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7);

    void setup() {

    lcd.begin(16, 2);

    lcd.setCursor(0,0);

    lcd.print(“By ~ Desmond P”);
    lcd.setCursor(0,1);
    lcd.print(“Press Key:”);
    }

    void loop() {
    int x;
    x = analogRead (0);
    lcd.setCursor(10,1);
    if (x < 60) {
    lcd.print ("Right ");
    }
    else if (x < 200) {
    lcd.print ("Up ");
    }
    else if (x < 400){
    lcd.print ("Down ");
    }
    else if (x < 600){
    lcd.print ("Left ");
    }
    else if (x < 800){
    lcd.print ("Select");
    }
    }

  3. Sample Code 1

    //Sample using LiquidCrystal library
    #include

    /*******************************************************

    This program will test the LCD panel and the buttons
    Mark Bramwell, July 2010

    ********************************************************/

    // select the pins used on the LCD panel
    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    // define some values used by the panel and buttons
    int lcd_key = 0;
    int adc_key_in = 0;
    #define btnRIGHT 0
    #define btnUP 1
    #define btnDOWN 2
    #define btnLEFT 3
    #define btnSELECT 4
    #define btnNONE 5

    // read the buttons
    int read_LCD_buttons()
    {
    adc_key_in = analogRead(0); // read the value from the sensor
    // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
    // we add approx 50 to those values and check to see if we are close
    if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
    // For V1.1 us this threshold
    if (adc_key_in < 50) return btnRIGHT;
    if (adc_key_in < 250) return btnUP;
    if (adc_key_in < 450) return btnDOWN;
    if (adc_key_in < 650) return btnLEFT;
    if (adc_key_in < 850) return btnSELECT;

    // For V1.0 comment the other threshold and use the one below:
    /*
    if (adc_key_in < 50) return btnRIGHT;
    if (adc_key_in < 195) return btnUP;
    if (adc_key_in < 380) return btnDOWN;
    if (adc_key_in < 555) return btnLEFT;
    if (adc_key_in < 790) return btnSELECT;
    */

    return btnNONE; // when all others fail, return this…
    }

    void setup()
    {
    lcd.begin(16, 2); // start the library
    lcd.setCursor(0,0);
    lcd.print("Push the buttons"); // print a simple message
    }

    void loop()
    {
    lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over
    lcd.print(millis()/1000); // display seconds elapsed since power-up

    lcd.setCursor(0,1); // move to the begining of the second line
    lcd_key = read_LCD_buttons(); // read the buttons

    switch (lcd_key) // depending on which button was pushed, we perform an action
    {
    case btnRIGHT:
    {
    lcd.print("RIGHT ");
    break;
    }
    case btnLEFT:
    {
    lcd.print("LEFT ");
    break;
    }
    case btnUP:
    {
    lcd.print("UP ");
    break;
    }
    case btnDOWN:
    {
    lcd.print("DOWN ");
    break;
    }
    case btnSELECT:
    {
    lcd.print("SELECT");
    break;
    }
    case btnNONE:
    {
    lcd.print("NONE ");
    break;
    }
    }

    }

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorail

Display Temperature and Humidity on OLED using DHT22 and Arduino
Getting Started With Teensy Using Arduino IDE
Night Light
Arduino Device Tracker Using GSM GPS SIM7600E Module
Chocolate Box with Touch Sensor and Arduino
Scroll to Top