This sunset to sunrise lighting switch is designed to control the light illuminated on the LDR sensor. The resistance of the LDR sensor changes with the change in intensity of light falling on LDR.
CIRCUIT DIAGRAM
CODE
#define led 11
int ldr = 0;
int bright = 0;
void setup()
{
pinMode(A4, INPUT);
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop()
{
ldr = analogRead(A4); //0-1023
Serial.println(ldr);
//bright = ldr/4 //0-255
bright = map(ldr,207,1012,0,255);
analogWrite(led,bright);
delay(10); // Delay a little bit to improve simulation performance
}
Comments