Keypad And LCD

I have a school project and I tried to make a guessing game using arudino with keypad and LCD but when I press the keypad it won’t print to the LCD.

#include <Keypad.h>
#include <LiquidCrystal.h>
char ind;
LiquidCrystal lcd(14, 15, 16 ,17 ,18 ,19);
char randomized[10] = {‘0’,‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’};
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {

byte rowPins[ROWS] = {A0, A1, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
int LCDRow = 0;
int randomnum[4];

Keypad kp = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
bool TorF = true;

void setup(){
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(LCDRow, 0);
int LCDROW = 0;
for(int i=0; i<=3; i++){
int randomNum = random(9);
ind = randomized[randomNum];
randomnum = ind;

  • Serial.println(ind);}*

void loop(){

  • char Key = kp.getKey();*

  • if(Key){*

  • Serial.println(Key);*

  • lcd.print(Key);*

  • lcd.setCursor(++LCDRow, 0);*

  • for(int x=0; x<=3;x++){*

  • if(Key == randomnum){*

  • Serial.println(Key);*

  • }*

  • }*

  • }*

*} *

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE itself has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code” it can as you now see, be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a “.ino” file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.

Now, tell us how you went with the simple “Hello World” test program displaying on your LCD display? That was of course the first step in the project. If you cannot get that to work, you would be better off to install the “HD44780” library using the Library Manager in the IDE and work through the included examples for that library.

You can debug by the following steps with minimum code:

  1. Print "Hello World" to LCD
  2. Print the pressed key to Serial monitor
  3. Print the pressed key to LCD.

You can know where the problem come from