Arduino LCD Tutorial: A must have for Arduino Projects
Interfacing a character LCD to an arduino is one of the coolest things that you can do on the arduino. Most of the best arduino projects around the world sport one of these LCD displays. These LCDs can be used to display information from the arduino or any sensor connected to it. For example, you can create a temperature monitoring system, which displays the temperature on the arduino. Or you can make your own speedometer, that displays the speed via the LCD. So, depending on what you want to build, an LCD is a highly useful output device for your arduino.
This arduino LCD tutorial will show you to interface a character LCD with an arduino. You can use the information from this post to build your own LCD based arduino projects. Here, the LCD displays the text that we have programmed into the arduino. You can modify and use the code posted here accordingly.
What are the stuff required to do this project?
- Arduino or an arduino clone board (freeduino), or make your own custom arduino board with this tutorial.
- A character LCD, like this: character LCD.
- 10K potentiometer.
- 16 pin male and female headers for connecting to the LCD and a breadboard.
How does it work?
LCDs are the easiest and coolest kinds of devices that you can use for displaying the output from arduino projects. However, there are two types of LCDs that are available. They are: graphical LCDs and character LCDs. We are going to be working on character LCDs here, as they are the easiest to work on. Also, based on the size of the LCD, there are different types of them
available. Some of the most commonly used are:
- 16×2 character LCD (16 columns and 2 rows).
- 20×4 character LCD (20 columns and 4 rows).
And they are also available in different colors:
- Green LCDs with black characters.
- Blue LCDs with white characters.
- Red LCDs with black characters.
- And many more.
However, green and blue LCDs are the most common ones. The other colors are a bit difficult to obtain. In this tutorial, we are going to be using a 20×4 blue character LCD.
The arduino talks to the LCDs via the four data lines. Here, we are using the digital pins on the arduino to talk to the LCD and display what we want on it. Apart from these lines, there is a also an enable pin, RS pin and a RW pin. The backlight on the LCD is activated when you give 5V from the arduino to pin no 15 on the LCD and by grounding pin no 16. Apart from this, you also need a 10K potentiometer to adjust the contrast of the LCD.
Arduino LCD tutorial Step 1: Setting up the initial set of connections
Before you start following this arduino LCD tutorial, you need to first solder the 16 pin male headers on to the LCD. You can then either use a 16 pin female header to connect to the arduino. Or just use female to female connectors to connect to the arduino pins. And it will also be easier, if you use a breadboard for interfacing it the first time.
The first step that you need to do before working on the LCD, is to check it. For this, do the connections as shown in the above diagram. Connect pin no 15 on the LCD to arduino’s 5V pin. Next, connect pin no 16 on the LCD to arduino’s GND pin. These pins are used to power the backlight of the LCD.
Now, you need to setup the logic for the LCD. For doing this, connect pin no 1 of the LCD to arduino’s GND pin. And pin no 2 of the LCD to arduino’s 5V pin. Next, you need to set up the contrast adjusting potentiometer. Take the 10K potentiometer and connect the first terminal to arduino’s 5V pin. The second terminal (middle pin) to the LCD’s pin no 3. And the third terminal to arduino’s GND pin. Please check out the above diagram for the connections.
Next, power up the arduino. You will notice that the backlight on the LCD turns ON. And also, when you turn the knob on the potentiometer, the character blocks on the LCD turns bright/dim. Check out the picture on the bottom to see what I am talking about. If you were able to observe this, then it means that you’re LCD is correctly set up. If you were not able to achieve this, double check your connections and your potentiometer.
Step 2: Completing the connections for the arduino LCD
Now, we need to connect the data lines and other pins for working with the LCD. Check out the connection diagram given below. Interconnect the arduino and the LCD as shown in the diagram.
First, let us start connecting the control wires for the LCD. Connect the LCD’s pin no 5 (RW) to arduino’s GND pin. This pin is not used, and serves as the Read/Write pin. Next, connect the LCD’s pin no 4 (RS) to arduino’s digital pin 7. The RS pin is used to tell the LCD whether we are sending data to it or commands (to change the position of the cursor). Next, connect the LCD’s pin no 6 (EN) to arduino’s digital pin 8. EN is the enable pin on the LCD, which is used to tell the LCD that data is ready for reading.
Next, we have to connect the four data pins on the LCD. Connect the LCD’s pin no 14 (DB7) to arduino’s digital pin 12. Then, LCD’s pin no 13 (DB6) to arduino’s digital pin 11. Next, the LCD’s pin no 12 (DB5) to arduino’s digital pin 10. And then the LCD’s pin no 11 (DB4) to arduino’s digital pin 9.
That’s it, you have finished wiring up the LCD to the arduino. And you will notice that there are four unconnected pins between the control pins and the data pins on the LCD, as shown.
Step 3: Uploading the code to the arduino LCD
We can now try displaying something on the LCD through the arduino. Before you do that, you need to download the arduino LiquidCrystal library. You can get it from here: LiquidCrystal. Next, you need to extract the “LiquidCrystal” folder from the download file. And then, copy and paste the “LiquidCrystal” folder inside the arduino’s directory, an example of the final outcome directory: arduino-1.0.5librariesLiquidCrystal.
Next, open up your arduino IDE and then go to: File–>Examples–>LiquidCrystal–>HelloWorld. Upload the code to your arduino. You will see the following display on your arduino.
Please note: If you are using a 16×2 LCD, please edit the lcd.begin(20,4) to lcd.begin(16,2).
Step 4: Working with the arduino LCD
Try tinkering with the code for the LCD. Basically, there are two main functions used for controlling the text on the LCD:
- lcd.begin(total columns, total rows) – This function is used inside the setup(), to initialize the size of the LCD we are using. If it is 20×4, then: lcd.begin(20,4), else if it is 16×2, then: lcd.begin(16,2).
- lcd.setCursor(column number, row number) – This function places the cursor of the LCD on the desired position you want. Any text displayed after this function will start from the position you have mentioned. Example use: lcd.setCursor(4,0), i.e., fifth column and first row (since it starts from 0,0).
- lcd.print(“text”) – This function is used for printing the text on the LCD. Whatever string is placed inside the ” “, gets displayed on the LCD.
That’s about it, now you can add an LCD to all your arduino projects. Check out this demo video, showing the character LCD with arduino on action: