Connecting a character LCD to an Arduino

The other day I was trolling SparkFun’s website for Arduino related items and came across a standard 16×2 character display with a black background and a red back-light. Being addicted to all things Arduino, I decided to purchase the display and get a bit more acquainted with it. Liquid crystal displays (LCD) come in different shapes, colors and sizes. The most basic is a 16X2, which means 16 character by 2 lines, but there are other options available, like 16X1, 16X4, and 20X4.
The Arduino uses the LiquidCrystal library to communicate with the LCD display. You can use any Arduino analog/digital pin to connect to the LCD pins. The cool thing is, most of the standard displays are swappable. For example, if you wire your project for a 16X2 display and decide later to upgrade to a 16X4 display, you can easily swap the old display for the new one, and it will work like before, granted you will have to update a few variables in the code to utilize the larger display size.

So, lets get this party started!
I assume you already have the basics such as:

Arduino Duemilanove,

a character LCD display with 0.1 header 16 pins long and a 10K potentiometer to adjust the contrast on the display,

a breadboard,

and breadboarding wire.

If you haven’t already done so, solder the strip of header to the LCD. The easiest way to do this is to stick the header into a breadboard and then sit the LCD on top, It helps to keep the LCD steady while soldering. Once you have the header soldered to the LCD, lets take a look at the pins on the LCD.

Most modern LCDs come with one row of sixteen pins
The first fourteen pins are used to control the display and the last two are reserved for the backlighting.
Its not necessary to use all the pins to communicate with the Arduino.

Pins 1, 2 & 3 are utilized by the potentiometer.
Pin 1 is for a ground (-).
Pin 2 is for a positive +5volt.
Pin 3 a.k.a the VEE pin connect to +5 and GND through 10k potentiometer to adjust the display contrast.

Pin 4 a.k.a the RS pin is set for character data or cleared for a command, it basically lets Arduino tell the LCD whether it wants to display data or whether it is a command byte like, change the position of the cursor.

Pin 5 a.k.a. the RW pin is used to set the direction, whether we want to write to the display or read from it, in our case we will ground it since we will be writing to the display, which is the most common use of an LCD display.

Pin 6 a.k.a the E pin is the ‘enable’ line, it loads the data, RW and RS into the LCD.

Pin 7 -14 are data pins or a 8-bit bi-directional data line.

Pin 15 is the backlight power supply positive(+).

pin 16 is the backlight power supply negative(-).

Now you should have a basic understanding of each pin and what it is used for, now lets wire up the LCD.
Lets first start out by wiring up the backlight to the Arduino.

For the sake of simplicity, I decided to provide illustrative images instead of a shot by shot of my breadboard, also the pin wiring conforms to the example sketch provided by the Arduino Ide.

The diagram below illustrates the use of a breadboard, where the Red line demonstrates a positive power rail and the Black line a negative power rail or ground. One can assume the LCD is connected to a row in the breadboard.

Simply connect a wire from the 5v of the Arduino to the positive rail on the breadboard. Connect a wire from the GND of the Arduino to the ground rail on the breadboard. Then connect a wire from the positive (+) rail to pin 15 of the LCD. Connect a wire from the ground (-) rail to pin 16 of the LCD. Connect the Arduino up to power via the USB or an external power source and you’ll notice the back light lights up

Now lets hook up the potentiometer.

Place the pot on its own row on the breadboard. Connect a wire from the ground rail to the pot (it doesn’t matter which leg/side you place it on), do the same for the positive connection. Then connect the middle of the pot (wiper) to Pin 3 of the LCD. Now wire up the logic of the LCD – this is separate from the back light! Connect a wire from the LCD Pin 1 to the ground rail and connect a wire from the LCD pin 2 to the positive (+) rail.
If the connections are correct you will be able to adjust the contrast of the LCD which will display a single line of rectangles.

Now all we have to do is wire up the data lines.

Lets start by grounding the RW pin, I mentioned early that we don’t need to use it. Connect a wire from the ground rail on the breadboard to the pin 5 of the LCD display.

Next connect the RS pin to the Arduino and LCD Screen. Connect a wire from the LCD pin 4 to the Arduino digital pin 12.

Next connect the E pin to the Arduino and LCD Screen. Connect a wire from the LCD pin 6 to the Arduino digital pin 11.

And finally connect the remaining data lines.
Connect Pin 11 of the LCD to the Arduino digital pin 5.
Connect Pin 12 of the LCD to the Arduino digital pin 4.
Connect Pin 13 of the LCD to the Arduino digital pin 3.
Connect Pin 14 of the LCD to the Arduino digital pin 2.

All we have left to do is upload the Hello World sketch to the Arduino.

Open up the Arduino IDE, if its not already open and navigate to File->Examples->LiquidCrystal->HelloWorld and upload the sketch. If all was wired correctly, you will see Hello World printed to your LCD.

Most displays work with the standard 128 ASCII characters. Often times, the displays are also able to display other characters, these include Asian characters and other special symbols and icons.
Sending text to the display is very straight forward, you simply send the ACSII text and it will display.
You can change the Hello World message by navigating to the line of code in the sketch:

lcd.print(“hello, world!”);

and change it to:

lcd.print(“Arduino Rocks!”);

compile and upload the sketch.

This is just the tip of the iceberg, let your imagination run wild and learn to utilize the LCD as visual feedback in your projects or head over to Nerd By Nature for a version of an Arduino hangman game.
One thing to keep in mind is that a 16×2 LCD will cut off anything past the 16th character, so be aware of your chacater count..
Also numbers are a bit trickey.
For example, if you want to pass the number 1 to the display you will either get nothing or a strange looking character. The reason why is ASCII number for the character “1” is 49. A handy tip is to add 48 to any number that you are sending to the display.
Another caveat is you can only send a single digit at a time to the display. So if you have the value of 100 to display, first it must be chopped into “1”, “0”, and “0” then you must add 48 to each before sending them to the display to convert the value into ASCII.

Here’s a cheat sheet for characters that will come in handy.

Well that concludes my quick tutorial, I hope this helps someone understand the connection between a standard LCD display and Arduino.

9 thoughts on “Connecting a character LCD to an Arduino

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: