[go: up one dir, main page]

0% found this document useful (0 votes)
102 views6 pages

Arduino LCD Tutorial

This document provides an overview of connecting and programming a 16x2 LCD display with an Arduino board. It discusses the LCD pinout and shows how to connect the LCD to the Arduino. The code examples demonstrate printing text to the LCD, setting the cursor position, clearing the display, and creating a custom character. Connecting and programming the LCD involves using the LiquidCrystal library, initializing the LCD interface, and calling functions like print(), setCursor(), and createChar() to output text and control the display.

Uploaded by

ede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views6 pages

Arduino LCD Tutorial

This document provides an overview of connecting and programming a 16x2 LCD display with an Arduino board. It discusses the LCD pinout and shows how to connect the LCD to the Arduino. The code examples demonstrate printing text to the LCD, setting the cursor position, clearing the display, and creating a custom character. Connecting and programming the LCD involves using the LiquidCrystal library, initializing the LCD interface, and calling functions like print(), setCursor(), and createChar() to output text and control the display.

Uploaded by

ede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Arduino LCD Tutorial

Dejan Arduino Tutorials 24

In this Arduino LCD Tutorial we will learn how to connect an LCD (Liquid Crystal Display) to the Arduino
board. LCDs like these are very popular and broadly used in electronics projects as they are good for
displaying information like sensors data from your project, and also they are very cheap.

You can watch the following video or read the written tutorial below.

The LCD Pinout


It has 16 pins and the first one from left to right is the Ground pin. The second pin is the VCC which we
connect the 5 volts pin on the Arduino Board. Next is the Vo pin on which we can attach a potentiometer
for controlling the contrast of the display.

Next, The RS pin or register select pin is used for selecting whether we will send commands or data to
the LCD. For example if the RS pin is set on low state or zero volts, then we are sending commands to
the LCD like: set the cursor to a specific location, clear the display, turn off the display and so on. And
when RS pin is set on High state or 5 volts we are sending data or characters to the LCD.

Next comes the R / W pin which selects the mode whether we will read or write to the LCD. Here the
write mode is obvious and it is used for writing or sending commands and data to the LCD. The read
mode is used by the LCD itself when executing the program which we don’t have a need to discuss
about it in this tutorial.

Next is the E pin which enables the writing to the registers, or the next 8 data pins from D0 to D7. So
through this pins we are sending the 8 bits data when we are writing to the registers or for example if we
want to see the latter uppercase A on the display we will send 0100 0001 to the registers according to
the ASCII table.

And the last two pins A and K, or anode and cathode are for the LED back light.

After all we don’t have to worry much about how the LCD works, as the Liquid Crystal Library takes care
for almost everything. From the Arduino’s official website you can find and see the functions of the library
which enable easy use of the LCD. We can use the Library in 4 or 8 bit mode. In this tutorial we will use
it in 4 bit mode, or we will just use 4 of the 8 data pins.

Components needed for this Arduino LCD Tutorial

You can get these components from any of the sites below:
16×2 Character LCD…………………….. Amazon / Banggood
Potentiometer ……………………………. Amazon / Banggood
Arduino Board …………………………… Amazon / Banggood
Breadboard and Jump Wires ……… Amazon / Banggood

Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.

Circuit Schematic

We will use just 6 digital input pins from the Arduino Board. The LCD’s registers from D4 to D7 will be
connected to Arduino’s digital pins from 4 to 7. The Enable pin will be connected to pin number 2 and the
RS pin will be connected to pin number 1. The R/W pin will be connected to Ground and the Vo pin will
be connected to the potentiometer.
Source Codes

First thing we need to do is it insert the Liquid Crystal Library. We can do that like this: Sketch > Include
Library > Liquid Crystal. Then we have to create an LC object. The parameters of this object should be
the numbers of the Digital Input pins of the Arduino Board respectively to the LCD’s pins as follow: (RS,
Enable, D4, D5, D6, D7). In the setup we have to initialize the interface to the LCD and specify the
dimensions of the display using the begin() function.

In the loop we write our main program. Using the print() function we print on the LCD.
The setCursor() function is used for setting the location at which subsequent text written to the LCD will
be displayed. The blink() function is used for displaying a blinking cursor and the noBlink() function for
turning off. The cursor() function is used for displaying underscore cursor and the noCursor()function
for turning off. Using the clear() function we can clear the LCD screen.

Here’s the source code of the first example from the video:

1. /*
2. * Arduino LCD Tutorial
3. *
4. * Crated by Dejan Nedelkovski,
5. * www.HowToMechatronics.com
6. *
7. */
8.
9. #include <LiquidCrystal.h> // includes the LiquidCrystal Library
10. LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5,
d6, d7)
11.
12. void setup() {
13. lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions
(width and height) of the display }
14. }
15.
16. void loop() {
17. lcd.print("Arduino"); // Prints "Arduino" on the LCD
18. delay(3000); // 3 seconds delay
19. lcd.setCursor(2,1); // Sets the location at which subsequent text written to the LCD will be
displayed
20. lcd.print("LCD Tutorial");
21. delay(3000);
22. lcd.clear(); // Clears the display
23. lcd.blink(); //Displays the blinking LCD cursor
24. delay(4000);
25. lcd.setCursor(7,1);
26. delay(3000);
27. lcd.noBlink(); // Turns off the blinking LCD cursor
28. lcd.cursor(); // Displays an underscore (line) at the position to which the next character
will be written
29. delay(4000);
30. lcd.noCursor(); // Hides the LCD cursor
31. lcd.clear(); // Clears the LCD screen
32. }

It is also possible to write a custom characters to the LCD. It supports up to 8 characters of 5×8 pixels.
We can specify the appearance of each character by an array of 8 bytes. In the source code below we
can notice how we can specify the appearance of the character by changing the 0 into 1 which
represents the 5×8 pixels. In the setup we have to create the custom character using
the createChar() function. The first parameter in this function is a number between 0 and 7, or we have
to reserve one of the 8 supported custom characters. The second parameter is the name of the array of
bytes. We write the custom character to the display using the write() function and as a parameter we
use the number of the character.

Here’s the source code of the second example for custom characters:

1. #include <LiquidCrystal.h>
2.
3. byte slash[8]= { // Array of bytes
4. B00001, // B stands for binary formatter and the 5 numbers are the pixels
5. B00010,
6. B00100,
7. B01000,
8. B10000,
9. B00000,
10. B00000,
11. B00000,
12. };
13. LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5,
d6, d7)
14.
15. void setup() {
16. lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the
dimensions (width and height) of the display
17. lcd.createChar(7, slash); // Create a custom character for use on the LCD. Up to eight
characters of 5x8 pixels are supported
18. }
19.
20. void loop() {
21. for(int i=0;i<=15;i++) {
22. lcd.setCursor(i,0); // Sets the location at which subsequent text written to the LCD will
be displayed
23. lcd.write(7); // Writes a character to the LCD
24. delay(1000); // 1 second delay
25. lcd.clear(); // Write a character to the LCD
26. }
27. }

Feel free to ask any question in the comments section below.

You might also like