const int LDR = 2; //LDR is connected to pin 2
const int red = 14;
const int green = 12;
int threshold =1000;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LDR,INPUT); //Configure pin 2 as an input
pinMode(red,OUTPUT); // RED LED SET AS OUTPUT
pinMode(green,OUTPUT);//Green LED set as OUTPUT
delay(2000);
Serial.println("Hello User");
delay(2000);
Serial.println("Initailizing.");
delay(2000);
Serial.println("Initailizing..");
delay(2000);
Serial.println("Initailizing...");
delay(2000);
Serial.print("Threshold value is : ");
Serial.println(threshold);
}
void loop() {
analogRead(LDR); //Read values from analog pin 2
float LDRVALUE = analogRead(LDR); //Creates a variable that reads the values
Serial.print("The LDR value is:");
Serial.println(LDRVALUE);
delay(2000);
if (threshold>LDRVALUE) {
digitalWrite(green, LOW);
digitalWrite(red, HIGH);
Serial.println("Light intensity is bellow threshold");
}
else if (threshold <LDRVALUE ) {
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
Serial.println("Light intensity is above threshold");
}
}