Arduino UNO R4 - LCD 20x4
In this tutorial, we will show you how to use a 20x4 LCD display with Arduino UNO R4 board using an I2C interface. In detail, We will learn:
- How to connect LCD I2C 20x4 to Arduino UNO R4
- How to program Arduino UNO R4 to display information on LCD I2C 20x4
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.
Additionally, some of these links are for products from our own brand, DIYables.
Overview of LCD I2C 20x4
Pinout
The LCD 20x4 I2C uses the I2C interface and has 4 pins:
- GND pin: connect it to GND (0V).
- VCC pin: connect to VCC (5V) to power the LCD.
- SDA pin: this is for I2C data signal.
- SCL pin: this is for I2C clock signal.
LCD Coordinate
The LCD I2C 20x4 has 20 columns and 4 rows. The columns and rows start from 0.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
LCD I2C | Arduino UNO R4, Nano | Arduino Mega |
---|---|---|
Vin | 5V | 5V |
GND | GND | GND |
SDA | A4 | 20 |
SCL | A5 | 21 |
How To Program For LCD I2C
Using the LCD is very easy with the LiquidCrystal_I2C library.
- Add the library:
#include <LiquidCrystal_I2C.h>
- Create a LiquidCrystal_I2C object with the I2C address, number of columns, and number of rows:
LiquidCrystal_I2C lcd(0x27, 20, 4); // Initialize LCD with I2C address 0x27, 20 columns, and 4 rows
- Set up the LCD screen.
lcd.init(); // Initialize the LCD display
lcd.backlight(); // Turn on the backlight of the LCD
- Place the cursor at the specific position given by column_index and row_index.
lcd.setCursor(column_index, row_index);
- Display a message on the LCD screen.
lcd.print("Hello World!");
※ NOTE THAT:
Different manufacturers may use different I2C addresses for the LCD. In our example, we used the address 0x27 as given by the manufacturer DIYables.
Arduino UNO R4 Code
/*
* This Arduino UNO R4 code was developed by newbiely.com
*
* This Arduino UNO R4 code is made available for public use without any restriction
*
* For comprehensive instructions and wiring diagrams, please visit:
* https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-lcd-20x4
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // Initial setup for a 20 columns x 4 rows LCD with I2C address 0x27
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0); // Position cursor at the first row, first column
lcd.print("LCD 20x4"); // Display text at the first row
lcd.setCursor(0, 1); // Position cursor at the second row, first column
lcd.print("I2C Address: 0x27"); // Display text at the second row
lcd.setCursor(0, 2); // Position cursor at the third row, first column
lcd.print("DIYables"); // Display text at the third row
lcd.setCursor(0, 3); // Position cursor at the fourth row, first column
lcd.print("www.diyables.io"); // Display text at the fourth row
}
void loop() {
// TODO
}
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Connect LCD I2C 20x4 to Arduino UNO R4 according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Go to the Libraries icon on the left side of the Arduino IDE.
- Type "LiquidCrystal I2C" and look for the LiquidCrystal_I2C library by Frank de Brabander.
- Press the Install button to add the LiquidCrystal_I2C library.
- Copy the code above and open it in Arduino IDE.
- Press the Upload button in Arduino IDE to send the code to Arduino UNO R4.
- Check the result on the LCD.
Arduino UNO R4 LCD 20x4 display
- Try changing the text and its placement.