DIY Night Light automatic turn ON and OFF using Arduino, Relay and LDR

In this tutorial we are going to make an automatic light ON and OFF during night and day respectively using LDR sensor that gets activated or it's resistance gets reduced when light falls on it. We have also connected a manual switch ON and OFF for the bulb whenever we are out of home for weekends.

Let's get started,

Components Required:

  1. Arduino UNO X 1
  2. LDR light sensor  X 1
  3. 5V RelayModule  X 1
  4. Resistor (100k) X 1
  5. AC Bulb (25 or 100) Watt X 1
Circuit Design:

(Note: First upload the program to the Arduino IDE then only do the below given wirings in order to avoid short circuit from previously uploaded code in the Arduino.)

About LDR (Light Dependent Resistor) Sensor:

It is the sensor with resistance as it's main property. When light falls upon it then it's resistance decreases and allows electric current to flow through it. And when it is dark then it offers high resistance to the circuit and blocks current to flow through it.
Let's see it graphically,

In the above diagram, as light intensity increases, resistance decreases and when light intensity decreases then resistance of LDR increases.

Arduino senses the value from LDR in the range 0 to 1023. When the LDR value is less than 900 or 1000 then we call it as day condition and the bulb remains off. When the value is greater than 900 or 1000 then we check for night condition and turn on the bulb.

(Note: About relay and other module we have already discussed in other tutorials that you can see in the same website.)


int ldr=A0;  // taking input from LDR in pin A0 i.e anolog pin
int led=1;   // declaring output pin for bulb
int ldrStatus;
void setup()
void loop()
 if (ldrStatus<=1000)       // checks if it is day then led remains OFF
 digitalWrite(led,HIGH);    // during night led becomes ON

In this way you can make your own automated light system using Arduino, Relay, and LDR sensor. Also by removing relay and placing the 5 volt bulb to the digital pin 1 with 0.5 K or 220 omh resistor, you can directly make your DC 5 volt bulb operate from Arduino as shown in below given figure with your mini project done.(Upload the same code)

  1. Make your own home automation using LDR sensor
  2. You can also make automated traffic light system that will ON during night and OFF during day

Post a Comment