
This is a very simple Arduino program which detects the contrast on your LCD and display which configuration is perfect and which is not. I think the code is self explainable but if there is any confusion please do ask.
I used
- A potentiometer (Trimpot – 10K)
- Arduino Uno
- 16×2 LCD Display(4 bit mode)
replace “LiquidCrystal.h” with <LiquidCrystal.h>
// include the library code:
#include "LiquidCrystal.h"
int pin=A5;
int value=0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 4, 8, 9, 10, 11);
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Tell Arduino to treat A5 pin as INPUT
pinMode(pin,INPUT);
}
void loop() {
value= analogRead(pin);
// set the cursor to column 3, line 0
// (note: line 1 is the first row, since counting begins with 0):
lcd.setCursor(3, 0);
lcd.print("Namaste");
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Potentiometer Range
if(value>=250){
Serial.println("It's too bright");
lcd.print("It's too bright");
}
else if(value>=210 && value<250)
{
Serial.println("A little bright");
lcd.print("A little bright");
}
else if (value>=90 && value<210)
{
Serial.println("Perfect! :)");
lcd.print("Perfect! :)");
}
else if(value>42 && value<90)
{
Serial.println("It's Okay :|");
lcd.print("It's Okay :|");
}
else if(value<42)
{
Serial.println("Too Dark :(");
lcd.print("Too Dark :(");
}
//Print value on serial monitor
Serial.println(value);
// delay of 500 milli seconds
delay(500);
//clear LCD screen
lcd.clear();
}
Comments
You must log in to post a comment.