LCD Keypad Shield Arduino: Pinout, A0 Button Values and Menu
LCD Keypad Shield Arduino guide: 16x2 LCD pinout, A0 button values and thresholds by version, menu code, the D10 backlight problem and safe use with an ESP32.
The LCD Keypad Shield is a ready-made board that plugs straight onto an Arduino Uno and carries a 16x2 character LCD and six buttons. No soldering, breadboard or wires are needed: as soon as you plug it in, the display is connected to pins D4–D9 and the five buttons to a single analog pin, A0. So the display and keypad you need for a thermostat with a menu, a timer or a small game come in one piece, and most of the Uno's pins stay free.
In this guide we explain which pins the shield uses, how five buttons are read from one pin and why the A0 value-to-button table changes between versions. First we'll write a test sketch that shows the real button values on the display, then a menu you navigate with the buttons. You'll also see the dangerous backlight pin issue found on many shields and how to use the shield safely with an ESP32.

What is the LCD Keypad Shield and how does it work?
The heart of the shield is a 16x2 LCD with an HD44780-compatible controller. The display runs in 4-bit mode, so only four of the eight data lines (D4–D7) plus two control lines (RS, E) are used; the R/W pin is tied to ground, so the display is only ever written to. The blue trimpot in the top-left corner sets the contrast. The backlight is switched by a small transistor connected to pin D10. At the bottom, the SELECT, LEFT, UP, DOWN and RIGHT buttons are wired to A0 through a resistor ladder; the sixth button, RST, goes straight to the Arduino's reset line and restarts your code. The original design comes from DFRobot, and most shields on the market are exact copies of it.
| Feature | Value |
|---|---|
| Display | 16 columns × 2 rows, HD44780-compatible, usually white text on blue |
| Supply | 5 V (from the Uno's 5V pin) |
| Display wiring | 4-bit mode: RS D8, E D9, data D4–D7 |
| Buttons | 5 buttons on one analog pin (A0) + RST button |
| Backlight | Controlled by D10 through a transistor |
| Contrast | 10 kΩ trimpot on the board |
| Compatible boards | Uno, Mega 2560, Leonardo and Uno-shaped boards |
Pinout: which Arduino pins does the shield use?
| Shield function | Arduino pin | LiquidCrystal order | Note |
|---|---|---|---|
| LCD RS | D8 | 1st parameter | Selects command or data |
| LCD Enable | D9 | 2nd parameter | Write strobe |
| LCD D4–D7 | D4, D5, D6, D7 | 3rd–6th parameter | 4-bit data bus |
| Buttons | A0 | - | Resistor ladder, read with analogRead() |
| Backlight | D10 | - | Transistor base; see the warning below |
| RST button | RESET | - | Restarts the Arduino |
| Free pins | D0–D3, D11–D13, A1–A5 | - | For sensors, relays and I2C modules |
That's why you always declare the display with LiquidCrystal lcd(8, 9, 4, 5, 6, 7); the pins are fixed on the shield and can't be changed. Of the free pins, D2 and D3 support external interrupts, and A4 and A5 form the I2C bus, ideal for adding a temperature sensor or an RTC clock module. The conflict to watch is D10: the Ethernet shield and many SD card modules use D10 as the SPI chip select (CS) pin, which clashes with the backlight circuit. To learn more about the display itself, see the 16x2 LCD parallel wiring guide, and for an alternative that needs fewer pins, read the I2C LCD display article.
Five buttons on one pin: the A0 resistor ladder
Instead of wiring five buttons to five pins, the shield uses a resistor ladder. A0 is pulled up to 5 V through a 2 kΩ resistor; with no button pressed there are 5 V on A0 and analogRead() returns 1023. Each button connects A0 to ground through a resistor chain of a different size, forming a voltage divider. The value follows the formula ADC = 1023 × R / (R + 2000). For example, on version V1.0 the UP button selects the 330 Ω path: 1023 × 330 / 2330 ≈ 145. The RIGHT button ties A0 directly to ground, so it reads 0. There's one limitation: if you press two buttons at once, only the one with the lowest resistance, i.e. the one highest in the list, is detected.
| Button | V1.0 value | V1.1 value | V1.0 threshold | V1.1 threshold |
|---|---|---|---|---|
| RIGHT | 0 | 0 | < 72 | < 50 |
| UP | 144 | 100 | < 236 | < 178 |
| DOWN | 329 | 257 | < 417 | < 333 |
| LEFT | 505 | 410 | < 623 | < 525 |
| SELECT | 741 | 641 | < 882 | < 832 |
| Not pressed | 1023 | 1023 | Anything else | Anything else |
Step by step: first test, showing the A0 value on the display
- Plug the shield onto the Uno so the headers seat fully; make sure the metal top of the USB socket doesn't touch the shield.
- Connect the board over USB. If you only see solid blocks or nothing at all, turn the contrast trimpot slowly with a small screwdriver.
- The LiquidCrystal library ships with the Arduino IDE; there's nothing to install. Upload the code below.
- Press each button in turn and write down the A0 value shown on the bottom line; the same numbers also scroll in the Serial Monitor.
- Put the five values into the KEY_ADC array in the order RIGHT, UP, DOWN, LEFT, SELECT.
1// LCD Keypad Shield: A0 değerini ve basılan butonu göster / show the A0 value and the pressed button
2#include <LiquidCrystal.h>
3
4LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // RS, E, D4, D5, D6, D7 (shield'in sabit pinleri / fixed shield pins)
5const int BTN_PIN = A0; // 5 buton tek analog pinde / 5 buttons on one analog pin
6
7// Ölçtüğün A0 değerleri, sıra: RIGHT, UP, DOWN, LEFT, SELECT / your measured A0 values
8// V1.1: {0, 100, 257, 410, 641} V1.0: {0, 144, 329, 505, 741}
9const int KEY_ADC[5] = {0, 100, 257, 410, 641};
10const char* KEY_NAME[6] = {"RIGHT", "UP", "DOWN", "LEFT", "SELECT", "NONE"};
11
12int buttonFromAdc(int v) {
13 for (int i = 0; i < 5; i++) {
14 int next = (i < 4) ? KEY_ADC[i + 1] : 1023;
15 if (v < (KEY_ADC[i] + next) / 2) return i; // iki değerin ortası eşik / midpoint threshold
16 }
17 return 5; // basılı değil / nothing pressed
18}
19
20void setup() {
21 Serial.begin(9600);
22 lcd.begin(16, 2); // 16 sütun, 2 satır / 16 columns, 2 rows
23 lcd.print("A0 test");
24}
25
26void loop() {
27 int v = analogRead(BTN_PIN); // 0-1023
28 lcd.setCursor(0, 1);
29 lcd.print("A0=");
30 lcd.print(v);
31 lcd.print(" "); // eski rakamları sil / clear old digits
32 lcd.setCursor(9, 1);
33 lcd.print(KEY_NAME[buttonFromAdc(v)]);
34 lcd.print(" ");
35 Serial.println(v); // Seri Çizici'de de izlenebilir / also works in the Serial Plotter
36 delay(150);
37}
38Instead of fixed thresholds, the buttonFromAdc() function uses the exact midpoint between two neighbouring button values. For example, if UP reads 100 and DOWN reads 257 on a V1.1 shield, every value below 178 counts as UP. So all you have to do is enter your measured values; the thresholds are calculated automatically and leave the widest possible safety margin between two buttons. Since analogRead() takes about 100 microseconds, reading the buttons hundreds of times per second is no problem.
Menu example: navigating and changing values with the buttons
In the menu below, UP and DOWN move between lines, SELECT performs the action of the selected line, and LEFT and RIGHT decrease and increase a counter. There are four lines: switching the onboard LED on D13, a counter, the backlight and how long the board has been running. The getEvent() function only produces an event when the button state changes, filters contact bounce with a short wait, and starts changing the value quickly half a second after you hold LEFT or RIGHT. The display is only redrawn when something changes, so it doesn't flicker. For bigger, multi-level menus, see the Arduino LCD menu article.
1// LCD Keypad Shield menü örneği / menu example
2#include <LiquidCrystal.h>
3
4LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
5const int BTN_PIN = A0;
6const int BACKLIGHT_PIN = 10; // arka ışık: asla OUTPUT HIGH yapma / backlight: never OUTPUT HIGH
7const int LED_PIN = 13; // kart üzerindeki LED / onboard LED
8const int KEY_ADC[5] = {0, 100, 257, 410, 641}; // V1.1; V1.0: {0, 144, 329, 505, 741}
9enum { BTN_RIGHT, BTN_UP, BTN_DOWN, BTN_LEFT, BTN_SELECT, BTN_NONE };
10
11const char* ITEMS[] = {"LED (D13)", "Sayac", "Arka isik", "Calisma suresi"};
12const byte ITEM_COUNT = 4;
13byte current = 0; // seçili menü satırı / selected menu item
14bool ledOn = false, lightOn = true;
15int counter = 0;
16int lastBtn = BTN_NONE;
17unsigned long pressedAt = 0, lastRepeat = 0, lastDraw = 0;
18
19int readButton() {
20 int v = analogRead(BTN_PIN);
21 for (int i = 0; i < 5; i++) {
22 int next = (i < 4) ? KEY_ADC[i + 1] : 1023;
23 if (v < (KEY_ADC[i] + next) / 2) return i;
24 }
25 return BTN_NONE;
26}
27
28// Yeni basışta ya da basılı tutulunca olay üret / produce an event on a new press or while held
29int getEvent() {
30 int b = readButton();
31 unsigned long now = millis();
32 if (b != lastBtn) { // durum değişti / state changed
33 delay(20); // kontak sıçraması / contact bounce
34 if (readButton() != b) return BTN_NONE;
35 lastBtn = b;
36 pressedAt = lastRepeat = now;
37 return b; // bırakınca BTN_NONE döner / returns BTN_NONE on release
38 }
39 if ((b == BTN_LEFT || b == BTN_RIGHT) && now - pressedAt > 500 && now - lastRepeat > 150) {
40 lastRepeat = now; // basılı tutunca hızlı değişim / auto-repeat while held
41 return b;
42 }
43 return BTN_NONE;
44}
45
46// Güvenli arka ışık kontrolü / safe backlight control
47void setBacklight(bool on) {
48 if (on) {
49 pinMode(BACKLIGHT_PIN, INPUT); // shield'deki pull-up yakar / the shield's pull-up turns it on
50 } else {
51 digitalWrite(BACKLIGHT_PIN, LOW); // önce LOW, sonra çıkış / LOW first, then output
52 pinMode(BACKLIGHT_PIN, OUTPUT);
53 }
54}
55
56void drawScreen() {
57 lcd.clear();
58 lcd.print('>');
59 lcd.print(ITEMS[current]);
60 lcd.setCursor(0, 1);
61 switch (current) {
62 case 0: lcd.print(ledOn ? "ACIK [SELECT]" : "KAPALI [SELECT]"); break;
63 case 1: lcd.print("< "); lcd.print(counter); lcd.print(" >"); break;
64 case 2: lcd.print(lightOn ? "ACIK [SELECT]" : "KAPALI [SELECT]"); break;
65 default: lcd.print(millis() / 1000); lcd.print(" sn"); break;
66 }
67}
68
69void setup() {
70 pinMode(LED_PIN, OUTPUT);
71 setBacklight(true);
72 lcd.begin(16, 2);
73 drawScreen();
74}
75
76void loop() {
77 bool changed = true;
78 switch (getEvent()) {
79 case BTN_UP: current = (current + ITEM_COUNT - 1) % ITEM_COUNT; break;
80 case BTN_DOWN: current = (current + 1) % ITEM_COUNT; break;
81 case BTN_LEFT: if (current == 1) counter--; else changed = false; break;
82 case BTN_RIGHT: if (current == 1) counter++; else changed = false; break;
83 case BTN_SELECT:
84 if (current == 0) { ledOn = !ledOn; digitalWrite(LED_PIN, ledOn); }
85 else if (current == 1) counter = 0; // sayacı sıfırla / reset the counter
86 else if (current == 2) { lightOn = !lightOn; setBacklight(lightOn); }
87 else changed = false;
88 break;
89 default: changed = false;
90 }
91 if (changed || (current == 3 && millis() - lastDraw >= 1000)) { // süre her saniye yenilenir / uptime refreshes every second
92 lastDraw = millis();
93 drawScreen();
94 }
95}
96| Code part | What it does |
|---|---|
| enum { BTN_RIGHT, … } | Names the buttons; the order matches the KEY_ADC array |
| getEvent() | Separates new presses, releases and held buttons |
| delay(20) and a second read | Filters contact bounce; if the same value isn't read again, the event is ignored |
| 500 ms / 150 ms | When held, repeats about 7 steps per second after half a second |
| setBacklight() | Switches the backlight without harming D10 |
| (current + ITEM_COUNT - 1) % ITEM_COUNT | Going up from the first line wraps around to the last |
The backlight pin (D10) problem
On most shields on the market, D10 is connected to the base of the NPN transistor that drives the backlight without a resistor; the only other part is a resistor on the board that pulls the base up. When you run pinMode(10, OUTPUT) and digitalWrite(10, HIGH), the Arduino pin pushes current straight into the base-emitter junction, which is clamped at 0.7 V. That current can exceed the pin's 40 mA absolute maximum; over time the ATmega328P's output stage degrades, or the pin burns out completely. The telltale signs are a board that gets warm while D10 is HIGH or a sudden jump in the current drawn from USB. You'll find the pin current limits in detail in the Arduino pin current limit article.
| What do you want to do? | Safe method | Avoid |
|---|---|---|
| Turn the backlight on | pinMode(10, INPUT) | pinMode(10, OUTPUT) + digitalWrite(10, HIGH) |
| Turn the backlight off | digitalWrite(10, LOW) + pinMode(10, OUTPUT) | Toggling the pin quickly between HIGH and LOW |
| Dim the backlight | analogWrite() after adding a 1 kΩ resistor between D10 and the base | analogWrite(10, …) without a resistor |
| Add an Ethernet or SD module | Move the module's CS pin to another pin | Both circuits using D10 |
ESP32 compatibility: what to watch out for
Plugging the shield straight onto Uno-shaped ESP32 boards (WEMOS D1 R32, ESPDuino-32) looks tempting, but there are two dangers. First, because the button ladder is pulled up to 5 V, A0 sees 5 V whenever no button is pressed; on these boards A0 is GPIO 2, and ESP32 pins can't tolerate more than 3.3 V. Second, the LCD's RS line lands on D8, which is the boot strapping pin GPIO 12; the LCD controller has weak pull-ups on some inputs, so GPIO 12 may read HIGH at boot and the board may not start. The display itself is not a problem: HD44780 inputs accept 2.2 V as HIGH, and since R/W is grounded, the display never sends a signal to the ESP32. The safest approach is to wire the shield to an ESP32 DevKit with jumper wires and bring the A0 output below 3 V with a 15 kΩ + 22 kΩ divider.
| Shield pin | ESP32 DevKit | Note |
|---|---|---|
| 5V | VIN (5 V) | The LCD and backlight run on 5 V |
| GND | GND | Common ground |
| D8 (RS) | GPIO 22 | Safe GPIO that isn't a strapping pin |
| D9 (E) | GPIO 23 | Safe GPIO |
| D4, D5, D6, D7 | GPIO 16, 17, 18, 19 | 4-bit data bus |
| A0 (buttons) | GPIO 34 through 15 kΩ | 22 kΩ between GPIO 34 and GND; about 2.8 V at most |
| D10 (backlight) | Leave unconnected | Thanks to the shield's pull-up, the backlight stays on |
1// ESP32 DevKit + LCD Keypad Shield (jumper kabloyla) / wired with jumper cables
2#include <LiquidCrystal.h>
3
4LiquidCrystal lcd(22, 23, 16, 17, 18, 19); // RS, E, D4, D5, D6, D7
5const int BTN_PIN = 34; // A0 -> 15 kΩ -> GPIO 34, GPIO 34 -> 22 kΩ -> GND
6// Bölücüden sonraki mV (V1.1 tahmini, kendi ölçümünle değiştir) / mV after the divider (V1.1 estimate, use your own)
7const int KEY_MV[5] = {0, 290, 740, 1170, 1800}; // RIGHT, UP, DOWN, LEFT, SELECT
8const int NONE_MV = 2820; // buton yokken / no button pressed
9const char* KEY_NAME[6] = {"RIGHT", "UP", "DOWN", "LEFT", "SELECT", "NONE"};
10
11int buttonFromMv(int mv) {
12 for (int i = 0; i < 5; i++) {
13 int next = (i < 4) ? KEY_MV[i + 1] : NONE_MV;
14 if (mv < (KEY_MV[i] + next) / 2) return i; // orta nokta eşiği / midpoint threshold
15 }
16 return 5;
17}
18
19void setup() {
20 Serial.begin(115200);
21 lcd.begin(16, 2);
22 lcd.print("ESP32 + Keypad");
23}
24
25void loop() {
26 int mv = analogReadMilliVolts(BTN_PIN); // kalibre edilmiş mV / calibrated millivolts
27 lcd.setCursor(0, 1);
28 lcd.print(mv);
29 lcd.print(" mV ");
30 lcd.setCursor(9, 1);
31 lcd.print(KEY_NAME[buttonFromMv(mv)]);
32 lcd.print(" ");
33 Serial.println(mv); // kalibrasyon için / for calibration
34 delay(150);
35}
36The ESP32 sketch uses calibrated millivolts from analogReadMilliVolts() instead of raw ADC counts, because the ESP32's ADC isn't linear near the ends of its range. The numbers in the KEY_MV array are estimates calculated for a V1.1 shield with the 15 kΩ + 22 kΩ divider; just as on the Uno, press each button, put the mV values shown on the bottom line into the array, and you can port the menu sketch to the ESP32 with the same logic. GPIO 34 is on ADC1, so it keeps working with Wi-Fi on, which lets you build projects that send a value chosen in the menu to the internet.
LCD Keypad Shield project ideas
- Thermostat: measure the temperature with a DS18B20, set the target with UP and DOWN and control a heater with a relay (Arduino thermostat).
- Alarm clock: show the time with an RTC module and set the alarm from the menu (Arduino alarm clock).
- Egg incubator: change temperature and humidity targets with the buttons and set the turning interval (Arduino incubator).
- Display game: make a small runner or reaction game with custom characters (Arduino game projects).
- Lab timer: choose the time with LEFT and RIGHT, start it with SELECT and sound a buzzer when it's up.
Common mistakes and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Solid blocks on the top line | Contrast not set or lcd.begin() didn't run | Turn the trimpot and check that the LiquidCrystal pins are 8, 9, 4, 5, 6, 7 |
| Display blank, backlight on | Contrast far too low | Turn the trimpot the other way |
| The wrong button is detected | Thresholds written for another version | Measure the values with the test sketch and update KEY_ADC |
| No button works, A0 always reads 1023 | Shield not seated or A0 connected to another circuit | Re-seat the shield and don't connect anything else to A0 |
| The board gets warm, backlight won't turn off | D10 was set to OUTPUT HIGH | Use the setBacklight() method and never set D10 HIGH |
| Garbage characters on the display | Noise or printing before lcd.begin() | Move lcd.begin(16, 2) to the start of setup() and try another USB cable |
If you want to try the LCD and button logic step by step before buying the shield, the BlueGrays app has projects such as printing a message on a 2x16 LCD, scrolling text on an LCD and a digital voltmeter with an LCD, each with a circuit diagram and ready-made code; the LCD Keypad Shield simply puts the same display and ready-made buttons on one board.
Frequently asked questions
Which pins does the LCD Keypad Shield use?
The display uses D4, D5, D6, D7, D8 (RS) and D9 (Enable), the five buttons use A0 and the backlight uses D10. In code you declare the display with LiquidCrystal lcd(8, 9, 4, 5, 6, 7). D0–D3, D11–D13 and A1–A5 stay free.
How do I read the LCD Keypad Shield buttons?
The buttons are wired to A0 through a resistor ladder, so the value from analogRead(A0) tells you which button is pressed. On version V1.1 the values are about 0, 100, 257, 410 and 641. Using the midpoint between two neighbouring values as the threshold is the safest approach.
Why is my LCD Keypad Shield display blank?
Most often the contrast isn't set; turn the blue trimpot on the board with a small screwdriver. If you see solid blocks on the top line, the display has power but wasn't initialised; check that the LiquidCrystal pins are 8, 9, 4, 5, 6, 7 and that lcd.begin(16, 2) is called.
Can I press two buttons at the same time?
No. All buttons share one analog pin, so when two are pressed only the one with the lowest resistance is detected, usually RIGHT or UP. If you need multiple keys at once, wire the buttons to separate digital pins.
Does the LCD Keypad Shield work with an Arduino Mega?
Yes. The Mega's first headers have the same layout as the Uno, so the shield plugs straight in and the same code runs unchanged. The Mega leaves many more pins free, which makes adding sensors and relays easy; the backlight warning still applies.
Can I use the LCD Keypad Shield with an ESP32?
Yes, but plugging it straight onto Uno-shaped ESP32 boards is risky, because the button line puts 5 V on A0 and the RS line lands on the boot pin GPIO 12. Wire the shield to an ESP32 DevKit with jumper wires and feed the A0 output to GPIO 34 through a 15 kΩ and 22 kΩ voltage divider.
Projects to build after reading this
See all projects
Print Message on 2x16 LCD Screen
Your first step to writing text on a screen. The two-line LCD screen first shows a waiting message, then writes a greeting on the top line and types a word letter by letter on the bottom line like a…

Bouncing Text Animation on LCD
On the top line of the LCD screen, the word BLUEGRAYS slides from one edge to the other and bounces back like a ball off a wall, over and over without end.

Measuring Distance Using LCD Display
A tool that measures distance without a ruler: move your hand back and forth in front of the sensor and watch the number change.

Temperature Measurement with NTC and 2x16 Lcd Display
Measure the temperature around you with a sensor that looks like a tiny bead. This part, called an NTC, lets electricity through more easily as it warms up; the Arduino reads that change, turns it…

DS1302 RTC Clock with LCD Display
A little desk clock that keeps the time even when the power goes out. The DS1302 clock module keeps time thanks to its own tiny battery; every second the Arduino reads it and writes the time and date…

Digital Voltmeter with LCD Display
Find out how much voltage a battery or power adapter gives with a meter you built yourself.

Arduino LCD Runner Game
Side scrolling endless runner game running on 16x2 character LCD screen. Hero runs automatically, player jumps over obstacles by pressing the button. Random obstacles appear on the top and bottom row. Passive buzzer plays opening melody, jumping sound, 50 point celebration sound and end of game melody. "BlueGrays - Arduino Projects" splash screen is shown on startup. The score is updated instantly in the upper right corner of the screen.

Password Lock with 4x4 Keypad and LCD
A small electronic door lock that keeps out anyone who doesn't know the code. You press the hash key and type the code on the keypad; if it is right, the screen says access granted, the green LED…
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

