0% found this document useful (0 votes)
2 views

Arduino LCD Tutorial _ How to Connect an LCD to Arduino

This tutorial provides a comprehensive guide on connecting and using a 16×2 LCD with Arduino, detailing the pinout, wiring diagram, and example codes. It covers adjusting the contrast, scrolling text, and creating custom characters using the LiquidCrystal library. The tutorial is suitable for beginners and includes practical examples to facilitate understanding.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Arduino LCD Tutorial _ How to Connect an LCD to Arduino

This tutorial provides a comprehensive guide on connecting and using a 16×2 LCD with Arduino, detailing the pinout, wiring diagram, and example codes. It covers adjusting the contrast, scrolling text, and creating custom characters using the LiquidCrystal library. The tutorial is suitable for beginners and includes practical examples to facilitate understanding.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

  MENU
Arduino 16×2 LCD Tutorial – Everything You
Need to Know
by Dejan • 25 Comments

In this Arduino tutorial we will learn how to connect and use an LCD
(Liquid Crystal Display) with Arduino. LCD displays like these are very
popular and broadly used in many electronics projects because they are
great for displaying simple information, like sensors data, while being very
affordable.

Table of contents
1. What is LCD Character Display?
2. 16×2 LCD Pinout
3. How to Connect Arduino to LCD – Wiring Diagram
4. Adjusting the contrast of the LCD
4.1. Can I use the LCD without Potentiometer?
5. LCD Arduino Code
6. Scrolling text example on 16×2 LCD and Arduino
7. How to Generate and Display Custom Characters on the LCD
8. Conclusion

I’ve already used them in several of my Arduino projects, and you can
check them out here:

Arduino Security and Alarm System Project


DIY Vending Machine – Arduino based Mechatronics Project

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 1/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

Arduino Range Measurer and Digital Spirit Level Project 

You can watch the following video or read the written tutorial below. It
includes everything you need to know about using an LCD character
display with Arduino, such as, LCD pinout, wiring diagram and several
example codes.

What is LCD Character Display?


An LCD character display is a unique type of display that can only output
individual ASCII characters with fixed size. Using these individual
characters then we can form a text.

If we take a closer look at the display we can notice that there are small
rectangular areas composed of 5×8 pixels grid. Each pixel can light up
individually, and so we can generate characters within each grid.

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 2/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

The number of the rectangular areas define the size of the LCD. The most
popular LCD is the 16×2 LCD, which has two rows with 16 rectangular
areas or characters. Of course, there are other sizes like 16×1, 16×4, 20×4
and so on, but they all work on the same principle. Also, these LCDs can
have different background and text color.

16×2 LCD Pinout


It has 16 pins and the first one from left to right is the Ground pin. The
second pin is the VCC which we connect the 5 volts pin on the Arduino
Board. Next is the Vo pin on which we can attach a potentiometer for
controlling the contrast of the display.

Next, The RS pin or register select pin is used for selecting whether we will
send commands or data to the LCD. For example if the RS pin is set on low
state or zero volts, then we are sending commands to the LCD like: set the
cursor to a specific location, clear the display, turn off the display and so
on. And when RS pin is set on High state or 5 volts we are sending data or
characters to the LCD.

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 3/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

Next comes the R/W pin which selects the mode whether we will read or
write to the LCD. Here the write mode is obvious and it is used for writing
or sending commands and data to the LCD. The read mode is used by the
LCD itself when executing the program which we don’t have a need to
discuss about it in this tutorial.

Next is the E pin which enables the writing to the registers, or the next 8
data pins from D0 to D7. So through this pins we are sending the 8 bits
data when we are writing to the registers or for example if we want to see
the latter uppercase A on the display we will send 0100 0001 to the
registers according to the ASCII table. The last two pins A and K, or anode
and cathode are for the LED back light.

After all we don’t have to worry much about how the LCD works, as the
Liquid Crystal Library takes care for almost everything. From the Arduino’s
official website you can find and see the functions of the library which
enable easy use of the LCD. We can use the Library in 4 or 8 bit mode. In

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 4/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

this tutorial we will use it in 4 bit mode, or we will just use 4 of the
 8 data
pins.

How to Connect Arduino to LCD – Wiring


Diagram
Here’s how we need to connect the 16×2 LCD display to an Arduino
board.

We will use just 6 digital input pins from the Arduino Board. The LCD’s
registers from D4 to D7 will be connected to Arduino’s digital pins from 4
to 7. The Enable pin will be connected to pin number 2 and the RS pin will
be connected to pin number 1. The R/W pin will be connected to Ground
and the Vo pin will be connected to the potentiometer middle pin.

You can get these components from any of the sites below:

16×2 Character LCD…………………….. Amazon / Banggood /


AliExpress

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 5/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

Potentiometer ……………………………. Amazon / Banggood


/
AliExpress
Arduino Board …………………………… Amazon / Banggood /
AliExpress
Breadboard and Jump Wires ……… Amazon / Banggood /
AliExpress

Disclosure: These are affiliate links. As an Amazon Associate I earn from


qualifying purchases.

Adjusting the contrast of the LCD


We can adjust the contrast of the LCD by adjusting the voltage input at the
Vo pin. We are using a potentiometer because in that way we can easily
fine tune the contrast, by adjusting input voltage from 0 to 5V.

Can I use the LCD without Potentiometer?

Yes, in case we don’t have a potentiometer, we can still adjust the LCD
contrast by using a voltage divider made out of two resistors. Using the
voltage divider we need to set the voltage value between 0 and 5V in

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 6/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

order to get a good contrast on the display. I found that voltage


of around
1V worked worked great for my LCD. I used 1K and 220 ohm resistor to
get a good contrast.

There’s also another way of adjusting the LCD contrast, and that’s by
supplying a PWM signal from the Arduino to the Vo pin of the LCD. We
can connect the Vo pin to any Arduino PWM capable pin, and in the setup
section, we can use the following line of code:

analogWrite(11,100); // Generate PWM signal at pin D11, value of 100 (out of 255)

It will generate PWM signal at pin D11, with value of 100 out of 255, which
translated into voltage from 0 to 5V, it will be around 2V input at the Vo
LCD pin.

LCD Arduino Code


Here’s a simple code through which we can explain the working principle
of the Liquid Crystal library. This is the code of the first example from the
video:

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 7/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

/*
* Arduino LCD Tutorial

*
* Crated by Dejan Nedelkovski,
* www.HowToMechatronics.com
*
*/

#include <LiquidCrystal.h> // includes the LiquidCrystal Library


LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

void setup() {
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and
}

void loop() {
lcd.print("Arduino"); // Prints "Arduino" on the LCD
delay(3000); // 3 seconds delay
lcd.setCursor(2,1); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("LCD Tutorial");
delay(3000);
lcd.clear(); // Clears the display
lcd.blink(); //Displays the blinking LCD cursor
delay(4000);
lcd.setCursor(7,1);
delay(3000);
lcd.noBlink(); // Turns off the blinking LCD cursor
lcd.cursor(); // Displays an underscore (line) at the position to which the next character will be written
delay(4000);
lcd.noCursor(); // Hides the LCD cursor
lcd.clear(); // Clears the LCD screen
}
 

Code description:

First thing we need to do is it insert the Liquid Crystal Library. We can do


that like this: Sketch > Include Library > Liquid Crystal. Then we have to
create an LC object. The parameters of this object should be the numbers
of the Digital Input pins of the Arduino Board respectively to the LCD’s
pins as follow: (RS, Enable, D4, D5, D6, D7). In the setup we have to
initialize the interface to the LCD and specify the dimensions of the display
using the begin() function.

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 8/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

In the loop we write our main program. Using the print() function
 we print
on the LCD.

lcd.print("Arduino"); // Prints "Arduino" on the LCD

The setCursor() function is used for setting the location at which


subsequent text written to the LCD will be displayed.

lcd.setCursor(2,1); // Sets the location at which subsequent text written to the LCD will be displayed

The blink() function is used for displaying a blinking cursor and the
noBlink() function for turning off.

lcd.blink(); //Displays the blinking LCD cursor

The cursor() function is used for displaying underscore cursor and the
noCursor() function for turning off. Using the clear() function we can clear
the LCD screen.

lcd.clear(); // Clears the LCD screen

Scrolling text example on 16×2 LCD and


Arduino
In case we have a text with length greater than 16 characters, we can scroll
the text using the scrollDisplayLeft() or scrollDisplayRight() function
from the LiquidCrystal library.

Here’s an example code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 9/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

void setup() {
lcd.begin(16, 2); 
lcd.print("Scrolling Text Example");
}
void loop() {
lcd.scrollDisplayLeft();
delay(500);
}

We can choose whether the text will scroll left or right, using the
scrollDisplayLeft() or scrollDisplayRight() functions. With the delay()
function we can set the scrolling speed.

If you want more control over how the text is scrolling, you could also
make the scrolling on your own using a “for” loop. Here’s an example:

#include <LiquidCrystal.h>

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

void setup() {
lcd.begin(16, 2); // Initializes the interface to the LCD screen, and specifies the dimensions (width an

void loop() {
// scroll text to the right
for (int i = 0; i <= 13; i++) {
lcd.setCursor(i, 0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("LCD");
delay(500); // 1 second delay
lcd.clear(); // Write a character to the LCD
}
// scroll text to the left
for (int i = 12; i >= 1; i--) {
lcd.setCursor(i, 0);
lcd.print("LCD");
delay(500);
lcd.clear();
}
}
 

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 10/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

How to Generate and Display Custom 


Characters on the LCD
In addition to the ASCII characters, with the LiquidCrystal library it is also
possible to generate and display custom characters on the LCD.

We can specify the appearance of each character by an array of 8 bytes.


Here’s an example code:

#include <LiquidCrystal.h>

byte heart[8] = { // Array of bytes


B00000, // B stands for binary formatter and the five numbers are the pixels
B01010,
B11111,
B11111,
B01110,
B00100,
B00000,
B00000
};

byte smile[8] = {
B00000,
B00000,
B01010,
B00000,
https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 11/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

B10001,
B01110, 
B00000,
B00000
};

byte lock[8] = {
B01110,
B10001,
B10001,
B11111,
B11011,
B11011,
B11111,
B00000
};

byte character[8] = {
B11111,
B10101,
B11111,
B01010,
B01110,
B11111,
B01110,
B01110
};

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)

void setup() {
lcd.begin(16, 2); // Initializes the interface to the LCD screen, and specifies the dimensions (width an
lcd.createChar(0, heart); // Create a custom character
lcd.createChar(1, smile);
lcd.createChar(2, lock);
lcd.createChar(3, character);

// Clears the LCD screen


lcd.clear();

// Print a message to the LCD


lcd.print("Custom Character");
}

void loop() {
lcd.setCursor(1, 1);
lcd.write(byte(0)); // Display the custom character 0, the heart

lcd.setCursor(5, 1);
lcd.write(byte(1));

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 12/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

lcd.setCursor(9, 1);
lcd.write(byte(2)); 

lcd.setCursor(13, 1);
lcd.write(byte(3));
}

We can notice how we can specify the appearance of the character by


changing the 0s into 1s within the 5×8 pixels grid.

In the setup we have to create the custom character using the


createChar() function.

lcd.createChar(0, heart); // Create a custom character

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 13/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

The first parameter in this function is a number between 0 and 


7, or we
have to reserve one of the 8 supported custom characters. The second
parameter is the name of the array of bytes.

We write the custom character to the display using the write() function
and as a parameter we use the number of the character.

lcd.write(byte(0)); // Display the custom character 0, or the heart

See also: Arduino Touch Screen Tutorial | TFT LCD

Conclusion
So, we have covered pretty much everything we need to know about using
an LCD with Arduino. These LCD Character displays are really handy for
displaying information for many electronics project. In the examples above
I used 16×2 LCD, but the same working principle applies for any other size
of these character displays.

I hope you enjoyed this tutorial and learned something new. Feel free to
ask any question in the comments section below and don’t forget to check
out my full collection of 30+ Arduino Projects.

 Arduino Tutorials

How to Control Servo Motors with Arduino – Complete Guide

nRF24L01 – How It Works, Arduino Interface, Circuits, Codes

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 14/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

25 thoughts on “Arduino 16×2 LCD Tutorial –


Everything You Need to Know”

Ekin
April 1, 2020 at 7:43 pm

Hello! I know it is late but I have to ask this question, my lcd only
shows blue screen I checked wires tons of times and tried to adjust
potentiometer but not works. I hope you could help me

Reply

Dejan
April 2, 2020 at 10:11 am

Hey, well you have already tried the recommended things when it
comes to that problem, only blue screen. Very often it’s problem
with the contrast, but you said you have tried with a
potentiometer. Try also by making a 3.3v voltage divider using two
resistors. Also the problem might be something else, maybe your
LCD have a different driver on its board that might not be
compatible with this example, I don’t know, maybe. Or maybe,
your LCD is faulty one.

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 15/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

Reply

Brian
January 27, 2020 at 5:49 pm

I GREATLY appreciate the help to be able to understand how to use


the the LCD!

Reply

ISaiD
March 14, 2019 at 3:57 pm

For those who don’t have a potentiometer, the potentiometer is


optional, you can use ‘analogWrite()’ function:

void setup() {
some code here;
analogWrite(your VO pin, 50);
some code here too;
}

Reply

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 16/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino


wayan kw
May 9, 2018 at 3:16 am

why use potentiometer, can i remove potentiometer?

Reply

Dejan Nedelkovski
May 9, 2018 at 8:51 am

Yes, you can remove it, but you will need to set two resistors as a
voltage dividers to get the proper voltage for getting the proper
contrast of the LCD.

Reply

Arduino is Life
September 24, 2021 at 7:49 pm

how do you make the voltage divider and what are the values of
the resistors?

Reply

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 17/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino


Muhammad Malik Bilal
February 24, 2018 at 1:57 pm

Really appreciate your work!

Reply

John McGraw
March 16, 2017 at 2:58 pm

Have no experience with writing code but you have made it easier
to understand the basics, TY Dejan!

Reply

Dejan Nedelkovski
March 21, 2017 at 10:15 am

I’m glad to hear this. Thanks.

Reply

Hamza
November 5, 2016 at 11:10 am
https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 18/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino


I made it ! finally, it is working !
But you should not connect Anode to Vcc directly, since there is a
LED, so may burn it. You need a resistor of 220 Ohm, and you can
increase the resistance of you want a dimmer backlight. I connected
my resistor to a PMW port to control the backlight from the code.

Reply

Dejan Nedelkovski
November 9, 2016 at 12:25 am

Great, connecting the backlight control to a PMW port and a


resistor is cool idea.

Reply

lioooo
October 17, 2016 at 5:32 pm

can we print something permanently , I mean its displayed again on


the LCD after reboot the LCD ?
and never changed again until you run the programming again ?

Reply

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 19/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino


Dejan Nedelkovski
October 18, 2016 at 1:05 am

Not really, you can print something permanently, but sure you can
make a code that would display what you want even after
rebooting the LCD, for example, using the EEPROM of the Arduino
which can store data when the power is off.

Reply

Anggi
April 30, 2016 at 3:03 pm

sir, if use I2c, what the codes ?

Reply

Dejan Nedelkovski
May 2, 2016 at 8:19 am

It would be different. I don’t have that code.

Reply

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 20/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino


Maria
March 23, 2016 at 10:11 am

avrdude: ser_open(): can’t open device “\\.\COM13”: The system


cannot find the file specified.

There’s an error. How to fix this.

Reply

Dejan Nedelkovski
March 24, 2016 at 10:42 pm

Check what’s your COM Port number.

Reply

magic
February 15, 2016 at 4:20 pm

Strange to use the D1 pin,


is that wanted or specific to RS LCD functionalism ?

Reply

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 21/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino


PP
February 3, 2016 at 7:58 pm

Why put code that doe’s not compile…???

Reply

Dejan Nedelkovski
February 5, 2016 at 8:40 am

The code is working properly. You might be doing something


wrong. What error do you get?

Reply

Brian
December 17, 2015 at 1:00 am

thank you so much! i have learn’t so much better with hands on


and you made it perfect for me ! thanks again!!!

Reply

Dejan Nedelkovski
December 17, 2015 at 8:42 am
https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 22/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino


I’m glad to hear that. You are welcome!

Reply

Anjana Perera
August 7, 2016 at 7:06 am

I highly appreciate that your video for LCD. I like to know whether
you have upload video for LCD though I2C module?. if so kindly
pass me a link (URL)

Reply

Dejan Nedelkovski
August 14, 2016 at 10:13 pm

Thanks. Sorry but I don’t have such a tutorial yet.

Reply

Leave a Comment

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 23/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

Name *

Email *

Website

Post Comment

Hey I'm Dejan, a maker, a techie and a mechatronics engineer. I love making
electronics and robotics projects for you to learn and make something cool on
your own.

Don't forget to check my 690K+ subs YouTube Channel.

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 24/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

MY FAVORITE 3D PRINTER

Creality K2 Plus Review – One of the Best 3D Printers

MY TOOLS RECOMMENDATIONS

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 25/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

Best Budget Oscilloscopes for Beginners and Makers

FEATURED PROJECTS

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 26/27
3/27/25, 11:38 PM Arduino LCD Tutorial | How To Connect an LCD to Arduino

How To Mechatronics

HowToMechatronics is an education website in the area of Mechanical,


Electrical and Computer Engineering. Tutorials, Tips, Tricks, How It
Works, Projects, Examples, Source Codes, Download files and much
more can be found here.

Disclosure

HowToMechatronics is a participant in the Amazon Services LLC


Associates Program, an affiliate advertising program designed to
provide a means for sites to earn advertising fees by advertising and
linking to Amazon.com

Copyright © 2025 HowToMechatronics.com. All rights reserved. Terms and Conditions | Privacy Policy

https://howtomechatronics.com/tutorials/arduino/lcd-tutorial/#what-is-lcd-character-display 27/27

You might also like