Use one LCDs displays with Arduino

LCD_display

I’m going to show how to control one LCD display with Arduino. In this example I’m just going to display a 10 second timer which goes forwards and backwards. As it can be seen in the picture above, I will use a potentiometer to manage the contrast of the LCD display. There are other ways to control it, even with the Arduino board but I find this to be the easiest one.

Requirements:
1. Arduino with an USB connection and the Arduino IDE installed.
2. One LCD display: there are many options available, for this post I’m using a cheap 1602 16×2 Character display which uses a HD44780 controller from China. Mine works pretty well, but if you want to be sure about the quality of the device, you can go for a similar Adafruit LCD Display.
3. A 2K Ohm linear potentiometer to control the contrast of the screen.
4. A breadboard and some wires to connect your LCD display to the Arduino board and to the potentiometer.

Circuit diagram:
The most complicated thing of this circuit is to connect all the wires to each pin, the image below shows how everything is wired up:

Arduino_and_LCD_display
Arduino and one LCD display. A potentiometer is used to control the contrast of the display.

The wiring may be difficult becuase the LCD display has many connections. These displays can be configured to use 4 or 8 bits and there is a small difference in speed, being the later faster. Yet, these displays are slow and the program gets complex if you want to use the 8-bit mode. Related to the Arduino library we need to use, it can be used for both 4 or 8-bit mode. So, because we don’t win too much with the speed and to save pins, we are going to use the 4-bit mode in this example.

For the circuit that means that we don’t use pins D0 to D3 but we still have 12 more pins to connect. To make things easier, you can find the following table with the connections of the LCD display. I also included the function of each pin:

LCD Display Pin
VSS (ground for the display) GND
VDD (Voltage for the display) 5V (it should also work with 3.3V)
VE (Contrast voltage for the screen) Potentiometer output (central pin)
RS (Register select) Pin 10 of Arduino board
RW (Read/Write pin) GND (sets the pin to write)
E (Enable pin) Pin 9 of Arduino board
D0 to D3 Not used, only required when 8 bit operation
D4 Pin 5 of Arduino bard
D5 Pin 4 of Arduino bard
D6 Pin 3 of Arduino bard
D7 Pin 2 of Arduino bard
A (Anode for backlight) 5V (lower voltage can be used for less light)
K (Cathode for backlight) GND

 

 

 

 

 

Arduino code:
The code needed to work with the display is the following one:

In the first line we call the LCD library from Arduino and in the second line we create an object called LCD. Be aware of the order of the pins: “LiquidCrystal LCD(RS,E,D4,D5,D6,D7)”. In the third line I just declare a variable for the counter called myCounter.

The code is ready to use the display, so we go to the void setup: we first start the LCD setting the size of the LCD. The size is set defining first the columns and then the rows, in this case, 16 by 2. Then we set the cursor in the first position (0,0) and LCD.print will write the string “My timer: “. We are going to change the values of the timer only in the second row. So we can include the first print instruction in the void setup and we don’t need to worry about it anymore.

Next step is inside the void loop where we create two for loops: the first one sets myCounter to 1 and it will add 1 until the value is 10. On the second for loop we give myCounter a value of 10 and it will subtract 1 until it reaches 0. Inside each for loop we do the same set of operations: we set the cursor on the first place of the second row (0,1) . A line of spaces to refresh the display replacing all the previous characters by an empty space. Then we set the cursor back to the beginning of the second row and we print the current value of the variable myCounter. It is important that now we don’t set again the position of the cursor back again. That makes the next print instruction write the string ” seconds” just after the previous string. We finish with a delay of 1000 miliseconds (1 second), that makes the code coun 1 second each time the loops runs.

Leave a Reply