Site icon DIY Usthad

Motion Sensor Activated Light With Automatic Brightness Adjustment | Arduino + PIR + LDR

Motion Sensor Activated Light With Automatic Brightness Adjustment

My room light was controlled using a RF remote based relay. It was actually a dumb system always I miss place the remote and some times my son will take the remote and run.

So today I am planning to put an end this struggle. In this project, we are going to make a PIR based motion sensor activated light and using an LDR (photoresistor) to automatically adjust the brightness of the light ie at night the light will be in full brightness and in the morning if the sunlight is low then the light will automatically turn on with a suitable brightness if motion is detected.

LDR With Arduino

Video

Hardware Required

ComponentsAmazonAliExpressBanggood
Arduino Nano
LDR (photoresistor)
PIR Motion Sensor
TIP120 Transistor

Circuit

circuit
Installed for my room 12v LED light

Code


#define LDR A7
#define PIR 2
#define Light 3

int LDRvalue;
long counter;

void setup() {
  pinMode(PIR, INPUT);
  pinMode(Light, OUTPUT);
}

void loop() {
  if (digitalRead(PIR) == HIGH)
  {
    counter =0;
    LDRvalue = map(analogRead(LDR), 0, 1024, 254, 0);
    delay(50);
    analogWrite(Light,LDRvalue);
  }
  else
    counter++;
  if (counter <= 10000)
    digitalWrite(Light, LOW);
}
Exit mobile version