top of page
Search

LDR DEPENDENT LIGHTS

  • Writer: Mein-bhi-Engineer
    Mein-bhi-Engineer
  • Aug 4, 2020
  • 1 min read

Updated: Aug 6, 2022


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

}

 
 
 

Comentarios


bottom of page