Arduino LCD Keypad Shield

Published

Introduction: Arduino LCD Keypad Shield

Step 1: Library

You will need to install the Keypad library.

Step 2: Code

Here is my modified code from the example code included with the library. I added the function to turn on the LED on digital pin 13 when the select button is pushed and to turn it back off then the select button is released.

Step 3: NOTE:

Do not changed digital pin 10. This pin is used to control the back light of the LCD. If its set to output and high it may damage you LCD shield.

Share

    Recommendations

    • Planter Challenge

      Planter Challenge
    • Make it Move Contest

      Make it Move Contest
    • Oil Contest

      Oil Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    2 Questions

    0

    I want to be able to generate random numbers when I press the select button on the keypad shield and do I need the localKey =1 or the SAMPLE-WAIT if ii want to generate random numbers when I press the select button?

    #include <LiquidCrystal.h>
    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
    #include <DFR_LCD_Keypad.h>
    #define KEY_SELECT DFR_LCD_KEYPAD_KEY_SELECT
    #define DFR_LCD_KEYPAD_KEY_SELECT_ADC_LOW 700
    #define DFR_LCD_KEYPAD_KEY_SELECT_ADC_HIGH 780
    #define DFR_LCD_KEYPAD_KEY_SELECT 4
    int localKey = 1;
    int count = 0;
    long diceOne;
    long diceTwo;
    int countDelay = 220;
    int setColumn = 0;
    int SAMPLE_WAIT;

    void setup() {
    lcd.begin(16, 2);
    lcd.setCursor(8, 0);
    lcd.print("Roll the dice!");

    }


    void buildUp() {
    lcd.clear();
    for (count = 0; count <= 16; count++) {
    lcd.setCursor(setColumn, 0);
    lcd.print(random(1, 7));
    lcd.setCursor(setColumn, 1);
    lcd.print(random(1, 7));
    delay(countDelay);
    countDelay -= 13;
    setColumn += 1;
    }
    }

    void loop() {
    if (localKey != SAMPLE_WAIT)
    {
    lcd.clear();
    lcd.setCursor(8, 0);
    lcd.print("rolling dice");
    }

    randomSeed(analogRead(0));

    diceOne = random(1, 7);
    diceTwo = random(1, 7);


    buildUp();
    lcd.clear();
    lcd.setCursor(7, 0);
    lcd.print(diceOne);
    lcd.setCursor(7, 1);
    lcd.print(diceTwo);

    if (diceOne + diceTwo == 7) {
    lcd.clear();
    lcd.setCursor(7, 0);
    lcd.print("7");
    lcd.setCursor(3, 1);
    lcd.print("The pirate");
    }

    if (diceOne + diceTwo == 5,4,3,2,6 ){
    lcd.clear();
    lcd.setCursor(7, 0);
    lcd.print("5,4,3,2,6");
    }
    }

    I downloaded your sketch but when I tried to compile it I got the following error messages:

    demo_simple:14: error: 'DFR_LCD_Keypad' does not name a type

    demo_simple.ino: In function 'void loop()':

    demo_simple:30: error: 'keypad' was not declared in this scope

    demo_simple:42: error: 'KEY_RIGHT' was not declared in this scope

    demo_simple:46: error: 'KEY_UP' was not declared in this scope

    demo_simple:50: error: 'KEY_DOWN' was not declared in this scope

    demo_simple:54: error: 'KEY_LEFT' was not declared in this scope

    demo_simple:58: error: 'KEY_SELECT' was not declared in this scope

    demo_simple:62: error: 'KEY_NONE' was not declared in this scope

    I am a newbee with Arduino but am trying to learn C++, but would appreciate any suggestions you might have to fix it. Thanks, Rob

    I got the same error when compiling on 1.8.1. I discovered that the Library file was in the wrong file directory on my PC. Once I moved it to the right spot it compiled fine for the Uno. I'm not sure if Arduino changed something with the newer IDE or I messed something up transferring everything to my new computer... I will go ahead and download the newist IDE and see if it will compile for me.

    6 more answers

    0

    Thanks. I'll make sure my files are in the correct place as well. Just very frustrating to copy someone else's code - which works - and find I can't compile it or there are error messages. Again, thanks for your help and interest.

    Thats the only thing I can think of. I uninstalled the Arduino IDE and deleted all my files, installed the newest IDE and added all my files back to the correct directory. Ran the code and it compiled with out any errors. I know it can be very frustrating, I have found many codes were their is some sort of problem. Most of the time it seems to be with the library's either something is wrong or it can't be found online anymore. Hope you get this working!

    0

    Great advice! I uninstalled then reinstalled IDE 1.8.5. Had moved all my libraries and renamed the folder. Then downloaded new libraries and made sure I put them in the right (Libraries) folder with proper names. Everything works now and I have a functional LCD shield-RTC-Uno clock! Thanks so much for your help. Regards, R

    Awesome! Glad you got it working.

    Did you download and instll the library?

    0

    I did, or at least I think I did, as they show up in the sketch. I tried in both IDE 1.8.5 (compiling error) and 1.0.5. Here are the screen shots. And thanks for your help!

    Screen Shot 2018-03-22 at 8.04.12 PM.pngScreen Shot 2018-03-22 at 8.06.59 PM.png

    6 Comments

    Thanks, your library and example sketch worked perfectly for me!

    1 reply

    the range of resistance for the up button was set too low. it is closer to 150 ohms. I fixed it in the DFR_LCD_Keypad.h file.

    .#define DFR_LCD_KEYPAD_KEY_UP_ADC_LOW 120

    #define DFR_LCD_KEYPAD_KEY_UP_ADC_HIGH 160

    works now

    Hi

    Thank you for such great information, I now have a functional LCD. The only issue is that the UP button does not work, could it be that I have a broken LCD shield? I am using a shield made by SainSmart. Thank you again

    Victor

    1 reply

    It could be the LCD shield or to code. I'm
    not sure if yours works the same as mine. You can check the shield by
    using a multimeter and check the continuity of the button and then
    follow the traces to the pins and recheck. You should only have
    continuity if the button is pressed. If that checks out it could either
    be a problem with the Arduino GPIO connectors (they ware out over time)
    or could be a problem with the library Pinout. If thats the case you can
    modify it or #define in the sketch.