Select Page

Overview

In this beginner tutorial, you are going to learn how to build a simple automatic lighting circuit using a Light Dependent Resistor (LDR) and Arduino. There are many applications of this circuit such as,

• Getting the lights in your house to turn on automatically when it’s dark and turn off when it is day
• A simple automatic streetlight, etc

It can also be used along with other sensors to do pretty cool stuff.

I am assuming at this point you know very little about Arduino and so I have tried to simplify and explain everything so that you can easily understand.

Basically, the LDR senses the amount of light around and tells the Arduino. The Arduino is programmed to turn on an LED when it gets dark and turn the LED off when there is enough light around.

This tutorial assumes you already know what and LDR and Potential Divider Is so if  you don’t know what these are, you may consider reading these tutorials.

• What is an LDR
• What is a Potentiometer
• What is a Potential Divider

Components Used

To build this circuit you’ll need the following components

• Arduino Uno
• LDR
• 10k or 50k Potentiometer
• LED
• 220 ohm resistor
• Jumper wires

If you live in Ghana, you can get an Arduino and other components to buy at Invent Electronics.

Schematic

Here is the schematic of the circuit Proteus Schematic for project

How It Works

The resistance of the LDR varies with the amount of light falling on it. The resistance increases when there is little light around and decreases in bright light.  The darker it is, the higher the voltage drop across the LDR.  The maximum resistance of each LDR can vary depending on the kind of LDR but it’s usually between 1kΩ and 10kΩ though it could go way higher.

The circuit works on the principle that when an LDR and a resistor are connected to form a potential divider, the voltage drop across the LDR is proportional to the resistance of the LDR which is in turn proportional to the amount of light falling on it.

The potentiometer and LDR form a Potential Divider circuit. As it gets darker, the resistance of the LDR increases and the voltage drop across it increases. This voltage is sent to Pin A0 of the Arduino which converts the measured analog voltage to a number between 0 and 1023. Depending on your connection, the higher the voltage drop across the LDR, the closer the number is to 1023.

The potentiometer is used to adjust the sensitivity of the whole system.

If you want to know how the Arduino converts the voltage from the Arduino into a number between 0 and 1023, please check out this tutorial.

• Arduino Analog to Digital Conversion

Here is the a Fritzing design of the circuit. If you are building the circuit on a breadboard, you can look on the Fritzing Design. Fritzing Circuit

To learn how to use Fritzing to design a circuit check out this tutorial

• How to use Fritzing to Design a circuit

The Arduino code is written to turn the LED on when the voltage across the LDR exceeds a certain threshold value. I have commented each line of the code to give you a better understanding of how the code works.

```/* Automatic Lighting With LDR and Arduino
Written by Isaac Sesi
www.currentcity.cc
18th April 2016 */

int LDR = A5;   //Tell the Arduino we will connect the LDR to Arduino Pin A5
int LED = 8;  //Tell the Arduino we will connect the LED to Arduino Pin 8

void setup(){
pinMode(LDR, INPUT);   //We are going to be reading a voltage(INPUTING) from the LDR
pinMode(LED, OUTPUT);  //We are going to be sending a voltage (OUTPUTING) to the LED
Serial.begin(9600);   //Set the spped at which the Arduino communicates with Serial Monitor (9600 means 9600 bits are transferred every second)
}

void loop(){
Serial.println(lightLevel);   //Display the value in the serial monitor
if(lightLevel >= 600 )    //If the value measured from the LDR is greater or equal to 600
{
digitalWrite(LED, HIGH);  //Turn on the LED
}
else{
digitalWrite(LED, LOW);   //Turn off the LED
}
}
```

Final Circuit

Here is a GIF of how the actual circuit works. When a finger is used to cover the LDR, signifying darkness, the LCD lights up. When the finger is taken away, the light goes off. So that’t it! Hope you had fun building it.

0 0 vote
Article Rating
0