Unit C - Actuators & Displays

16. 16x2 LCD in 4-Bit Mode

Display text and live values on a character LCD.

Estimated time 4 hours

Learning outcomes

  • Explain LCD data and instruction registers
  • Wire RS, E and four data lines
  • Set contrast and backlight safely
  • Position and update text without leftover characters

Parts and preparation

Uno, HD44780-compatible 16x2 LCD, 10 k ohm potentiometer, 220 ohm backlight resistor where required and jumpers.

Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.

Libraries for this lesson

In Arduino IDE 2 open Tools → Manage Libraries…. Search by the Library Manager name and install the package by the exact author below. Similar names from other authors can use different APIs and will break the example.

IncludeLibrary Manager nameAuthorInstall note
LiquidCrystal.hLiquidCrystalArduinoBuilt-in with Arduino AVR Boards. No Library Manager install required.
16x2 LCD in 4-Bit Mode instructional connection diagram
Open the diagram for a larger view. Trace every connection before building.

Interface

RS selects command or data, E latches a transfer, and D4D7 carry four bits at a time. R/W is normally tied to GND for write-only operation.

Contrast

VO needs an adjustable voltage from a potentiometer. A row of solid blocks usually means power and contrast are present but initialization/data wiring is wrong.

Coordinates

setCursor(column, row) uses zero-based positions. A 16x2 display has columns 0-15 and rows 0-1.

Updating text

Printing a shorter value leaves old characters behind. Pad with spaces or overwrite the full field.

Wiring and safe build sequence

Breadboard wiring for lesson 16: 16x2 LCD in 4-Bit Mode
Breadboard layout for this lesson. Match colours and pins before powering the circuit. Click the image for a larger view.
  1. VSS -> GND, VDD -> 5 V, R/W -> GND
  2. 10 k ohm pot ends -> 5 V/GND; wiper -> VO
  3. RS -> D12, E -> D11
  4. D4-D7 -> D5, D4, D3, D2
  5. Backlight through resistor if the module does not include one
Power rule: switch off before moving wires. Arduino I/O pins are control signals; high-current loads require a driver and suitable external supply.
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("Arduino ready");
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print("Time ");
  lcd.print(millis() / 1000);
  lcd.print(" s    ");
  delay(200);
}

How the code works

  1. Constructor order must match RS, E, D4, D5, D6, D7 wiring.
  2. Trailing spaces erase digits left by a longer previous number.

Test and record evidence

Expected result: Line 1 shows Arduino ready; line 2 shows increasing seconds.

Practical evidence checklist

Common faults and checks
  • Adjust contrast before changing code.
  • Check R/W is grounded.
  • If text is scrambled, verify D4D7 order.
Extension challenge: Display an ADC voltage with two decimal places and a unit.

Check your understanding

Q1. What does RS select?

Show answer

The instruction register or data register.

Q2. Why print trailing spaces?

Show answer

To erase characters from a longer previous value.