In this section, we will first learn how to print Alphabets and then output from an IR sensor on LCD display.
BY ASHISH BARTWAL
INTRODUCTION
There are many commands in Arduino through which we can control the output of an LCD display.These commands enable us to move, blink a specific text printed on LCD display. We can code Arduino in such a way that it reads the input from sensors like infrared sensor and then print it on LCD display. Some basic codes that will be required for performing above functions are listed in this project.
LIST OF COMPONENTS REQUIRED
- Arduino
- 1602 LCD Screen (16 x 2 LCD)
- Jumper wires
- 220ῼ resistor
- 10k potentiometer
- Breadboard
- Infrared sensor
CIRCUIT DIAGRAM :
FIG. Interfacing LCD with Arduino
FIG. Printing IR sensor o/p on LCD
CONNECTION
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
- 220 ῼ resistor: LCD pin 15 and ground
- Potentiometer wiper to LCD VO pin (pin 3) and ends to +5v and ground of Arduino kit
- LCD pin 16 to ground
- Infrared module VCC to +5V
- Infrared module Gnd to 0V
- Infrared module DO to digital pin 9 of Arduino
- Infrared module AO pin will not be used.
FUNCTION OF LCD PINS
Numbering of the pins is done from the viewer’s left-hand side
- Gnd– This is the ground pin of the LCD display.
- Vcc– This is the power pin of the LCD display.
- V– This is the variable voltage pin of the LCD. Brightness of LCD can be
Adjusted using this pin with a potentiometer.
- RS– This is the register select pin of the LCD. LCD has two registers, they are- A)Command Register- It controls the way that data is displayed. This is set as 0 i.e. ground pin. B)Data Register- It controls the content that has to be displayed. This is set as 1 i.e. +5v pin.
- R/W– This is read or write pin of the LCD. A) Read operation- Reads data from Arduino. This is set to 0 to perform read operation.B)Write operation-Writes the data as given by external devices such as keypads. This is set to 1 to perform a write operation.
- E– This is enable pin of the LCD. It enables the LCD to accept data either as a falling edge triggered pin or rising edge triggered pin.
NOTE: Following pins make LCD to work in either 8bit mode (DB0- DB7) or 4bit mode DB4-DB7)
- DB7-
- DB6-
- DB5-
- DB4-
- DB3-
- DB2-
- DB1-
- DB0-
COMMANDS USED :
- LiquidCrystal LCD(12, 11, 5, 4, 3, 2);
Initializes library with the specified interface pins.
- #include <LiquidCrystal.h>
This is the library code of liquid crystal in Arduino. It is preinstalled in Arduino IDE.
- begin(16, 2);
It sets the 16 columns and 2 rows in LCD.
- setCursor(x, y);
Sets the LCD cursor to x row and n coulomb.
- print(“ ”);
Prints the desired data in the LCD.
- autoscroll();
- noAutoscroll();
- noBlink();
It turns on blinking cursor.
- rightToLeft();
Go right for the next character.
- home();
Sets cursor to its initial position i.e.[ 0,0]
- clear();
Clear all the available character.
- scrollDisplayLeft();
Scroll text to one position left.
- scrollDisplayRight();
Scrolls text to one position right
CODE TO DISPLAY AND CONTROL THE TEXT ON LCD:
**extensive comments are written for a better understanding of code.
AIM: Arduino starts printing the alphabets from ‘a’. Once ‘m’ is printed, remaining alphabets are printed from right to left direction one after the other. And finally when ‘s’ is printed, direction get reversed and characters are printed up to ‘z’.
#include <LiquidCrystal.h>
LiquidCrystal LCD(12, 11, 5, 4, 3, 2); //RS,EN,D4,D5,D6,D7 pin of LCD respectively
int thisChar = ‘a’; //defines this character ‘a’
void setup() //in this function we initialize the device connected to Arduino
{
LCD.begin(16, 2); // set up the LCD’s number of columns and rows
LCD.cursor(); //turn on the cursor
}
void loop()
{
if (thisChar == ‘m’) //alphabets till ‘m’ is reached according to alphabetical order
{
LCD.rightToLeft(); //alphabets will move from right to left one after the other when ‘m’ is reached
}
if (thisChar == ‘s’)
{
LCD.leftToRight(); //alphabets will movefrom left to right once ‘s’is reached
}
if (thisChar > ‘z’)
{
LCD.home(); //if character is greater than z than set cursor at thisChar = ‘a’;(0,0) and print ‘a’
}
LCD.write(thisChar); //print the characters on LCD
delay(1000);
thisChar++;
}
CODE TO PRINT OUTPUT FROM IR SENSOR ON LCD
AIM: Arduino prints value 0 when there is no object in front of IR transmitter and value 1 when there is an obstacle in front.
#include <LiquidCrystal.h>
#define sensor 9 //defines ir sensor connected to digital pin 9 of Arduino
int val=0; //sets the initial value equal to 0
LiquidCrystal LCD(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(sensor,INPUT); //sets sensor i.e.digital pin 9 as input to the Arduino
Serial.begin(9600);
LCD.begin(16, 2);
LCD.print(“OUTPUT IS “);
}
void loop() {
LCD.setCursor(11,0);
val=digitalRead(sensor); //sensor readings are assigned to val (just a character)
Serial.print(val); //LCD prints val i.e. sensor readings
Serial.print(“val”);
if(val==HIGH) //if sensor detects object than it glows red i.e.“HIGH”state
{
LCD.print(“1”); //prints 1 if above condition is satisfied
delayMicroseconds(100);
}
else
{
LCD.print(“0”); //prints 0 if above condition not satisfied
delayMicroseconds(100);
}
}
NOTE: Hence Arduino prints value 0 when there is no object in front of IR transmitter and value 1 when there is an obstacle in front.
VIDEO TUTORIAL:
Watch this video to see above codes in action:
Interesting blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple tweeks would really make my blog jump out.
Please let me know where you got your theme.
Cheers