Arduino tutorial | 16 x 2 LCD display full explanation

Mr.ElectroUino
1
Hello Friends
As you know that there are so many devices are using LCD display to communicate between humans and machines like calculator, olds phone, weather station, even server and soon. It's very useful for an electronics project for display sensor value, date time and many more. There are different types of LCD display like 8x1, 16 x 2, 20x4 etc.
In this blog, I am using 16x2 Lcd display and I will explain multiple programs like blinking text, scroll, setCursor, custom character, animation, etc.


16x2 LCD interface:



In the 16x2 LCD display, we have 16 columns and 2 rows in which each block having 5x8 pixels. In that, we can display up to 32 characters and 8 custom characters. It has 16 pins for controlling data, display contrast, backlight and so on.


LCD pins explanation:



    1.     Vss/GND
 VSS pin is also called a ground pin or negative pin and we have to connects to the Arduino ground pin.

    2.     VDD/Vcc
VDD pin is also called a VCC pin or positive pin and we have to connect to the Arduino 5v pin.

    3.     Vo
Vo is used to controlling the display contrast with the help of a potentiometer.
    
     4.     Rs(Register Select)
Rs pin is used for selecting commands or data. When RS pin is low then we are sending commands to the LCD like set the cursor to a specific location, clear the display or scroll, etc. And when RS pin is High state so then we are sending data or characters to the LCD and then the input will provide d0 to d7 for printing data.

     5.     R/W  (Read/write)
R/w pin is used for selecting the operations of read/Write.
To perform the write mode the R/W should be LOW.
To perform the read mode the R/W should be HIGH.
  
     6.     E (enable)
Enable pin will be work like sync or refresh for every changing of data.
We have to make enable pin high to low then LCD understand that you have to change the data.
                       
7 - 14:  D0 ~ D7
Pins used to send commands or data to the LCD.

15.  A(anode)+
it is a Backlight LED of the positive pin.

16.  K(Cathode)/gnd
it is a Backlight LED of the negative pin. k pin is also called a ground pin.


Working of 16x2 LCD display:


How to display capital “H” in a 16x2 LCD display?
For that, we have to send 4 bits of data. So that for entering in sending mode with the help of RS pin.
There are two modes in RS pin:
          1.     Command
     when RS pin is low then we are sending commands like a set cursor, clear screen, etc.    

          2.     Data
     when RS pin is high then we are sending data.

Note: For sending data the RS pin must Be high.

now we have permission to send data but we have to write a Character on LCD
for that, the next pin is R/W.
R/W is used to read and write mode
1.     To perform the write mode the R/W should be Low.
2.     To perform the read mode the R/W should be High.
Note: R/W pin must Be LOW for writing on the LCD display.


Next, enable pin
Enable pin will be work like sync or refreshing LCD.
for example when the enable pin goes high to low then LCD understands that you have to change the data.


next d0 to d7 pin.
it is used to send data or command.
There are 2 modes for sending data
1. 4bits
2. 8bits
now we have to display Capital H the binary number of capital H is 01001000
In this tutorial, we will send 4 bits of data that why we use 4 pins d4 to d7.
so we have to divide 8 bits into 4, 4 bits.
so first send for 4bits and then enable pin goes high to low and then another four bits again enable pin goes high to low and then Capital H will be Display.


Component required in this project.
1. Arduino Uno
2. 16x2 LCD display
3. 10k potentiometer               
4. 220-ohm resistor
5. jumper wire
6. breadboard


Circuit Diagram

Step1: Take a jumper wire and connect LCD k pin to Arduino Gnd pin

Step2: Attach a 220 ohms resistor to LCD A pin and at the end of the resistor is connected to the Arduino 5v pin.
Note: Using the resistor to protect LCD backlight.

Step3: connect Arduino digital pin 2 to LCD d7 pin
             connect Arduino digital pin 3 to LCD d6 pin   
             connect Arduino digital pin 4 to LCD d5 pin
             connect Arduino digital pin 5 to LCD d4 pin

Note: leave  d3, d2,d1,d0  LCD pin, we send only four-bit of data that why we don't need this pin.

Step4: connect Arduino digital pin  11 to LCD E (Enable)pin.

Step5: Connect Arduino gnd pin to LCD R/W (read/Write) pin.
Step6: Connect Arduino digital pin 12 to LCD RS (register selector)pin.
Step7:  Take a 10k  potentiometer to control display contrast for clear vision.

  Ø connect p1 pin  to Arduino gnd pin.
  Ø connect p2 pin  to LCD vo pin.
  Ø connect p3 pin  to Arduino 5v pin.

Step8:  connect Arduino 5v pin to an LCD VDD or VCC pin.
Step9: connect Arduino gnd pin to an LCD VSS or gnd pin.

Coding with explanation:
we have to start with simple programs to print a hello world on the LCD display.

HELLO WORLD Program:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
    lcd.begin(16, 2);
    lcd.print("hello, world!");
}
void loop() {
}


#include <LiquidCrystal.h>
Includes the library. Library provide us extra functionally and also reduce number the code.
LiquidCrystal LCD(12, 11, 5, 4, 3, 2);
create a liquid crystal object LCD  and pass some parameter, Arduino uses these pins to connect to the LCD(rs, en, d4, d5, d6, d7).

lcd.begin(16, 2);
 In void setup, we have to initialize the LCD interface like column and row with the help of begin function. lcd.begin(16col and ,2 row);
 
  lcd.print("hello, world!");
after that write the print function to display a message.
 use with object name lcd.print("hello, world!");
 

   
we can also set the position of the text.

setCursor

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  lcd.begin(16, 2);
}
void loop() {
  lcd.setCursor(2, 1);
  lcd.print("Hello");

  delay(100); 
  lcd.clear();
  delay(100);
}

           
if you want to set the position of text there is the function called setCursor in that we have 0 to 15 columns and row 0 or 1.
write object name lcd.setCursor(column, row); in parentheses define the position of text where we want to display. Column :0 to 15  row : 0 and 1 

Note: one thing always write a setCursor function upon the print function

We can also blink the text with the help of clear function The clear function is used to clear the screen for that write a print function in void loop
because in the void loop the code runs again and again.

Note: Like this format….
lcd.print(“Blink”);
Delay(100);
lcd.clear();
Delay(100);


Scroll right and left
Right now we can print up to 16 character at one row if you want to print above the 16 character it will not display but we can display it with the help of scrollDisplay Left or right function
This function also helps us to move a text in left or right direction.
where we can print up to 40 characters in one row.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
  lcd.print("hello, world!");
}
void loop() {
lcd.scrollDisplayLeft();
//lcd.scrollDisplayRight();
 delay(1000); 
}


lcd.scrollDisplayLeft();
  scroll a text to left direction and we can print up to 40 character at one row.

delay(1000);
Adding of delay to move per ALphabet at a rate of one second per character
 



Question:
If you have any questions so comment below.

Watch this:-

If you like this video so give it Thumps up and don't forget to subscribe to my channel for more video.

Post a Comment

1Comments

  1. This is a great article with lots of informative resources. I appreciate your work this is really helpful for everyone. Check out our website digital signage singapore for more zoomvisual.com.sg related info!

    ReplyDelete
Post a Comment