0% found this document useful (0 votes)
159 views18 pages

Experiment No.7 Embedded System

This document provides information about interfacing an LCD 16x2 module with an Arduino. It describes the objective to gain knowledge about the LCD interface. The equipment needed includes an Arduino, LCD 16x2 module, connecting leads, and variable resistor. It then discusses the specifications and pin configuration of the LCD 16x2 module to understand its operation and how to interface it with a microcontroller like the Arduino. The working principle is also briefly explained that LCDs display data by changing the position of molecules to absorb or pass light in each pixel.

Uploaded by

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

Experiment No.7 Embedded System

This document provides information about interfacing an LCD 16x2 module with an Arduino. It describes the objective to gain knowledge about the LCD interface. The equipment needed includes an Arduino, LCD 16x2 module, connecting leads, and variable resistor. It then discusses the specifications and pin configuration of the LCD 16x2 module to understand its operation and how to interface it with a microcontroller like the Arduino. The working principle is also briefly explained that LCDs display data by changing the position of molecules to absorb or pass light in each pixel.

Uploaded by

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

Laboratory Hand Book

Experiment No. 02
Interfacing of LCD module with Arduino
OBJECTIVE
 To expose student and gain more knowledge about LCD module interface
with Arduino.
EQUIPMENT
 Arduino IDE
 LCD 16x2
 Connecting Leads
 Variable Resistor

THEORY
What is LCD 16X2?

An electronic device that is used to display data and the message is known as LCD 16×2. As the
name suggests, it includes 16 Columns & 2 Rows so it can display 32 characters (16×2=32) in
total & every character will be made with 5×8 (40) Pixel Dots. So the total pixels within this
LCD can be calculated as 32 x 40 otherwise 1280 pixels.

LCD 16 X2

16 X2 displays mostly depend on multi-segment LEDs. There are different types of displays
available in the market with different combinations such as 8×2, 8×1, 16×1, and 10×2, however,
the LCD 16×2 is broadly used in devices, DIY circuits, electronic projects due to less cost,
programmable friendly & simple to access.

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

Specifications of LCD 16X2


The specifications of LCD 16X2 are discussed below.

 The operating voltage of this display ranges from 4.7V to 5.3V


 The display bezel is 72 x 25mm
 The operating current is 1mA without a backlight
 PCB size of the module is 80L x 36W x 10H mm
 HD47780 controller
 LED color for backlight is green or blue
 Number of columns – 16
 Number of rows – 2
 Number of LCD pins – 16
 Characters – 32
 It works in 4-bit and 8-bit modes
 Pixel box of each character is 5×8 pixel
 Font size of character is 0.125Width x 0.200height

LCD 16X2 Pin Configuration

The pin configuration of LCD 16 X 2 is discussed below so that LCD 16×2 connection can be
done easily with external devices.

16X2 LCD Pin Diagram

 Pin1 (Ground): This pin connects the ground terminal.


 Pin2 (+5 Volt): This pin provides a +5V supply to the LCD
 Pin3 (VE): This pin selects the contrast of the LCD.
 Pin4 (Register Select): This pin is used to connect a data pin of an MCU & gets either 1
or 0. Here, data mode = 0 and command mode =1.
 Pin5 (Read & Write): This pin is used to read/write data.

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

 Pin6 (Enable): This enables the pin must be high to perform the Read/Write procedure.
This pin is connected to the data pin of the microcontroller to be held high constantly.
 Pin7 (Data Pin): The data pins are from 0-7 which are connected through the
microcontroller for data transmission. The LCD module can also work on the 4-bit mode
through working on pins 1, 2, 3 & other pins are free.
 Pin8 – Data Pin 1
 Pin9 – Data Pin 2
 Pin10 – Data Pin 3
 Pin11 – Data Pin 4
 Pin12 – Data Pin 5
 Pin13 – Data Pin 6
 Pin14 – Data Pin 7
 Pin15 (LED Positive): This is a +Ve terminal of the backlight LED of the display & it is
connected to +5V to activate the LED backlight.
 Pin16 (LED Negative): This is a -Ve terminal of a backlight LED of the display & it is
connected to the GND terminal to activate the LED backlight.

Sr. Pin
Pin Name Pin Type Pin Description Pin Connection
No No.

Connected to the
Pin This is a ground pin ground of the
1 Ground Source Pin
1 of LCD MCU/ Power
source

Connected to the
Pin This is the supply
2 VCC Source Pin supply pin of
2 voltage pin of LCD
Power source

Connected to a
Pin Adjusts the contrast
S3 V0/VEE Control Pin variable POT that
3 of the LCD.
can source 0-5V

Connected to a
MCU pin and gets
Toggles between
Pin Register either 0 or 1. 0 ->
4 Control Pin Command/Data
4 Select Command
Register
Mode 1-> Data
Mode

5 Pin Read/Write Control Pin Toggles the LCD Connected to a


5 between Read/Write MCU pin and gets
Operation either 0 or 1. 0 ->
Write Operation 1-

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

> Read Operation

Must be held high to Connected to


Pin
6 Enable Control Pin perform Read/Write MCU and always
6
Operation held high.

In 4-Wire
Mode Only 4 pins
Pin Pins used to send (0-3) is connected
Data Bits Data/Command
7 7- Command or data to to MCU In 8-Wire
(0-7) Pin
14 the LCD. Mode All 8
pins(0-7) are
connected to MCU

Normal LED like


Pin LED
8 LED Pin operation to Connected to +5V
15 Positive
illuminate the LCD

Normal LED like


operation to
Pin LED Connected to
9 LED Pin illuminate the LCD
16 Negative ground
connected with
GND.

Working Principle
The basic working principle of LCD is passing the light from layer to layer through modules.
These modules will vibrate & line up their position on 90o that permits the polarized sheet to
allow the light to pass through it.

These molecules are accountable for viewing the data on every pixel. Every pixel utilizes the
method of absorbing light to illustrate the digit. To display the value, the position of molecules
must be changed to the angle of light.

So this light deflection will make the human eye notice the data that will be the ingredient
wherever the light gets absorbed. Here, this data will supply to the molecules & will be there till
they get changed
At present, LCDs are used frequently in CD/DVD players, digital watches, computers, etc. In
screen industries, LCDs have replaced the CRTs (Cathode Ray Tubes) because these displays
use more power as compared to LCD, heavier & larger.

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

The displays of LCDs are thinner as compared to CRTs. As compared to LED screens, LCD has
less power consumption because it functions on the fundamental principle of blocking light
instead of dissipating.

Registers of LCD

The registers used in LCD are two types like data register & command register. The register can
be changed by using the RS pinout. If we set ‘0’ then it is command register and if it is ‘1’ then it
is data register.

Command Register

The main function of the command register is to save instructions illustrated on LCD. That
assists in data clearing & changes the cursor location & controls the display.

Data Register

The data register is used to save the date to exhibit on the LCD. Once we transmit data to LCD,
then it shifts to the data register to process the data. If we fix the register value at one that the
data register will start working.

It is okay if you do not understand the function of all the pins, I will be explaining in detail
below. Now, let us turn back our LCD:

Okay, what is this two black circle like things on the back of our LCD?
These black circles consist of an interface IC and its associated components to help us use this
LCD with the MCU. Because our LCD is a 16*2 Dot matrix LCD and so it will have (16*2=32)
32 characters in total and each character will be made of 5*8 Pixel Dots.  A Single character with
all its Pixels enabled is shown in the below picture.

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

So Now, we know that each character has (5*8=40) 40 Pixels and for 32 Characters we will have
(32*40) 1280 Pixels. Further, the LCD should also be instructed about the Position of the Pixels.
It will be a hectic task to handle everything with the help of MCU, hence an Interface IC like
HD44780 is used, which is mounted on LCD Module itself. The function of this IC is to get
the Commands and Data from the MCU and process them to display meaningful information
onto our LCD Screen.
Let’s discuss the different type of mode and options available in our LCD that has to be
controlled by our Control Pins.
4-bit and 8-bit Mode of LCD:
The LCD can work in two different modes, namely the 4-bit mode and the 8-bit mode. In 4 bit
mode we send the data nibble by nibble, first upper nibble and then lower nibble. For those of
you who don’t know what a nibble is: a nibble is a group of four bits, so the lower four bits (D0-
D3) of a byte form the lower nibble while the upper four bits (D4-D7) of a byte form the higher
nibble. This enables us to send 8 bit data.
Whereas in 8 bit mode we can send the 8-bit data directly in one stroke since we use all the 8
data lines.
Now you must have guessed it, Yes 8-bit mode is faster and flawless than 4-bit mode. But the
major drawback is that it needs 8 data lines connected to the microcontroller. This will make us
run out of I/O pins on our MCU, so 4-bit mode is widely used. No control pins are used to set
these modes. It's just the way of programming that change.

Interfacing LCD 16×2 with Arduino

Interfacing of a 16X2 LCD with Arduino is discussed to display “Hello World!” on the screen. A
library like LiquidCrystal permits you to manage the displays that are well-matched through the
driver like Hitachi HD44780 driver. Here, the following example circuit displays “Hello World!”
on the LCD & displays the time in sec once the Arduino board was reset.

The 16×2 display includes a parallel interface which means that the microcontroller used in this
has to control different interface pins immediately to control the LCD. The interface includes

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

mainly these pins like RS (Register Select) pin, Read/Write pin, Enable Pin, Data pins from D0
to D7, display contrast pin, LED backlight pins, power supply pins.

The display controlling process mainly involves placing the data to form the picture of what you
desire to show into the data registers, after that placing instructions within the instruction
register. A library like LiquidCrystal will simplify this for you so you don’t require identifying
the instructions in low-level.

The controlling of LCDs compatible with Hitachi can be done using two modes like 4-bit/8-bit.
Here, the 4-bit mode needs 7 I/O pins using the Arduino board, whereas the 8-bit mode needs 11
pins. To display the text on the LCD, the 4-bit mode is used. The following example will explain
how to control an LCD using 4-bit mode.

Liquid Crystal Library
This library allows an Arduino board to control LiquidCrystal displays (LCDs)
based on the Hitachi HD44780 (or a compatible) chipset, which is found on
most text-based LCDs. The library works with in either 4- or 8-bit mode (i.e.
using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw
control lines).

To use this library


#include <LiquidCrystal.h>
Examples
 Autoscroll: Shift text right and left.
 Blink: Control of the block-style cursor.
 Cursor: Control of the underscore-style cursor.
 Display: Quickly blank the display without losing what's on it.
 Hello World: Displays "hello world!" and the seconds since reset.
 Scroll: Scroll text left and right.
 Serial Display: Accepts serial input, displays it.
 Set Cursor: Set the cursor position.

 Text Direction: Control which way text flows from the cursor.

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

LiquidCrystal()
Description
Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8
data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines
unconnected. The RW pin can be tied to ground instead of connected to a pin on the
Arduino; if so, omit it from this function's parameters.

Syntax
LiquidCrystal (rs, enable, d4, d5, d6, d7)
LiquidCrystal (rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal (rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal (rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)

Parameters
rs: the number of the Arduino pin that is connected to the RS pin on the LCD
rw: the number of the Arduino pin that is connected to the RW pin on the LCD
(optional)
enable: the number of the Arduino pin that is connected to the enable pin on the
LCD
d0, d1, d2, d3, d4, d5, d6, d7: the numbers of the Arduino pins that are connected to
the corresponding data pins on the LCD. d0, d1, d2, and d3 are optional; if omitted,
the LCD will be controlled using only the four data lines (d4, d5, d6, d7).

Example LiquidCrystal (rs, enable, d4, d5, d6, d7)


#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16,1);
  lcd.print("hello, world!");
}

void loop() {}

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

begin()
Description
Initializes the interface to the LCD screen, and specifies the dimensions (width and
height) of the display. begin() needs to be called before any other LCD library
commands.
Syntax
lcd.begin(cols, rows)
Parameters
lcd: a variable of type LiquidCrystal
cols: the number of columns that the display has
rows: the number of rows that the display has

------------------------------------------------------------------------------------------------------

clear()
Description
Clears the LCD screen and positions the cursor in the upper-left corner.
Syntax
lcd.clear()
Parameters
lcd: a variable of type LiquidCrystal
-------------------------------------------------------------------------------------------------------
home()
Description
Positions the cursor in the upper-left of the LCD. That is, use that location in
outputting subsequent text to the display. To also clear the display, use
the clear() function instead.
Syntax
lcd.home()
Parameters
lcd: a variable of type LiquidCrystal
-------------------------------------------------------------------------------------------------------
setCursor()
Description
Position the LCD cursor; that is, set the location at which subsequent text written to
the LCD will be displayed.
Syntax
lcd.setCursor(col, row)

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

Parameters
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
-------------------------------------------------------------------------------------------------------
write()
Description
Write a character to the LCD.
Syntax
lcd.write(data)
Parameters
lcd: a variable of type LiquidCrystal
data: the character to write to the display
Returns
byte
write() will return the number of bytes written, though reading that number is optional
Example
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available()) {
    lcd.write(Serial.read());
  }
}

-------------------------------------------------------------------------------------------------------
print()
Description
Prints text to the LCD.
Syntax
lcd.print(data)
lcd.print(data, BASE)
Parameters
lcd: a variable of type LiquidCrystal

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

data: the data to print (char, byte, int, long, or string)


BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC
for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).
Returns
byte
print() will return the number of bytes written, though reading that number is optional
Example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
  lcd.print("hello, world!");
}
void loop() {}
-------------------------------------------------------------------------------------------------------
cursor()
Description
Display the LCD cursor: an underscore (line) at the position to which the next
character will be written.
Syntax
lcd.cursor()
Parameters
lcd: a variable of type LiquidCrystal
Example
 cursor()
------------------------------------------------------------------------------------------------
noCursor()
Description
Hides the LCD cursor.
Syntax
lcd.noCursor()
Parameters
lcd: a variable of type LiquidCrystal
Example
 noCursor()
------------------------------------------------------------------------------------------------
blink()
Description
Display the blinking LCD cursor. If used in combination with the cursor() function,
the result will depend on the particular display.

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

Syntax
lcd.blink()
Parameters
lcd: a variable of type LiquidCrystal
Example
 blink() and noBlink()
------------------------------------------------------------------------------------------------
noBlink()
Description
Turns off the blinking LCD cursor.
Syntax
lcd.noBlink()
Parameters
lcd: a variable of type LiquidCrystal
Example
 blink() and noBlink()
------------------------------------------------------------------------------------------------
display()
Description
Turns on the LCD display, after it's been turned off with noDisplay(). This will restore
the text (and cursor) that was on the display.
Syntax
lcd.display()
Parameters
lcd: a variable of type LiquidCrystal
Example
 display() and noDisplay()
------------------------------------------------------------------------------------------------
noDisplay()
Description
Turns off the LCD display, without losing the text currently shown on it.
Syntax
lcd.noDisplay()
Parameters
lcd: a variable of type LiquidCrystal
Example
 display() and noDisplay()
------------------------------------------------------------------------------------------------

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

scrollDisplayLeft()
Description
Scrolls the contents of the display (text and cursor) one space to the left.
Syntax
lcd.scrollDisplayLeft()
Parameters
lcd: a variable of type LiquidCrystal
Example
 scrollDisplayLeft() and scrollDisplayRight()
------------------------------------------------------------------------------------------------
scrollDisplayRight()
Description
Scrolls the contents of the display (text and cursor) one space to the right.
Syntax
lcd.scrollDisplayRight()
Parameters
lcd: a variable of type LiquidCrystal
Example
 scrollDisplayLeft() and scrollDisplayRight()
------------------------------------------------------------------------------------------------
autoscroll()
Description
Turns on automatic scrolling of the LCD. This causes each character output to the
display to push previous characters over by one space. If the current text direction is
left-to-right (the default), the display scrolls to the left; if the current direction is right-
to-left, the display scrolls to the right. This has the effect of outputting each new
character to the same location on the LCD.
Syntax
lcd.autoscroll()
Parameters
lcd: a variable of type LiquidCrystal
------------------------------------------------------------------------------------------------
noAutoscroll()
Description
Turns off automatic scrolling of the LCD.
Syntax
lcd.noAutoscroll()

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

Parameters
lcd: a variable of type LiquidCrystal
------------------------------------------------------------------------------------------------
leftToRight()
Description
Set the direction for text written to the LCD to left-to-right, the default. This means
that subsequent characters written to the display will go from left to right, but does not
affect previously-output text.
Syntax
lcd.leftToRight()
Parameters
lcd: a variable of type LiquidCrystal
------------------------------------------------------------------------------------------------
rightToLeft()
Description
Set the direction for text written to the LCD to right-to-left (the default is left-to-
right). This means that subsequent characters written to the display will go from right
to left, but does not affect previously-output text.
Syntax
lcd.rightToLeft()
Parameters
lcd: a variable of type LiquidCrystal
------------------------------------------------------------------------------------------------

Procedure:
1. Construct /assemble circuit of required task.

2. Connect the Arduino board to your computer using the USB cable.

3. Select the board and serial port as outlined in earlier section.

4. Write code of required task.

5. Verify / compile code and upload / run the code button to send sketch to the
Arduino.

6. Check the result of the required Task.

7. Save the result and attached with Report.

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

Circuit Diagram:

Task # 01

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

Write Code and construct / assemble circuit for manipulate LCD Interfacing with Arduino
for displaying number of group at 1st line and roll no of all member at 2nd line and Display
the result?
Group No. 2
Roll.No.12,13,14
Task # 02

Write Code and construct / assemble circuit for manipulate LCD Interfacing with Arduino
for displaying number of group at 1st line and roll no of all member at 2nd line and Display
the result, (Blinking Mode)
Group No. 2
Roll.No.12,13,14
Task # 03

Write Code and construct / assemble circuit for manipulate LCD Interfacing with Arduino
for displaying number of group at 1st line and roll no of all member at 2nd line and Display
the result, (Shifting Mode Left to Right)
Group No. 2
Roll.No.12,13,14
Task # 04

Write Code and construct / assemble circuit for manipulate LCD Interfacing with Arduino
for displaying number of group at 1st line and roll no of all member at 2nd line and Display
the result, (Shifting Mode Left to Right and Right to Left)
Group No. 2
Roll.No.12,13,14
Task # 05

Write Code and construct / assemble circuit for manipulate LCD Interfacing with Arduino
for displaying any message from serial monitor and Display on LCD.

Task # 06

Write Code and construct / assemble circuit for manipulate LCD Interfacing with Arduino
for displaying the value of Temperature from external temperature sensor and Display on
LCD.

PIN Connection Table: Fill table according to your connection diagram

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

Sr. No LCD PIN Arduino PIN


1
2
3
4
Circuit
5
6
7
8
9
10
11
12
13
14
15
16
Diagram:

RESULTS & CONCLUSION: -


-------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------

Introduction to Embedded System Engr. Ali Iqbal


Laboratory Hand Book

-------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------

Introduction to Embedded System Engr. Ali Iqbal

You might also like