Arduino Based Automatic AC Bulb Triggered in Dark

Introduction: Arduino Based Automatic AC Bulb Triggered in Dark

Arduino is a microcontroller based prototyping board that runs on small DC power. A Relay is a device that helps microcontrollers (or microcontroller based boards) like Arduino to switch on or off different household appliances like motors, lights, water heaters, television and fans etc.

In this project, we will see a simple circuit where an Arduino UNO will control a 5V relay, which will light up in dark and to Sense the darkness we will use LDR to sensor to sense the darkness to trigger the bulb.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Things You Need

For this instructables we will need following things :


5V Relay Module

10K potentiometer
Lamp / AC bulb
Wires for connecting DC Voltage components
Wires for connecting AC Mains and lamp

Step 2: Schmatics

Let us now see how the circuit is designed. First thing is we used a 5V relay in this project. This makes it easy as Arduino can power up the relay directly. If you used a 12V relay like we used in this project Arduino Relay Control, you need to use a separate power supply for relay.

Coming to the design of the circuit, it is very simple as we used a 5V relay module and not the individual components. Although the circuit diagram explains the detailed connections, practically we didn’t need to make all the connections.

Most relay modules (whether 5V or 12V) will come with the aforementioned connection and hence all you need is to give power supply to the relay module i.e. 5V and GND and connect the control signal from Arduino to control pin on the relay board.

Coming to the load part i.e. the lamp, hot wire from the mains supply is connected to one terminal of the lamp. Other terminal of the lamp is connected to Normally Open (NO) contact of the 5V Relay. Finally, the neutral wire from the mains is connected to the Common (COMM) contact of the relay.

A small light sensor in the form of LDR (Light Dependent Resistor) is used to switch on or off the light automatically. The output of the LDR sensor is given to the Analog Input pin A0.

Step 3: Code

Please copy the following code and upload it to the arduino Board :

const int relay=8;
const int Ainput=A0;
int ldrValue = 0;
int range = 0;
void setup()
digitalWrite(relay,HIGH); // My Relay is an active LOW Relay.


void loop()

ldrValue = analogRead(Ainput);

range = map(ldrValue, 0, 1023, 0, 255);

view raw5V_

Step 4: Turning ON the Bulb in Dark

After connecting everything together and uploading the code to arduino, we are ready to test our project. So lets turn on the power and when there is no light on LDR sensor light will trigger automatically, as you can whenever i am covering the LDR with my hand the bulb is turning ON and when it is exposed to light is OFF.

Be the First to Share


    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest