LCD1602 on pins 7 to 12, on an Arduino Uno
A 16x2 LCD with RS on pin 7, E on 8 and D4 to D7 on pins 9 to 12: a greeting on the top line and the seconds since reset under it. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 20 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $35. On Mokxi they're free.
What you'll learn
- Four bit LCD wiring
- The
LiquidCrystallibrary - Rows and columns count from zero
- Showing elapsed time with
millis()
- Difficulty: Beginner
- Time: About 20 minutes
- Board: Arduino Uno R3
- Parts: 3
How it works
A 16x2 LCD has its own controller chip. The Uno sends it commands and letters four bits at a time over D4 to D7. RS on pin 7 says whether a byte is a command or a letter, and E on pin 8 says the four bits are ready.
In the code, the order in LiquidCrystal lcd(7, 8, 9, 10, 11, 12) is RS, E, D4, D5, D6, D7. The first line shows "Hello, World!".
The second line shows how many seconds have passed, from millis() / 1000, followed by " s". It refreshes every 200 ms.
Parts list
3 parts, plus the jumper wires. They retail for about $35; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Full-size breadboard
- 1 × Character LCD, 16x2
Kits that can build it
These 7 starter kits have every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Character LCD, 16x2 pin D7 | Arduino Uno R3 pin 12 |
| Character LCD, 16x2 pin D6 | Arduino Uno R3 pin 11 |
| Character LCD, 16x2 pin D5 | Arduino Uno R3 pin 10 |
| Character LCD, 16x2 pin D4 | Arduino Uno R3 pin 9 |
| Character LCD, 16x2 pin E | Arduino Uno R3 pin 8 |
| Character LCD, 16x2 pin RS | Arduino Uno R3 pin 7 |
| Character LCD, 16x2 pin VDD | Arduino Uno R3 pin 5V |
| Character LCD, 16x2 pin A | Arduino Uno R3 pin 5V |
| Character LCD, 16x2 pin VSS | Arduino Uno R3 pin GND |
| Character LCD, 16x2 pin V0 | Arduino Uno R3 pin GND |
| Character LCD, 16x2 pin RW | Arduino Uno R3 pin GND |
| Character LCD, 16x2 pin K | Arduino Uno R3 pin GND |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A 16x2 LCD on pins 7 to 12: a greeting, and a seconds counter under it.
//
// LCD RS -> pin 7 LCD E -> pin 8
// LCD D4 -> pin 9 LCD D5 -> pin 10 LCD D6 -> pin 11 LCD D7 -> pin 12
// LCD RW, VSS, K -> GND LCD VDD, A -> 5V
// LCD V0 (contrast) -> GND here; on the bench, the middle leg of a 10k pot
//
// The display has its own controller chip. LiquidCrystal sends it commands
// and characters four bits at a time over D4 to D7, and E tells it when the
// four bits are ready. The order of the numbers in the constructor is RS, E,
// D4, D5, D6, D7.
//
// lcd.setCursor(column, row) counts from zero: (0, 1) is the start of the
// second line.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
lcd.begin(16, 2);
lcd.print("Hello, World!");
Serial.begin(9600);
Serial.println("Mokxi Uno: LCD1602 on pins 7 to 12");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
lcd.print(" s");
delay(200);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Starts the display as 16 columns by 2 rows and prints "Hello, World!". It also starts the serial port and prints a line saying the LCD is on pins 7 to 12.
void setup() {
lcd.begin(16, 2);
lcd.print("Hello, World!");
Serial.begin(9600);
Serial.println("Mokxi Uno: LCD1602 on pins 7 to 12");
}loop sketch.ino
Sets the cursor to column 0, row 1, prints the seconds since start and " s", then waits 200 ms. The text is overwritten each time in the same spot.
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
lcd.print(" s");
delay(200);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The screen lights but shows no text This project
Turn the contrast. Here V0 goes to ground, which gives dark characters in the simulator. - Nothing appears This project
Check RS on pin 7 and E on pin 8, then D4 to D7 on pins 9 to 12. - The screen lights up but shows only a row of solid boxes, or nothing at all. Character LCD
Contrast pin V0 needs a voltage. Connect the middle pin of a 10 k pot to V0, with its ends on 5 V and GND. Also confirm that the code calls lcd.begin(16, 2). - Garbled characters or a blank display even with good contrast. Character LCD
In 4-bit mode only D4 to D7 are used, and D0 to D3 stay unconnected. Tie RW to GND. Match the pins in LiquidCrystal(rs, en, d4, d5, d6, d7) exactly to your wiring. - Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected. - Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.