How to Use The 1602 LCD

How LCD Screen Work

Light Polarization

LCD screens uses light polarization phenomena to work without consuming a lot of energy, this is why we find them everywhere, in Calculators, Air Conditioner Remote, Radio, Watches…
Light is an electromagnetic wave has a lot of vibrations in many directions, and that is called unpolarized light.
To convert unpolarized light into polarized light we need to use a polarizing filter to let only light vibration that travels in one plane to pass-through.

An interesting trick happens when we place two polarizers on top of each other and rotate one of them 90°, the light passing through the first filter is polarized in one direction but it is incapable of passing through the next one.

LCD Screen Composition

LCD screens are mainly composed of two polarizing filters, rear and front electrodes are covered with a conductive coating and one of them is conductive in the shape that we want to see it on the screen. This shape could vary from one LCD to another according to the application needs.

In the middle, are the liquid crystals and it is a material whose molecules
behave in a quirky way to rotate the polarization of light and let it pass through the next polarizer.
When we apply a voltage to this kind of material it will be incapable of rotating the polarization of light thus we will see the darkness in the area that is exposed to the electric field. because the light is not passing through the next polarizer.

Getting Familiar With The Device

LCD stands for Liquid Crystal Display and 1602 means it has 16 columns and 2 rows. On the screen, there is 32 Matrix (16*2 matrix) every matrix is composed of 40 Pixel (5*8 pixel) to display a character.

Because this is CMOS technology
VSS is the GND pin and VDD is the VCC pin.
V0 is the brightness control voltage of the LCD characters.
RS is the Register Select pin.
For example :
If we want to display something on the LCD RS = HIGH
The data register is selected and the INPUT Data is processed there.
If we want to send commands to the LCD (like cursor blink, clear the display..) RS = LOW
The command register is selected and the INPUT Data is processed there.
RW is Read or Write pin
Rw = HIGH
We can read data from the HD44780 registers.
Rw = LOW
We can write data to the HD44780 registers.
E is the Enable pin
E = HIGH ability to see the result on the LCD screen.
E = LOW we will not see anything.
From D0 to D7 are the 8 DATA Input pins.
A is the Anode of the backlight LED.
K is the Cathode of the backlight LED.

Connecting The 1602 LCD Screen With Arduino

4 Bit Mode

In this example, we will be using the 4-bit mode for fewer wires

  • To use the 8-bit mode of the LCD you will be using 8 wires for the 8 DATA Input pins(D0, D1,.., D7) of the LCD to hook them up with the Arduino.
    For example, if you would like to display the letter “H”, the Arduino write on the 8 DAT Input pins 0100 1000 according to the ASCII table.
  • To use the 4-bit mode of the LCD you will be using 4 wires for the 4 DATA Input pins D4, D5, D6, and D7.
    For example, if you would like to display the letter “H”, First the Arduino will split the 8-bit binary number into 2 nibbles (1 Nibble = 4 Bit) and write on the 4 upper DATA Input pins the HIGH nibble first the 4 most significant bits “1000” following by the lOWER nibble the 4 least significant bits “0100“.

Schematic

We are going to use a library called <LiquidCrystal.h> that will help us a lot to write the code, This library does come with the Arduino IDE software so you don’t have to install it.
You can Load the sketch from File > Examples > LiquidCrystal > HelloWorld or just copie the next one.

Code

#include <LiquidCrystal.h>// include liquidcrystal library
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);// create LCD object with the following parameters (RS=7, E=6, D4=5, D5=5, D6=3, D7=2)
void setup() {
  lcd.begin(16, 2);// set the type of LCD you are using, 16 columns and 2 rows
  lcd.print("Hello world!");// Print "Hello world!" to the LCD
  lcd.setCursor(0,1);// set the cursor to column 0, line 2
  lcd.print("stay home y'all!");// Print "stay home y'all!" to the LCD
}
void loop() {
  // as long as we are printing these messages once, we write them all in void setup, the place where the code will run once
}                                                             						

So basically to display any word, we will write
lcd.print("Hello world!");
To choose the place that we would like to display our message, we set the cursor to the target location then write our message
lcd.setCursor(0,1);//note that 0 is the 1st column and 1 is the second row
lcd.print("stay home y'all!");

You can go through the example sketches that come with the library to know more about what you can do with your LCD such as the blinking effect or the scrolling effect that gives more attention to the user.

Using The I2C Adapter

With fewer wires, we can control the 1602 LCD using The I2C Serial Interface Module
We will use the I2C Protocol to send serial data carrying the information that we want via the SDA and ACL pins you can find these pins respectively in A4 and A5 or just above the AREF pin of the Arduino UNO.
We will write a program that will enable the Arduino (The Master) to send serial data to the I2C adapter (The Slave) to control the LCD.

First of all, we should know the I2C Interface Module Address before you can run the main sketch.
You can Load the sketch by going to File > Examples > Wire > i2c_scanner or just copie the next one, Paste it on your Arduino IDE, upload it to the Arduino Board, Open the Serial Monitor, and copy your ADDRESS (address example “0x27”).

// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup() {
  Wire.begin();
  Serial.begin(9600);
  while (!Serial); // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
void loop() {
  int nDevices = 0;
  Serial.println("Scanning...");
  for (byte address = 1; address < 127; ++address) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();
    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println("  !");
      ++nDevices;
    } else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  } else {
    Serial.println("done\n");
  }
  delay(5000); // Wait 5 seconds for next scan
}						

Once you got your address go to Sketch > Include Library > Manage Libraries, Search for liquid crystal and install the one by Frank De Brabander.

Now load the sketch by going to File > Examples > LiquidCrystal I2C > HelloWorld and make sure to make the next changes.
LiquidCrystal_I2C lcd(0x27, 16, 2);// create lcd object with the following parameters (0x27=address, 16=16 columns, 2=2 rows)
Or you can just copy and paste the next sketch to your Arduino IDE.

#include <Wire.h> // include wire library
#include <LiquidCrystal_I2C.h> // include liquidcrystal i2c library
LiquidCrystal_I2C lcd(0x27,16,2);// create lcd object with the following parameters (0x27=address, 16=16 columns, 2=2 rows)
void setup()
{
  lcd.init();// initialize the lcd
  lcd.backlight();// backlight is on
  lcd.setCursor(0,0);// set the cursor to column 0, line 1
  lcd.print("Hello world!");// Print "Hello world!" to the LCD
  lcd.setCursor(0,1);// set the cursor to column 0, line 2
  lcd.print("stay home y'all!");// Print "stay home y'all!" to the LCD
}
void loop()
{
  // as long as we are printing these messages once, we write them all in void setup, the place where the code will run once
}

I hope you learned something, If you have any questions feel free to write them in the comments section down below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top