Arduino Code

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.

This example uses different pins to the ones we use, so find the line of code below:

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

and change it to be:

Download: file
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.

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

Download: file
#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.

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

The arguments to this are as follows:

Display Pin Name Display Pin Number Arduino Pin (in this example) RS 4 7 E 6 8 D4 11 9 D5 12 10 D6 13 11 D7 14 12
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

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

Download: file
  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 also have two commands:

Download: file
  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.

This guide was first published on Dec 13, 2012. It was last updated on Dec 13, 2012. This page (Arduino Code) was last updated on Feb 27, 2018.