• 8412906903
  • dnatechindia@gmail.com

Product categories

Have You Seen

Samsung 18650 2600mah Li-ion Battery

Samsung 18650 2600mah Li-ion Battery

Samsung ICR18650-26J 2.6Ah BatteryOriginal Samsung 18650 2600 mah Lithium-ion BatteryThis is or..

Rs.275.00 (inc GST)

Arduino Mega 2560 Pro Mini

Arduino Mega 2560 Pro Mini

Mega Pro 2560 Development Board Mega 2560 Pro a  Atmega2560 based compact Arduino MegaThis..

Rs.973.50 (inc GST)

Arduino Based Dark Switch



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
}

You can Download the Ready working code from HERE

Written by Amol Shah

Amol Shah

Founder of DNA Technology an Electronic Engineer by choice. Started working on this website as an Hobby and now its a full time venture. Very passionate about Electronics and like to learn new stuff. Want to make DNA Technology one of the best Online Store for Electronics Components in India.
Follow Me Twitter | Facebook | Google Plus | Instagram