Arduino Lcd
Parts needed.
Arduino lcd
1 pushbutton
Arduino uno
Jumpers
2 1kohms resistors
1 potentiometer
Let's begin.
Step 1. Push Button and Potentiometer
My first step was to connect the push button and potntiometer to GND and 5,as the picture above shows.The push button is later connected to pin6 of the arduino, and when pressed the LCD displays on, and when when pressed the LCD displays off. The potentiometer on the other hand is connected to the V0 of the LCD.
LCD
before we can use the LCD, we have to solder pins to it,if not we cannot be able to connect it, but i guess if you are reading this article your LCD already have pins soldered. Reading the LCD pins from left to right.
LCD pins Connection
vss ________ GND
VDD ________ +5V
V0 ________ potentiometer
Rs ________ arduino pin12
Rw ________ GND
E ________ arduino pin11
D0 to D3 ________ empty(no connections)
D4 ________ arduino pin5
D5 ________ arduino pin4
D6 ________ arduino pin3
D7 ________ arduino pin2
A ________ +5V
K ________ GND
Arduino Sketch
// include the library code:
#include<LiquidCrystal.h>
int state=1;//initialize push button state
int pb=6;//initialize push button state
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
pinMode(pb,INPUT);//set pb as input
// set up the LCD's number of columns and rows:
lcd.begin(16, 1);
lcd.setCursor(0,1);
lcd.clear();//clear LCD
}
void loop() {
//LCD library command for no blink
lcd.noBlink();
state=digitalRead(pb);
if(state==0){
//to get a steady input, the LCD has to clear and write the message after the delay //without the .clear() command, the message will run from right to left or verse varsa
//in the LCD, using the clear and a short delay message, the LCD clears and prints the meaage a
//again after the delay time.
lcd.clear();
lcd.print("off");//print message on the LCD
delay(10); //delay message
lcd.clear();//clear LCD
delay(10);//delay message again
}
else
{
lcd.clear();
lcd.print("on");
delay(10);
lcd.clear();
delay(10);
state=1;
}
}
Finally
power up your arduino and breadboard and test what you have done, when you rotate the potentiometer message gets brighter or disappears and when you push the button the message changes to "ON" and when you release it shows "OFF", you can write a program to toggle the button by debouncing it. As you can see from the video mine is working as i expected.Take your time and play around with it. ARIGATO :)