Built-in project · Arduino Uno R3

LCD1602 on pins 4, 6 and 10 to 13, on an Arduino Uno

A 16x2 LCD with RS on pin 4, E on 6 and D4 to D7 on pins 10 to 13: the top line greets you and the bottom line scrolls a message across. 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.

The circuit runs here once the page has loaded.

What you'll learn

  • Wiring an LCD in 4 bit mode
  • The order of the LiquidCrystal constructor
  • Scrolling text with an offset and %
  • setCursor selects the row
  • Difficulty: Beginner
  • Time: About 20 minutes
  • Board: Arduino Uno R3
  • Parts: 3

How it works

A 16x2 LCD wired directly to the Uno needs six signal lines. RS goes to pin 4, E goes to pin 6, and the four data lines D4 to D7 go to pins 10 to 13. The LiquidCrystal library takes them in order: RS, E, D4, D5, D6, D7.

The top row shows "Mokxi LCD1602" and stays put. The bottom row scrolls the message "Hello from the Uno!" across the screen, shifting by one letter every 300 ms.

The contrast pin V0 goes to ground here. On a real bench you would use the middle leg of a potentiometer to adjust it.

Parts list

3 parts, plus the jumper wires. They retail for about $35; on Mokxi they're free.

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 pinConnects to
Character LCD, 16x2 pin D7Arduino Uno R3 pin 13
Character LCD, 16x2 pin D6Arduino Uno R3 pin 12
Character LCD, 16x2 pin D5Arduino Uno R3 pin 11
Character LCD, 16x2 pin D4Arduino Uno R3 pin 10
Character LCD, 16x2 pin EArduino Uno R3 pin 6
Character LCD, 16x2 pin RSArduino Uno R3 pin 4
Character LCD, 16x2 pin VDDArduino Uno R3 pin 5V
Character LCD, 16x2 pin AArduino Uno R3 pin 5V
Character LCD, 16x2 pin VSSArduino Uno R3 pin GND
Character LCD, 16x2 pin V0Arduino Uno R3 pin GND
Character LCD, 16x2 pin RWArduino Uno R3 pin GND
Character LCD, 16x2 pin KArduino 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.

sketch.ino · Arduino Uno R3
// A 16x2 LCD on pins 4, 6 and 10 to 13.
//
//   LCD RS -> pin 4    LCD E -> pin 6
//   LCD D4 -> pin 10   D5 -> pin 11   D6 -> pin 12   D7 -> pin 13
//   LCD RW, VSS, K -> GND     VDD, A -> 5V
//   LCD V0 (contrast) -> GND here; on the bench, the middle leg of a pot
//
// LiquidCrystal's constructor takes RS, E, D4, D5, D6 and D7, in that order.
// The top line shows a fixed greeting; the second line scrolls a message
// across one character at a time by printing it from a moving start column.

#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 6, 10, 11, 12, 13);

const char MESSAGE[] = "Hello from the Uno!   ";
int start = 0;

void setup() {
  lcd.begin(16, 2);
  lcd.print("Mokxi LCD1602");
  Serial.begin(9600);
  Serial.println("Mokxi Uno: LCD1602 on pins 4, 6 and 10 to 13");
}

void loop() {
  int length = sizeof(MESSAGE) - 1;
  lcd.setCursor(0, 1);
  for (int i = 0; i < 16; i++) lcd.print(MESSAGE[(start + i) % length]);
  start = (start + 1) % length;
  delay(300);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Starts the LCD with 16 columns and 2 rows, prints "Mokxi LCD1602" on the first row, and starts the serial port.

void setup() {
  lcd.begin(16, 2);
  lcd.print("Mokxi LCD1602");
  Serial.begin(9600);
  Serial.println("Mokxi Uno: LCD1602 on pins 4, 6 and 10 to 13");
}

loop sketch.ino

Moves to the start of row 1, then prints 16 characters from the message. Each one comes from (start + i) % length, so the message wraps around. start goes up by one each time, then it waits 300 ms.

void loop() {
  int length = sizeof(MESSAGE) - 1;
  lcd.setCursor(0, 1);
  for (int i = 0; i < 16; i++) lcd.print(MESSAGE[(start + i) % length]);
  start = (start + 1) % length;
  delay(300);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • Nothing shows, or only boxes This project
    Check the contrast pin V0 and the 5 V and ground wires. Check the pin numbers match LiquidCrystal lcd(4, 6, 10, 11, 12, 13).
  • Garbled letters This project
    Make sure D4 to D7 are on pins 10 to 13 in order.
  • 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.