Liquid Crystal Display Arduino tutorial

In this tutorial I will demonstrate the use a 1602 Liquid Crystal Display (LCD) with Arduino. This will involve four simple steps. You can find the pins configuration of the 1602 LCD by following the tutorial on the Introduction to 1602 Liquid Crystal Display.

1). What you will need 

  • Male to male jumper wires 
  • 1602 LCD compatible with Hitachi HD44780 driver 
  • Arduino board R3
  • Breadboard 
  • 10K ohm potentiometer 
  • 220 ohm resistor 
  • Arduino USB cable 

Arduino Liquid Crysta

2).  Connecting the Liquid Crystal Display with Arduino

  •        VSS pin of the LCD to ground
  •        VCC pin of the LCD to 5V
  •        RS pin of the LCD to digital pin 7 of the Arduino
  •        R/W pin of the LCD to ground
  •        E pin of the LCD to  digital pin 6 of the Arduino
  •        D4 pin of the LCD to  digital pin 5 of the Arduino
  •        D5 pin of the LCD to  digital pin 4 of the Arduino
  •        D6 pin of the LCD to  digital pin 3 of the Arduino
  •        D7 pin of the LCD to  digital pin 2 of the Arduino

    For  220 ohm resistor

  •         one end to A pin of the LCD and the other end to 5V

    For  10k ohm potentiometer

  •         Slider pin of the potentiometer to LCD VO pin of the LCD 
  •         A and B pins of the potentiometer to +5V and ground respectively

Arduino Liquid Crysta

3).  Type in the code

Open up your Arduino IDE and type in the code below. The sketch uses a nested for loop (loop within a loop) to calculate the product of two real numbers x and y and then displays the result z which is also a real number. 


//Include the LCD library
#include <LiquidCrystal.h>

//Initialize the LCD arduino pins
LiquidCrystal lcd(7,6,5,4,3,2);

void setup() {
  //LCD number of columns and rows:
  lcd.begin(16, 2);
}

void loop() {
 
 int x, y, z; //where we will have  x*y = z
 
   for(x=1; x<=9; x++) //Outer loop
  {
    lcd.clear(); //Clear the contents on the screen
    lcd.setCursor(3,0); // set the cursor to column 3, line 0
    lcd.print("TABLE NINE");
    for(y=1; y<=9; y++) //Inner loop
    {   
      z=x*y;  
      lcd.setCursor(3,1);  // column 3, line 1
      lcd.print(x);
      lcd.setCursor(5,1);  // column 5, line 1
      lcd.print("x"); 
      lcd.setCursor(7,1);  // column 7, line 1
      lcd.print(y);
      lcd.setCursor(9,1);  // column 9, line 1
      lcd.print("=");
      lcd.setCursor(11,1); // column 11, line 1
      lcd.print(z);
      delay(1000); // delay for 1 second 
    }
  }
}

4).  Power up and upload the sketch (code)

Power up your Arduino from your pc using usb cable and then upload the sketch onto your board. Refer to the below video.