As the name suggests Dark switch is basically a circuit which Turns on when it becomes Dark. This is a very simple Arduino based project. This project is basically for Arduino beginners who are just learning to use Arduino. A simple Automation project required in every home, gardens, restaurants where the lights automatically Turn ON at night. This project can also be used for Automatic street light application.
Circuit Diagram of Arduino based Dark Switch
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.
A relay is used over here as a switching element. Since Arduino cannot directly Turn ON/OFF a bulb 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.
Components used
Implemented Circuit Output
Successfully implemented output of Arduino Based Dark Switch under Light Condition
Successfully implemented output of Arduino Based Dark Switch under Dark Condition
Code for Arduino Based Dark Switch
/*
Arduino Based DARK SWITCH
Tested By Amol Shah
DNA Technology : http://www.dnatechindia.com/
*/
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
}