#define LDR A0
#define red 2
#define green 3
#define blue 4
int data;
#include <LiquidCrystal_I2C.h>;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
Serial.begin(96000);
lcd.init();
lcd.backlight();
lcd.clear();
}
void loop()
{
data = analogRead(LDR);
data=map(data, 0, 1023, 0, 4);
Serial.print("LDR Senor Data:");
Serial.println(data);
lcd.setCursor(0, 0);
lcd.print("LDR Senor Data:");
lcd.println(data);
if (data== 1)
{
digitalWrite(red, 1);
digitalWrite(blue, 0);
digitalWrite(green, 0);
}
else if (data ==2)
{
digitalWrite(green, 1);
digitalWrite(red, 0);
digitalWrite(blue, 0);
}
else if (data ==3)
{
digitalWrite(blue, 1);
digitalWrite(red, 0);
digitalWrite(green, 0);
}
delay(1000);
}