Publications

LCD Arduino

Using an LCD with Arduino

By Timothy Coyle

arduino

Eventually the time will come when you will want to add a display to your microcontroller project so that you can get real-time feedback on what's going on like with a temperature controller. There are different types of displays out there but the text liquid crystal display (LCD) is one of the most popular for microcontroller projects. Fortunately the Arduino has a built-in library for working with LCD displays.

LCD Modules and LCD Driver Chips

Most LCD displays that you can purchase are actually a module: it contains an LCD display driver chip (usually the Hitachi HD44780 or some variant) along with the other necessary circuitry to make the display work. Over at SparkFun (great place to buy your stuff by the way) you can find a datasheet for a LCD Module and a LCD Driver chip.

lcd arduino

In the diagram above for the LCD driver chip you can see there is a MPU Interface where you connect a microcontroller to drive the LCD driver chip. The LCD is a parallel interface so the LCD driver chip has to interface to the actual LCD display.

lcd arduino

Looking at the LCD Module block diagram you get a better understanding of how the LCD driver chip and the actual LCD display are connected together. By using a module all of the connections and the extra circuitry to connect the LCD driver chip to the display are already done for you. Now you can see that you will interface the Arduino to the LCD driver chip on the module along with some extra pins for the backlight display and the rest is taken care of for you.

Hardware Setup

lcd arduino

Most LCD modules will have a 16 pin configuration.

Vo => Constrast Adjust. You will need to connect a 10K pot to this pin in order to change the contrast.

RS => Register Select. Controls where in LCD memory you are writing to which can be data register or instruction register.

R/W => Read/Write. Select read or write mode.Write mode is "0" so often times you will see this pin connected to ground rather than use up an IO pin on the microcontroller.

E => Enable. Enable for read or write mode.

LED+/LED- => Backlight Pins.Connect to power and ground in order to provide backlight to the LCD display.

lcd arduino

As you can see from the picture above it can be a little messy to connect up the LCD module to the Arduino Uno board. I usually try to keep my wire colors coordinated so I know what are power, ground, and data but didn't have everything I needed this time around. Below is the circuit diagram which is easier to look at:

lcd arduino

LCD Sketch

The LCD module that I used was a 20x4 which means 20 characters per row and 4 rows. To display a message on the LCD display you need to put the message into the LCD display registers then put instructions in the LCD instruction register. This can be a little complicated but the Arduino has a built-in library to handle the low level interaction for you. The key is to use the right setup with the LiquidCrystal() function as described below from the Arduino website:

lcd arduino

Below is the Sketch for the Arduino Uno to send a message to the LCD:

//
//Date: 8/2/15
//Version: 1.0
//
//Comments:
//This sketch writes a message to a 20x4 character LCD display. 
//
// LCD Pinout Connection:
// RS Pin: Connect to digital input 2.
// Enable Pin: Connect to digital input 3.
// D4 Pin: Connect to digital input pin 4.
// D5 Pin: Connect to digital input pin 5.
// D6 Pin: Connect to digital input pin 6.
// D7 Pin: Connect to digital input pin 7.
// R/W Pin: Connect to Ground so in write mode which is logic low "0".
// Vo Pin: Connect to the 10K pot that is connected between power and ground.


// Arduino LCD Display Library
#include 

// Call the library with the right pin configuration
// In this sketch we are using: lcd(RS,EN,D4,D5,D6,D7) in 4 bit mode
LiquidCrystal lcd(2,3,4,5,6,7);

// The setup runs once when you press reset or power on the board
void setup() {
  // Setup the LCD display column and row
  // We are using a 20x4 display in this example
  lcd.begin(20, 4);
 
}

// Main code for Arduino goes in the loop function to be run over and over again
void loop() {
  lcd.setCursor(0, 0);  // set the start of the message to be first column first row
  lcd.print("Line 1");  // print a message to the LCD  
  lcd.setCursor(0, 1);  // set the cursor to print beginning of second line
  lcd.print("Line 2");  // print a message to the LCD
  lcd.setCursor(0,2);   // set the cursor to print beginning of third line
  lcd.print("Line 3");  // print a message to the LCD
  lcd.setCursor(0,3);   // set the cursor to print beginning of fourth line
  lcd.print("Line 4");  // print a message to the LCD
}

                            
GITHUB

Newsletter

Sign up for my monthly email newsletter Signal Bytes to get the latest on embedded hardware design