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:

Arduino UNO R4 and LCD I2C 20x4

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×LCD 20x4
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino UNO R4
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno

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. We appreciate your support.

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 20x4 I2C Pinout

LCD Coordinate

The LCD I2C 20x4 has 20 columns and 4 rows. The columns and rows start from 0.

Arduino UNO R4 LCD I2C Coordinate

Wiring Diagram

The wiring diagram between Arduino UNO R4 LCD 20x4 I2C

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.
Arduino UNO R4 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.
  • Try changing the text and its placement.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!