Special Characters Are Displaying Instead of Numbers

I want to print the number pressed from the 4x3 matrix keypad to my 20x4 lcd but instead I got a w and arrow as a result.

Here is my code.

#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//RS,EN,D4,D5,D6,D7

const byte Rows= 4; //number of rows on the keypad i.e. 4
const byte Cols= 3; //number of columns on the keypad i,e, 3

//we will definne the key map as on the key pad:

char keymap[Rows][Cols]={
{‘1’, ‘2’, ‘3’},
{‘4’, ‘5’, ‘6’},
{‘7’, ‘8’, ‘9’},
{’*’, ‘0’, ‘#’}

byte rPins[Rows]= {9, 8, 7, 6}; //Rows 0 to 3
byte cPins[Cols]= {5, 4, 3}; //Columns 0 to 2

Keypad kpd= Keypad(makeKeymap(keymap), rPins, cPins, Rows, Cols);

void setup() {
// put your setup code here, to run once:
lcd.begin(20, 4);//initializing LCD


void loop() {
// put your main code here, to run repeatedly:
char keypressed = kpd.getKey();
if (keypressed != NO_KEY)
Please help me out. Thanks.

Please edit you post to include code-tags. See How to use the forum.

And have you tried printing anything else to the LCD like a Hello World? What if you print to the Serial Monitor? And if that's garbage as well, try printing it as HEX. Please show us the result.

And a tip, don't get into the habit of extremely shorting variable names. They only get harder to remember and to read. ;) Just stick to RowPins, ColPins (may both be const) and keyboard.


Some more tips.

you: but instead I got a w and arrow as a result.

Is that a or A, w or W, and what direction was the arrow pointing ? Instead of what ? What were you typing and expecting to see ?

Did you test your screen setup with a 'hello world' -like sketch to make sure your screen setup is correct ? Most often these things happen because of either a defective connection between your Arduino and the display, or an incorrect connection between the two of them (so again either at least an incorrect wire connection, or the incorrect description in your "LiquidCrystal lcd..." line).