Introduction: Arduino Based Dark Switch
Arduino based Dark Switch is a simple project which is basically for Arduino beginners who have just started learning to use Arduino.
As the name suggests in this project we will be turning ON the lights automatically as the ambient light intensity decreases. Similarly the lights are Turned OFF when there is sufficient light intensity. This project can be used in every home, gardens, restaurants and even for street light automation.
Step 1: What You Will Need?
For this Project You will Need:
- Arduino Uno (I have used a local Arduino over here)
- LDR Light Dependent Resistor
- Single Channel Relay Board
- Jumper wires
- Bread Board
- 10K resistor
- 12 Volt, 1 Ampere Adapter
- LED Strip Light (or any other light source)
All these components you can easily get at any local electronic store. I have tried to keep this project as simple as possible. There is no need of solder iron so even small kids can test this project.
Step 2: Circuit Diagram
A Light Dependent Resistor (LDR) is used over here to measure the ambient light condition and accordingly Turn ON/OFF a Relay. An LDR's resistance changes as the intensity of the light falling on it changes as the light intensity increases the resistance decreases i.e. resistance is inversely proportional to light intensity.
Arduino cannot measure the resistance of LDR but it can measure voltage so we have used a resistor of 10K and made a voltage divider circuit whose output is voltage. So now as the resistance changes the output voltage of the voltage divider changes. This voltage decreases as the light intensity decreases.
Analog channel of the Arduino is used to measure the voltage from the voltage divider section which is then compared with a set limit (fixed in code) and then accordingly the Lights are either Turned ON or OFF.
A relay is used over here as a switching element. Since Arduino cannot directly Turn ON/OFF the lights hence a relay is used over here. The relay acts as a High current & voltage switching element and also provides isolation between the Arduino and the high voltage lights.
Step 3: The Code
int sensorPin = A0; // select the input pin for ldr
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(2, OUTPUT); //pin connected to the relay
Serial.begin(9600); //sets serial port for communication
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor:
// Serial.println(sensorValue); //prints the values coming from the sensor on the screen
if (sensorValue < 150) //setting a threshold value
{
digitalWrite(2,HIGH); //turn relay ON
}
else digitalWrite(2,LOW); //turn relay OFF
delay(100); // Change Delay as per your required Response time. I have set it to 100ms
}
This is a very simple code and I do not think there is much need of any explanation. But if you have any queries then I am there to help you out. You can also download the code from HERE.
Step 4: Final Output
Here you can see the Final output. When ambient light is sufficient the Relay and the Strip LED's are OFF. And under dark condition the Relay as well as the LED Strip lights are Turned ON.