// ldr_smart_lighting.ino
// Photocell LED control
//set pin numbers
const int ledPin = 13; //the number of the LED pin
const int ldrPin = A0; //the number of the LDR pin
int threshold = 300; // LED trigger value
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //initialize the LED pin as an output
pinMode(ldrPin, INPUT); //initialize the LDR pin as an input
}
void loop() {
int ldrStatus = analogRead(ldrPin); //read the status of the LDR value
Serial.print("LDR value is ");
Serial.print(ldrStatus);
Serial.print(" Trigger value is ");
Serial.println(threshold);
if (ldrStatus <= threshold) { //check if the LDR status is <= threshold, then set LED HIGH
digitalWrite(ledPin, HIGH); //turn LED on
Serial.println("Now is DARK, turn LED ON");
}
else {
digitalWrite(ledPin, LOW); //turn LED off
Serial.println("---------------");
}
delay(1000);
}