Introduction: Darkness Sensor

About: Hyperrobotix provides Robotics and Electronics solutions online.

This is a small project to sense the darkness in environment. It uses LDR & Arduino to measure the intensity of light. Based on the parameters the LED is lit up if the environment turns dark.

Although the final output is LED but the same concept can be employed to construct real world systems such as Automatic Street Light Controller.

Step 1: Gather the Components

All the materials required can be easily be found & bought from electronics outlet's in your premises.

The components required are as follows :---

1) Arduino Uno ( Any version of Arduino will do)

2) LDR

3) Variac

4) LED

5) Multimeter

6) Breadboard & Breadboard Wires

Step 2: Simple Circuit Diagram & Working

The explanation of diagram is as follows :---

The output led is connected to 11 Pin and ground pin. One leg of LDR is connected to GND and another leg is connected to the leg of variac. The another leg of variac is connected to 5v Volts.

Working :---

The LDR varies its resistance by the amount of light it falls upon. In other words, if the intensity of light following on it will increase, its resistance would decrease and vice-versa.

So there is a inverse relationship between the resistance and intensity of light. As resistance is directly proportional to voltage, so as the darkness increases the voltage across the LDR increases. The output from LDR is taken and fed to analog input of arduino. As said earlier, when the darkness increases the voltage read by Arduino would increase. The ADC (Analogue to Digital Convertor) converts the analog voltage value readings into digital values which can be used by code to determine when to turn the LED on.

For example : Let's say that under normal lighting condition, the output read from LDR is 2.5 V. The corresponding converted digital value would be calculated as :----

(5.00 / 1024) * 2.5 = 512 Units [5 V divided by 1024 multiplied by 2.5 V as the chip uses 10 Bit ADC]

Step 3: Code

The following is the code :---

/*

This code reads the output from LDR connected on analog input port and turns the LED if there is darkness. The darkness would increase the resistance of LDR and hence the voltage across it.

*/

void setup() {

pinMode(11, OUTPUT); //LED is connected to PIN 11

}

void loop()

{

int sensorValue = analogRead(A0); // Read the voltage from pin A0 which is connected to LDR

if(sensorValue > 900)

{

digitalWrite(11, HIGH); // Turn the LED on if voltage output of LDR > 4.39 V

}

else

{

digitalWrite(11, LOW); // Turn the Led off if voltage output of LDR < 4.39 V

}

}

Step 4: Final Output

The LED turns on when there is darkness and turns off when there is light. Also as we are using variac, we can do the fine tuning adjusting the same.