Arduino Nano - LCD 20x4
This tutorial instructs you how to use LCD 20x4 display with Arduino Nano, how to program for Arduino Nano to display text on LCD 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) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of LCD I2C 20x4
LCD I2C is made up of a standard LCD, an I2C module and a potentiometer.
The LCD Pinout
The LCD I2C uses the I2C interface to connect to Arduino Nano. It has four pins:
- The GND pin needs to be connected to ground (0V).
- The VCC pin is the power supply for the LCD and must be connected to VCC (5V).
- The SDA pin is the I2C data signal.
- The SCL pin is the I2C clock signal.
LCD Coordinate
The LCD I2C 20x4 has 20 columns and 4 rows, with the columns and rows being numbered starting from 0.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
LCD I2C module | Arduino Nano |
---|---|
Vin | 5V |
GND | GND |
SDA | A4 |
SCL | A5 |
How To Program For LCD I2C
The LiquidCrystal_I2C library needs to be included in order to use the LCD.
- Set up the LCD:
The LCD must be set up properly for it to work correctly.
- Write to the LCD:
Writing to the LCD is easy thanks to the LiquidCrystal_I2C library.
- Create a LiquidCrystal_I2C object with an I2C address, the number of columns, and the number of rows specified.
- Start up the LCD.
- Go to the column and row indicated by column_index and row_index respectively.
- Display a message on the LCD.
Explore the possibilities of what can be achieved with LCD by looking at the "Do More with LCD" section.
※ NOTE THAT:
The address of the LCD may differ depending on the manufacturer. For our code, we used 0x27 as specified by DIYables.
Arduino Nano Code
Detailed Instructions
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for "LiquidCrystal I2C" and locate the LiquidCrystal_I2C library created by Frank de Brabander.
- Then, click the Install button to add the library.
- Copy the code and open it with the Arduino IDE.
- Click the Upload button in the IDE to send the code to the Arduino Nano.
- Check the LCD for the result.
- Experiment with altering the text and its location.
Guide for Choosing LCD I2C Displays
There are different types of LCD I2C displays you can buy. They mainly differ in background color and how you select the I2C address.
Color Options
Most LCD I2C displays come in two background colors:
- Green
- Blue
I2C Address Selection Options
With a Jumper
- Allows you to switch between two I2C addresses.
- Useful if you are using two LCDs at the same time.
- Can be confusing if you are only using one LCD.
- Takes up more space.
Without a Jumper
- Has a fixed I2C address.
- Very convenient if you are using only one LCD.
- Recommended for most projects, as most use just one LCD display.