Indice
- 7.1 What Is an LCD 1602 Display? Meet the 16x2 LCD
- 7.2 How Does I2C Work? Understanding the I2C Interface
- 7.3 Parts List and Wiring: Connecting the LCD 1602 I2C Display to Arduino
- 7.4 Installing the LiquidCrystal_I2C Library and Drawing the Flowchart
- 7.5 Writing the Code and Displaying Your First Message on the LCD
- 7.6 Displaying Sensor Values on the LCD 1602: Arduino Photoresistor (LDR) Example
- 7.7 Troubleshooting Your Arduino LCD 1602 I2C Display: Testing and Fixing the Program
- 7.8 Arduino LCD 1602 Exercises and Variations: Practice What You’ve Learned
- Coming up in the next chapter...
7.1 What Is an LCD 1602 Display? Meet the 16x2 LCD
In the previous chapters, we learned how to use the Serial Monitor to display sensor readings on the computer and to check that our Arduino programs are working properly.
The Serial Monitor is a really handy tool while we’re developing a project, but it isn’t always available when we want our device to work on its own. Imagine, for example, building a system that measures how bright a room is: it would be so much more convenient to read the value right there on the device, without having to plug Arduino into a computer.
To do this, we can use a display: a component that shows information as text, numbers or symbols.
The LCD 1602 display
One of the most popular displays in Arduino learning projects is the LCD 1602 display, also known as the 16x2 LCD.
LCD stands for Liquid Crystal Display. The number 1602 tells us that the display has 16 columns and 2 rows, giving us a total of 32 positions in which to show characters.
We can think of it as a small window made up of two lines of text, where Arduino can write messages, numbers and other useful information.
For example, an LCD 1602 display could show:
- Light sensor
- Value: 675
Here, the first line describes what is being displayed, while the second shows the number read by the sensor.
Of course, that number is just an example: in our project, the value will change depending on how much light the sensor detects.
What are displays used for in Arduino projects?
A display lets us communicate with the user without constantly relying on a computer. We can use it to show:
- values measured by sensors;
- messages that tell us the status of the system;
- temperatures, distances and other numerical data;
- instructions or warnings that are useful while using the device.
In our projects, the display will act as a small interface between Arduino and the person using the system.
The I2C version
The LCD 1602 comes in several versions. Some models need lots of wires to connect to Arduino, while others come with a small extra module that uses the I2C interface.
This second version is particularly handy for beginners, because it lets us connect the display to Arduino using just four connections:
- GND, the ground (or earth) connection;
- VCC, the power supply;
- SDA, the data line;
- SCL, the clock line, which keeps the communication in sync.
Thanks to this interface, we can control the display with only a few wires, leaving plenty of Arduino’s pins free for other components.
In the next section, we’ll take a closer look at how I2C communication works and why it makes connecting Arduino to the display so much simpler.

7.2 How Does I2C Work? Understanding the I2C Interface
To connect a display to Arduino, the two components need to be able to talk to each other. There are several electronic communication systems for this, called communication protocols, which set out how devices should exchange information.
One of these protocols is I2C, often pronounced “I-squared-C” (or “I-two-C”). The name comes from Inter-Integrated Circuit, and it describes a communication system used to connect different electronic components to one another.
How does I2C communicate?
The I2C interface mainly uses two communication lines:
- SDA (Serial Data Line): the line that carries the data.
- SCL (Serial Clock Line): the line that provides the synchronisation (US: synchronization) signal, helping the devices to coordinate how they exchange data.
To keep things simple, we can picture SDA as a road along which the information travels, and SCL as a signal that tells the devices when to read or send data.
On top of these two lines, the components need to share a common electrical reference by connecting their GND (ground, or earth) pins together, and they also need a suitable power supply.
Why is I2C useful with Arduino?
Without an I2C interface, a traditional LCD 1602 display can need quite a few Arduino pins to receive the commands and data it needs to show anything.
With the I2C module, on the other hand, the communication happens over just the two lines SDA and SCL. This means that four wires are normally enough to connect the display: GND, VCC, SDA and SCL.
This is especially useful when we build projects that use several components at once, such as sensors, push buttons, LEDs and servo motors. By cutting down the number of pins used by the display, we can save plenty of others for the rest of our project.
The I2C pins on the Arduino UNO R3
On the Arduino UNO R3 board, the I2C lines correspond to the following pins:
- SDA: analogue (US: analog) pin A4.
- SCL: analogue (US: analog) pin A5.
The board also has two dedicated pins, labelled SDA and SCL, which are wired to the same electrical lines as A4 and A5. We can use either set, but not both at the same time.
It’s worth remembering that when A4 and A5 are used for I2C communication, they can’t also be used as ordinary analogue (US: analog) inputs for other, independent tasks.
The I2C module on the back of the display
An LCD 1602 display with an I2C interface usually has a small circuit board fixed to the back. This module takes care of the communication between Arduino and the display, which makes controlling the rows and columns much simpler.

Many modules also have a small potentiometer (also called a trimmer): an adjustable component that lets us change the contrast of the characters. If the display is powered but you can’t see any text, you may need to adjust this potentiometer.
The module also has an I2C address, which is used to identify the device during communication. The address depends on the model and on how the module is set up, so it isn’t always the same for every display.
In the next section, we’ll gather the materials we need and connect the LCD 1602 display to the Arduino UNO R3.
7.3 Parts List and Wiring: Connecting the LCD 1602 I2C Display to Arduino
Now that we’ve seen how the LCD 1602 display works and how it talks to Arduino through the I2C interface, we can move on to building our first circuit.
The goal is simple: connect the display to the Arduino UNO R3 board correctly and get everything ready to show a message.
What you’ll need
For this exercise we’ll need:
- an Arduino UNO R3 board;
- an LCD 1602 display with an I2C module already fitted to the back;
- a breadboard, if it helps to keep the wiring tidy;
- four jumper wires that match the connectors on the display and on Arduino;
- a USB cable to connect Arduino to the computer.
The display must have the I2C module: an LCD 1602 without it needs different wiring, so it can’t be connected by following the instructions in this section.
Identifying the display pins
On the I2C module, we usually find four pins marked with the following labels:
- GND: ground (or earth);
- VCC: positive power supply;
- SDA: data line;
- SCL: clock line.
Before making any connections, let’s check the labels printed on the module. The order of the pins can vary from one model to another, so we shouldn’t assume they’re always laid out in the same way.
Connecting the display to Arduino
With Arduino unplugged from the USB cable, let’s make the connections following this table.
| LCD 1602 I2C display | Arduino UNO R3 |
|---|---|
| GND | GND |
| VCC | 5V, if the module supports it |
| SDA | SDA or A4 |
| SCL | SCL or A5 |
As for the power supply, let’s make sure our module is compatible with the board’s 5 V. Some I2C modules have different electrical characteristics, so it’s always a good idea to check the manufacturer’s instructions.
We can connect SDA and SCL to the dedicated pins on the board or, alternatively, to A4 and A5 respectively. Both options use the same communication lines.
Once all the wires are in place, let’s check that each one is plugged into the right pin and that there are no accidental contacts between different connections.
Checking the circuit before powering it up
Before plugging in the USB cable, let’s carefully check:
- that GND is connected to GND;
- that VCC is connected to the correct power supply;
- that SDA and SCL haven’t been swapped;
- that the connections are firm and there are no bare wires that could cause a short circuit.
At this point we can connect Arduino to the computer using the USB cable.
The display may light up and show a row of rectangles, or it may not show any characters at all. This doesn’t necessarily mean something is wrong: we haven’t uploaded a program yet to send it the information to display, and we might also need to adjust the contrast.

7.4 Installing the LiquidCrystal_I2C Library and Drawing the Flowchart
We’ve connected the LCD 1602 display to the Arduino UNO R3. Before we can show a message, though, we need to teach Arduino how to communicate with the display.
To do this, we’ll use a library: a collection of ready-made functions that lets us control a component without having to program every detail of the communication from scratch.
What is a library?
So far we’ve used instructions such as pinMode(), digitalWrite() and analogRead(), which are built into the Arduino programming environment.
When we work with more complex components, like an LCD display, we may need some extra functions. Libraries provide these functions and make writing the program much easier.
For our display we’ll use a library designed for LCD 1602 modules with an I2C interface, commonly known as LiquidCrystal_I2C.
It’s worth knowing that there are several versions of this library, and they can differ slightly in the functions they offer and in the way the display is initialised (US: initialized). For this reason, when installing the library and writing the code, we need to use a version that is compatible with the code in this tutorial.
Installing the library in the Arduino IDE
To install the library, we can use the Library Manager built into the Arduino IDE.
- Open the Arduino IDE on your computer.
- From the side menu, or from the Tools menu depending on the version you’re using, open the Library Manager.
- In the search box, type
LiquidCrystal_I2C. - Find a library that’s compatible with the I2C LCD display and install it.
- Wait for the installation to finish before moving on.
Since there may be several libraries with similar names, it’s important to follow the instructions for the version you’ve chosen and to use examples that are compatible with it.
Getting the program ready
Once the library is installed, we can create a new program (also called a sketch) in the Arduino IDE.
To use the library’s functions, we’ll put this line at the beginning of the program:
#include <LiquidCrystal_I2C.h>
The #include directive tells the compiler to make the declarations contained in the library available to the program.
This way, we’ll be able to use the functions we need to set up the display, position the cursor and show text.
The I2C address of the display
To communicate with the display, Arduino also needs to know its I2C address: the value that identifies the device on the communication bus.
Many LCD 1602 modules use the address 0x27 or 0x3F, but there’s no way to tell which one is correct just from the type of display: it depends on the module you’re using.
Now that we’ve connected the LCD 1602 display to Arduino and installed the library we need, we can write our first program to show a message.
Our goal is to display two lines of text on the screen, using just a few instructions and learning how to control the position of the cursor.
As usual, let’s start by drawing our flowchart:

7.5 Writing the Code and Displaying Your First Message on the LCD
Once we’re clear on how the flow of the program should work, we can move on to writing the code.
Writing the program
Let’s open the Arduino IDE, create a new sketch and enter the following code:
/* Exercise No. 07.5
Writes two lines of text to the 1602 display via the I2C interface */
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(“Hello Arduino!”);
lcd.setCursor(0, 1);
lcd.print(“First display”);
}
void loop() {
}
Before uploading the program, let’s check that the library we installed supports the functions used in the code. Some versions may need the display to be set up slightly differently.
Going through the main instructions
The first line:
#include <LiquidCrystal_I2C.h>
lets us use the library that handles the communication with the display.
The instruction:
LiquidCrystal_I2C lcd(0x27, 16, 2);
creates an object called lcd, which we’ll use to control the display.
The three parameters mean:
- 0x27: the I2C address of the module, which must match the actual address of our device;
- 16: the number of columns;
- 2: the number of rows.
If our module uses a different address, we’ll need to replace 0x27 with the correct one.
Inside the setup() function we find:
lcd.init();
This instruction sets up the display and gets it ready to communicate with Arduino.
Right after that, we find:
lcd.backlight();
which turns on the backlight: the light that makes the characters on the display easier to see.
Writing text on the display
To decide where to start writing, we use:
lcd.setCursor(0, 0);
This instruction places the cursor at column 0 of row 0, in other words at the start of the first line.
Next:
lcd.print(“Hello Arduino!”);
displays the text inside the quotation marks (or quotes).
To write on the second line, we use:
lcd.setCursor(0, 1);
lcd.print(“First display”);
This time, the cursor is placed at the start of the second line.
It’s important to remember that row and column indexes start from zero. That’s why, on a two-line display, the first line has index 0 and the second has index 1.
Why is the loop() function empty?
In this first program, all the operations are carried out just once inside setup(), when Arduino starts up or is restarted.
The loop() function stays empty because we don’t need to keep repeating the instructions: once the message has been displayed, the display can keep it on screen.
Uploading the program and checking the result
After writing the code:
- Let’s connect Arduino to the computer using the USB cable.
- Let’s select the Arduino UNO board and the correct port in the IDE.
- Let’s verify and upload the program.
- Let’s take a look at the display.
If everything works properly, we should read:
Hello Arduino!
First display
If the backlight is on but we can’t see any text, let’s try slowly adjusting the contrast potentiometer on the I2C module. If the text still doesn’t show up, we’ll need to check the connections, the I2C address and whether the library we’re using is compatible.
And that’s it: we’ve written our first program that lets Arduino communicate with a display and show information without using the Serial Monitor.

In the next section, we’ll use the display to show not only messages but also numbers and values read from a sensor, going back to the photoresistor (or light-dependent resistor, LDR) project we built in the previous chapter.
7.6 Displaying Sensor Values on the LCD 1602: Arduino Photoresistor (LDR) Example
In the previous section, we learned how to display a message on the LCD 1602. Now we’re going to take a step forward: we’ll use the display to show a numerical value read from a sensor.
We’ll bring back the photoresistor (LDR) that we used in Chapter 6. This way, we’ll be able to see how the sensor reading changes as the brightness changes, with the result shown right on the display.
Getting the circuit ready
For this exercise, we’ll use:
- an Arduino UNO R3 with its USB cable;
- an LCD 1602 display with an I2C module;
- a photoresistor (LDR);
- a 10 kΩ resistor;
- a breadboard;
- jumper wires.
We’ll keep the light sensor circuit we already built in Chapter 6:
- connect one terminal of the photoresistor to the 5V pin on Arduino;
- connect the other terminal of the photoresistor to the analog pin A0;
- connect a 10 kΩ resistor between A0 and GND.
The LCD display must stay connected through the I2C module, as we saw in section 7.3.

Drawing the flowchart
Unlike the previous program, which showed fixed text on the display, this time we want to show a value read from the photoresistor. Since this value changes depending on how much light reaches the sensor, the program will have to repeat two operations over and over: reading the sensor and writing the result to the display.

Writing the program
Let’s open a new sketch in the Arduino IDE and enter the following code. We’ll use the same I2C address and the same library as in section 7.5.
/* Exercise No. 07.6
Detects light with a photoresistor and writes the intensity value to the 1602 display */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(“Light sensor”);
}
void loop() {
int lightValue = analogRead(A0); // reads the analog value on pin A0 and stores it in the variable lightValue
lcd.setCursor(0, 1);
lcd.print(“Value: “);
lcd.print(lightValue);
lcd.print(“ “);
delay(300);
}
As in the previous section, if your module uses an address other than 0x27, you’ll need to enter the correct one. Also, the code assumes a version of the LiquidCrystal_I2C library that is compatible with the functions used.
Going through the new instructions
The first part of the program is similar to what we’ve already seen: we set up the display, turn on the backlight and write the title on the first line.
The main new feature is in the loop() function.
int lightValue = analogRead(A0);
With this instruction, Arduino reads the analog value on pin A0 and stores it in the variable lightValue.
On the Arduino UNO R3 board, analogRead() normally returns a number between 0 and 1023, depending on the voltage measured relative to the analog reference voltage.
To display the result, we use:
lcd.setCursor(0, 1);
lcd.print(“Value: “);
lcd.print(lightValue);
The first instruction places the cursor at the start of the second line. The next two display the text Value: and the number stored in the variable.
Finally:
delay(300);
adds a pause of 300 milliseconds before the next reading. This means the value on the display is refreshed several times a second.
We’ve also added:
lcd.print(“ “);
These spaces help wipe out any digits left over from the previous reading when the new number is shorter. Without this precaution, when going from 1000 to 999, for example, an unwanted digit could be left on the display.
Uploading the program and checking the result
Let’s upload the sketch to Arduino and take a look at the display. We should see a screen like this:
Light sensor
Value: 675
The number is just an example: the actual value depends on the brightness of the room and on the characteristics of the photoresistor.
Let’s try covering the sensor with a hand and then shining more light on it. In the circuit we used in Chapter 6, with the photoresistor connected between 5V and A0 and the 10 kΩ resistor between A0 and GND, the reading tends to go up as the light gets brighter and down as it gets dimmer.
Remember that the number shown doesn’t directly represent brightness in lux: it’s an analog reading converted into a numerical value by Arduino.
Why is it useful to show data on the display?
With this simple change, we’ve turned our circuit into a small monitoring tool. We can read the sensor’s value right on the device, without having to open the computer’s Serial Monitor.
This will come in very handy in our next projects, where we’ll use displays to show information about how the system is working, such as the distance detected by a sensor or the status of a device.
In the next section, we’ll look at how to spot and fix some common problems that can come up when using the LCD 1602 display.
7.7 Troubleshooting Your Arduino LCD 1602 I2C Display: Testing and Fixing the Program
When we build an electronic circuit and write a program, the result isn’t always what we expected. That’s perfectly normal: learning to spot and fix errors is an important part of working with Arduino.
In this section, we’ll look at how to tackle some common problems that can come up when using the LCD 1602 display with an I2C interface.
The display won’t turn on
If the display stays completely off, let’s start by checking the electrical connections.
- Let’s check that the USB cable is plugged in properly and that Arduino is powered.
- Let’s make sure the display’s VCC pin is connected to the power supply the module requires.
- Let’s check that GND is connected properly.
- Let’s make sure the wires are in the right pins and that none of them are loose.
If the connections are all correct but the display still stays off, there may be a problem with the module or its power supply.
The display is on, but there’s no visible text
Sometimes the backlight is on, but the characters aren’t visible, or only rectangles appear on the display.
In this case, we can try slowly adjusting the contrast potentiometer (or trimmer), which is usually found on the back of the I2C module.
If the text still doesn’t appear, let’s check that the program has been uploaded correctly and that the I2C address in the code matches the address of our module. It may also be necessary to check that the library we’re using is compatible.
The display shows the message, but the sensor value doesn’t change
If the first line is displayed correctly but the number always stays the same, the problem might lie in the photoresistor circuit or in the analog reading.
Let’s check that:
- the photoresistor is connected between 5V and A0;
- the 10 kΩ resistor is connected between A0 and GND;
- the point where the photoresistor and the resistor meet is connected to pin A0;
- the program contains the analogRead(A0) instruction inside the loop() function.
We can also temporarily open the Serial Monitor and display the value Arduino is reading, by adding Serial.begin(9600); in the setup() function and Serial.println(lightValue); straight after the sensor reading. This way, we can check whether the value changes regardless of what appears on the display.
If the value doesn’t change on the Serial Monitor either, it’s best to check the sensor circuit first.
Unwanted digits are left on the display
Imagine that one reading shows the number 1000 and the next one shows 999. If the program only writes the new digits without erasing the previous ones, an extra character could be left on the display. To avoid this problem, we’ve added three spaces after the value in our program:
lcd.print(“ “);
These spaces overwrite any characters left over from the previous reading. It’s a simple solution that works well for our first programs.
A method for finding errors
When something doesn’t work, it’s better to go step by step rather than changing the circuit and the program at the same time.
We can follow these steps:
- Check the power supply and the connections of the display, the sensors and the actuators.
- Check the program, making sure it has been compiled and uploaded without errors.
- Compare the sensor values with the ones shown on the Serial Monitor, if necessary.
- Change one thing at a time, and watch the result before moving on.

7.8 Arduino LCD 1602 Exercises and Variations: Practice What You’ve Learned
Now that we know how to connect an LCD 1602 display to Arduino and use it to show messages and numerical values, we can try out a few changes to the program.
The exercises below are arranged in order of increasing difficulty. The first ones help you get comfortable with the instructions we’ve already used, while the last ones ask you to combine several things you’ve learned.
Exercise 1 – Write Your Own Message
Change the program from section 7.5 by replacing the messages shown on the display with two sentences of your choice.
For example, you could show the name of your project on the first line and a short description on the second.
Remember that the display has 16 characters per line. If the text is too long, it might not be shown in full.
Goal: learn how to change the text and how to use lcd.setCursor() and lcd.print().
Exercise 2 – Show the Value with a Different Label
In the program from section 7.6, the second line shows the text Value: followed by the photoresistor reading.
Change the message, using for example:
lcd.print(“Light: “);
Try changing the title on the first line too.
Goal: learn how to change the information shown on the display without changing how the sensor works.
Exercise 3 – Change the Refresh Rate
In the program from section 7.6, we find this instruction:
delay(300);
Try replacing 300 with 1000 and then with 100.
Watch how the display behaves and try to work out how the rate at which the values are updated changes.
Goal: understand how a pause in the program affects how often the information is updated.
Exercise 4 – Show a Message Based on the Light Level
Change the program from section 7.6 so that the display shows a different message depending on the value read from the photoresistor.
Use an initial threshold of 500:
- if the value is greater than 500, show Bright light;
- otherwise, show Low light.
You can use an if...else structure, which we met in Chapter 5.
Goal: combine reading a sensor, a condition and displaying a message.
Exercise 5 – Build a Small Light Monitor
Try combining the previous exercises to build a program that shows this on the first line:
Light monitor
and the value read from the photoresistor on the second line.
When the value goes above the threshold you’ve set, the program should also show a message saying that the light level is high. When the value drops below the threshold, it should show that the light level is low.
Since the display only has two lines, you’ll need to decide how to lay out the information: for example, you could show the numerical value during normal operation and temporarily replace the title with the message about the light level.
Goal: build a simple application that collects a piece of data, processes it and reports the result to the user.
Review questions
Before moving on to the next chapter, try answering these questions:
- What does the abbreviation LCD stand for?
- What does the number 1602 in the name of the display mean?
- What’s the advantage of using an I2C module?
- What are the SDA and SCL lines for?
- What’s the role of the LiquidCrystal_I2C library?
- What are the lcd.setCursor() and lcd.print() instructions for?
- Why can we show the value returned by analogRead(A0) on the display?
- What’s the difference between displaying a numerical value and displaying a message chosen by means of a condition?
Chapter wrap-up
In this chapter, we learned how to use an LCD 1602 display with an I2C interface, how to connect it to Arduino and how to program it to show messages and numerical values.
We also went back to the light sensor from Chapter 6, learning how to show the data we collect straight on the display and how to choose a message based on the value detected.
So the display lets us turn a simple circuit into a device that can communicate information on its own, without constantly needing a computer.
In the next chapters, we’ll dig deeper into programming and into using other electronic components. This knowledge will help us build, step by step, a robotic system that can detect what’s happening in its environment and react accordingly.
Coming up in the next chapter...
So far, we’ve learned how to connect components, read a sensor and show the results on a display. In the next chapter, Chapter 8 - Arduino Programming for Beginners: Variables, Loops, Functions and millis() Explained, we’ll take a step forward: we’ll find out how Arduino “thinks” and how we can teach it to make decisions on its own.
We’ll see how to make our program remember important information, how to compare values to choose what to do, how to repeat operations without rewriting the same lines, and how to tidy up our code so it stays clear even when our projects get more ambitious. We’ll also learn how to manage time, so that Arduino can handle several things at once without stopping to wait.
And since making mistakes is part of the game, we’ll also learn how to track down and fix errors in a methodical way. This will be the chapter where our Arduino stops simply following basic commands and starts behaving in a truly “smart” way: a valuable foundation for the final project that awaits us.
If you’re curious to see where this journey will take us, have a look at the page Beginner's Guide to Robotics with Arduino: there you’ll find the full contents list, from the first chapter to the final project, and you can choose whether to carry on in order or go back and review a topic.
If you’ve found this course useful and would like to explore other robotics or hobby electronics projects, you can keep reading by visiting the other content in the Electronics and Robotics section of the site, where you’ll find plenty more practical guides and step-by-step explanations.
I’d like to point out that some of the images in the course were generated by artificial intelligence (AI), and I apologise for any inaccuracies they may contain. The course itself was also written with the help of AI, but the structure is the result of my own experience: I’m a retired programmer and, over the course of my career, I’ve taught several courses. So I chose the topics, organised the whole structure of the course and reviewed the text myself.
I care a great deal about the quality and originality of the content I publish. That’s why I’d prefer it not to be copied or republished elsewhere. If you think this guide could be useful to other people, though, I’ll be really happy if you share the link to the page: it’s the right way to spread the information and to support the work behind every article.
Thank you
Luciano (Capitan Farloc)

English (United Kingdom)
Italiano (Italia)