Connect an LCD Display

H@KR Challenge 5.7 [60pts]

Adapted from Adafruit Industries Tutorials

The display has an LED backlight and can display two rows with up to 16 characters on each row. You can see the rectangles for each character on the display and the pixels that make up each character. The display is just white on blue and is intended for showing text.


STEP 1: Parts

To carry out the experiment described in this lesson, you will need the following parts.

1 Jumper wire pack Jumper wire pack
1 LCD Display (16x2 characters) LCD Display (16x2 characters)
1 10 kΩ variable resistor (pot) 10 kΩ variable resistor (pot)

STEP 2: Breadboard Layout

The LCD display needs six Arduino pins, all set to be digital outputs. It also needs 5V and GND connections.

Arduino LCD Fritzing Diagram

There are quite a few connections to be made. Lining up the display with the top of the breadboard helps to identify its pins without too much counting, especially if the breadboard has its rows numbered with row 1 as the top row of the board. Do not forget, the long yellow lead that links the slider of the pot to pin 3 of the display. The 'pot' is used to control the contrast of the display.

You may find that your display is supplied without header pins attached to it. If so, follow the instructions in the next section.

STEP 3: Lighting Up the Display

The Arduino IDE includes an example of using the LCD library which we will use. You can find this on the File menu under Examples > Liquid Crystal > HelloWorld.

However, this example uses different pins than the ones used here, so find the line of code below:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

and change it to be:

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 

Upload the code to your Arduino board and you should see the message 'hello, world' displayed, followed by a number that counts up from zero.

After uploading this code, make sure the backlight is lit up, and adjust the potentiometer all the way around until you see the text message

The pin matches are as follows:

LCD Pin Name LCD Pin Number Arduino Pin
RS 4 7
E 6 8
D4 11 9
D5 12 10
D6 13 11
D7 14 12

STEP 4: Customizing Display Text

The first thing of note in the sketch is the line:

#include <LiquidCrystal.h>

This tells Arduino that we wish to use the Liquid Crystal library.

Next we have the line that we had to modify. This defines which pins of the Arduino are to be connected to which pins of the display.

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

In the 'setup' function, we have two commands:

  lcd.begin(16, 2);
  lcd.print("hello, world!");

The first tells the Liquid Crystal library how many columns and rows the display has. The second line displays the message that we see on the first line of the screen.

In the 'loop' function, we aso have two commands:

  lcd.setCursor(0, 1);

The first sets the cursor position (where the next text will appear) to column 0 & row 1. Both column and row numbers start at 0 rather than 1.

The second line displays the number of milliseconds since the Arduino was reset.

Try This:

  • Try pressing the Reset button on the Arduino, notice that the count goes back to 0.
  • Try moving the position where the count is displayed to near the middle of the second row of the display.
  • Try changing the text on your display to be your name.

STEP 5: Save your Code GitHub!

cd ~/scholar-work-open
git branch
git checkout your-branch-name
git add *
git commit -a -m 'Hackshop Challenge 5.7'
git push origin your-branch-name