Arduino Uno R4 I2C LCD Simulator: Wiring, Code and a Live Circuit
This is a 16 by 2 character LCD with a PCF8574 I2C backpack, wired to an Arduino Uno R4 Minima and running live: the first line names the board and the second counts the seconds since reset. It uses the LiquidCrystal_I2C library, so four wires replace the sixteen of a bare LCD.
SDA goes to pin A4 and SCL to pin A5. Everything runs at 5 V, the Arduino Uno R4’s own level.
- 5 V logic
- Library: LiquidCrystal_I2C.h
- I2C address 0x27
- Powered from 5V
Wiring the I2C LCD to the Arduino Uno R4
Every connection in the circuit above, with the board’s own pin names.
| I2C LCD pin | Arduino Uno R4 pin | Why |
|---|---|---|
| VCC | 5V | The display and its backlight run from 5 V. |
| GND | GND | Common ground. |
| SDA | pin A4 | I2C data. |
| SCL | pin A5 | I2C clock. |
The Uno R4 keeps the Uno’s layout: I2C is A4 (SDA) and A5 (SCL), also brought out as SDA and SCL beside AREF. The backpack’s own pull-ups hold both lines at 5 V, which is the Arduino Uno R4’s own logic level, so nothing else is needed.
Pins to leave alone on the Arduino Uno R4
An Uno sketch’s source builds for the R4, but a compiled Uno program will not run on it: different chip. The R4’s pins source less current than an Uno’s, about 8 mA each, so do not drive a relay coil or a motor straight from one.
On a real bench
The Uno R4 Minima fits every Uno shield and every Uno breadboard layout, so wire the I2C LCD exactly as you would on an Uno R3. It has a USB-C socket, and its VIN accepts up to 24 V where an Uno R3 stops at 12.
The code
The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// A 16 x 2 display behind a PCF8574 backpack at 0x27.
// SDA pin A4, SCL pin A5.
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Arduino Uno R4");
Serial.println("LCD ready");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print("Seconds: ");
lcd.print(millis() / 1000);
lcd.print(" "); // clears the tail of a shorter number
delay(250);
}
LiquidCrystal_I2C lcd(0x27, 16, 2) names the backpack’s address and the size of the display. init() wakes the HD44780 controller behind the backpack in four-bit mode, and backlight() turns the LED on, which is a bit in the backpack, not in the display.
setCursor(column, row) counts from zero, so (0, 1) is the start of the second line. print() writes text there and moves the cursor along, the way Serial.print() does.
The three spaces after the number overwrite whatever a longer number left behind. Calling clear() every time would do the same and make the display flicker, because clear() takes about 2 ms and blanks the whole panel. Serial.begin(9600) opens the serial monitor. Serial is the USB port; Serial1 is on pins 0 and 1, which on the R4 are free for other serial devices.
Common mistakes with the I2C LCD on the Arduino Uno R4
The wrong address
Backpacks with the PCF8574T chip answer at 0x27; those with the PCF8574AT answer at 0x3F. The screen lights but shows nothing when the address is wrong. Run an I2C scanner, or set the part’s address property in the editor to match yours.
Contrast turned all the way down
A row of solid blocks, or nothing at all with the backlight on, is usually the blue trimmer on the backpack. Turn it until the text appears. In the simulator the part has a contrast property for the same thing.
Clearing the screen in every loop
lcd.clear() takes about 2 milliseconds and blanks the panel, so calling it every pass makes the text flicker. Overwrite the line and pad it with spaces, as the sketch does.
Questions and answers
Can I simulate a 16x2 I2C LCD with an Arduino Uno R4 Minima?
Yes. The circuit at the top of this page is an Arduino Uno R4 Minima with a 16x2 I2C LCD, running in your browser on a simulated Renesas RA4M1 (Cortex-M4). The characters the sketch prints appear on the simulated panel, backlight and contrast included. Press Run it in the editor to change the wiring or the code; it is free and needs no account.
Where do SDA and SCL go on the Arduino Uno R4?
The Uno R4 keeps the Uno’s layout: I2C is A4 (SDA) and A5 (SCL), also brought out as SDA and SCL beside AREF.
Do I need a level shifter?
No. The Arduino Uno R4 and the backpack both run at 5 V, so SDA and SCL connect directly.
How do I find the LCD’s I2C address?
Upload an I2C scanner sketch: it calls Wire.beginTransmission() on every address and prints the ones that answer. The two you will almost always see are 0x27 and 0x3F.
Build your own I2C LCD project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.