Arduino LCD Tutorial: A must have for Arduino Projects

 

Arduino LCD tutorial for beginners DIY Hacking

Arduino LCD tutorial for beginners

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?

Hardware:

  1. Arduino or an arduino clone board (freeduino), or make your own custom arduino board with this tutorial.
  2. A character LCD, like this: character LCD.
  3. 10K potentiometer.
  4. 16 pin male and female headers for connecting to the LCD and a breadboard.

Software:

Arduino IDE

How does it work?

Arduino LCD tutorial for Arduino projects DIY Hacking

Arduino LCD tutorial for Arduino projects

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

Arduino LCD tutorial for beginners DIY Hacking

Different colored LCDs

available. Some of the most commonly used are:

  1. 16×2 character LCD (16 columns and 2 rows).
  2. 20×4 character LCD (20 columns and 4 rows).

And they are also available in different colors:

  1. Green LCDs with black characters.
  2. Blue LCDs with white characters.
  3. Red LCDs with black characters.
  4. 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

Arduino LCD tutorial for beginners DIY Hacking

Arduino LCD tutorial – Soldered 16 pin headers

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.

Arduino LCD tutorial for beginners DIY Hacking

Arduino LCD tutorial – Initial connections

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.

Arduino LCD tutorial for beginners DIY Hacking

Arduino LCD tutorial – Adjusting the contrast

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.

Arduino LCD tutorial for beginners DIY Hacking

Arduino LCD tutorial – Final connections

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.

Arduino LCD tutorial for beginners DIY Hacking

Arduino LCD tutorial – Soldered 16 pin headers

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.

Arduino LCD tutorial for Arduino projects DIY Hacking

Arduino LCD tutorial – Arduino code

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.

Arduino LCD tutorial for beginners DIY Hacking

Arduino character LCD

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:

  1. 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).
  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).
  3. 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:

Recommended Posts
Showing 4 comments
  • Nidhiya
    Reply

    Good one indeed!

  • Athul krishna
    Reply

    The picture you used in the homepage,it is a speedometer cum other stuff thing right?
    Could you please give a tutorial on that?

  • Sathiakiumar
    Reply

    It is very much interesting.

    • Naeem
      Reply

      dear!!! from where i can find arduino code…….
      can u provide it.

Leave a Comment

23 + = 30

Start typing and press Enter to search