Starting from the first line. First import the <liquidCrystal.h> library This library is designed to provide necessary functions to be used with lcd. Then the line LiquidCrystal lcd(12,11,5,4,3,2); is initializing the lcd in 4-bit mode. Arduino has less pins than other simple micro controllers so we use lcd with Arduino in 4-bit mode.
* 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
Now You people are thinking how does it do that. The liquidcrystal library do that since it is coded in such a way that it automatically assign pins in the above format. Note that always assign the pins in descending order like i did 12,11,5,4,3,2. If you not assign it in descending order than your lcd wont work. In the statement the starting keyword LiquidCrystal is the library keyword than in lcd(12,11,5,4,3,2) lcd is the name which we are going to use for our lcd operations you can also change it according to your wish. In setup loop my first statement is lcd.begin(16 ,2). The statement tells the Arduino Atmag micro controller that we are using 16×2 lcd. Rest of the code is very easy I hope you can understand them. The LiquidCrystal library can perform many functions here is detail of each function.
- lcd.clear() ->This clears the screen (and sets the cursor to theupper left hand corner).
- lcd.print() ->Prints the text.
- lcd.setCursor(coloumb , row) ->It takes two arguments first is coloumb and second is row to which we want to set our cursor.
- lcd.noCursor() ->Shows no cursor on the screen.
- lcd.cursor() ->Brings back the cursor.
- lcd.noDispla() ->Nothing will display on the lcd.
- lcd.display() ->Trun on the dispaly.
- lcd.blink() ->Cursor will blink on the screen.
- lcd.noBlink() ->Cursor will not blink on the screen.
Note: Use the correct syntax of the statements the ardunio functions uses first word starting with small letter and second with capital. For example noBlink() n is small B is capital digitalWrite() d is small W is capital.
CODE
//countng using lcd and button
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);//always initiliaze
//lcd pins in sequence like 12 11 5 4 3 2
int button =8;//button 8 used as input
void setup()
{
lcd.begin(16, 2);
lcd.clear();
pinMode(button, INPUT);//initiliziong button as input
}
void loop()
{
int count;
lcd.print(“PRESS BUTTON”);
delay(4000);
lcd.clear();
lcd.setCursor(0, 0);
while(1){
if(digitalRead(button)==HIGH)
{
delay(1000);//necessary delay other wise pressing one time
// will made wile loop run many times and value is incremented
//to thousands so a delay is used so one high signal increments
//one time
count++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(count);//Arduino can display integer types also
}}}
Download program sketch from here
If you don’t understand any thing just leave a comment below.
Filed Under: Arduino Projects, Microcontroller Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.