Here is another simplified project to connect the LCD 16×2, I have included both the methods.
- Direct interfacing of LCD 16×2 on Arduino
- Interfacing LCD 16×2 using I2C Module on Arduino
Method 1 is complicated as it involves a lot of connection. If you are a beginner and do not want your learning to stop, I would advise you to buy an I2C module which is cheap and easily available online. And then you can follow method 2.
An LCD (Liquid Crystal Display) screen is an electronic display module and has a wide range of applications. A 16×2 LCD display is very basic module and is very commonly used in various devices and circuits. A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5×7 pixel matrix. The 16 x 2 intelligent alphanumeric dot matrix display is capable of displaying 224 different characters and symbols. This LCD has two registers, namely, Command and Data.
Why is it called the LCD 16×2 ?
The LCD has 16 columns and 2 Rows. When we program the LCD we are going to point out the cursor position using the numbers in white. When we program we read numbers as 0,1,2,3,4,5,67,8,9,10,11,12,13,14 and 15. Similarly, we have 2 Rows 0 and 1.
Anything longer than 16 characters is unlikely to fit on the display. Hence while programming, count the characters that will be displayed on the LCD.
Interfacing LCD 16×2 with Arduino
The LCD being a display module comes in handy with many projects. So just interfacing an LCD is not enough.
But for now we are going to learn two methods to connect. But before that….
Things Needed
LCD 16×2 Pin Diagram
- GND should be connected to the ground of Arduino..
- Vcc is the Power supply of the LCD
- V0 controls the brightness of the LCD with a 10k potentiometer
- RS(Register Select) tells the LCD if arduino is sending a command or data.
- R/W (Read/Write)controls whether we want to read or write the data from the LCD. In this interfacing we will only write to the LCD so the pin will be grounded.
- E – Enable allows the LCD to display
- D0-D7 are the data pins through which arduino transmit the data(8 bits of data in total).
- A – Anode (+) for the backlight of the display
- K – Cathode (-) for the backlight of the display
Circuit Diagram (Method 1)
Connect the following circuit as shown in the diagram. Next step would be programming the Arduino to print characters on the LCD 16×2.
Code
Since the LCD is widely used in the industry, there is an liquid crystal library that will allow us to code the display.
Click here to download the libraries and see other content : https://github.com/rolan37/Arduino-LCD-16×2
Use the liquidCrystal library that is easily available on the IDE. Refer to the below code, edit and make it your own.
//LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
Circuit Diagram (Method 2)
I2C Module Pin Diagram
GND – Connected to the Arduino Ground
Vcc – Connected to the 5V on the Arduiono
SDA – is the Serial Data Line that sends data to the LCD
SCL – SCL is the clock line. It is used to synchronize all data transfers over the I2C bus
Code
Click here to download the libraries and see other content : https://github.com/rolan37/Arduino-LCD-16×2
Use the Arduino-LiquidCrystal-I2C-library-master.zip that is easily available on the link. Refer to the below code, and enjoy the easy method. Incase you want to see the demonstration of this activity. you can watch the video below.
Please keep in mind if the code is not functioning, it only means that you need to find your correct address of the LCD. Watch the video as I have explained how to fix it.
//Electronicssimplified - LCD I2C Module
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
lcd.begin();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Like | Share");
lcd.setCursor(0,3);
lcd.print("Subscribe");
}
void loop()
{
}
I have lcd 16X2 ,in project I use pic 16f876 in radio frequency Swr/power meter.I2c is attached with LCD.my question is (1) can I connect lcd with microcontroller (in circuit) keeping i2c attached with lcd? (2) how can I connect pic 16f876 , lcd using i2c circuit,as i2c has 4 pin where as I have to 8+2 ten pins from circuit.