Introduction: Automatic Lights Using LDR (Brightness Control)

About: My team has developed a new product. PLEASE CHECK IT OUT ON INDIEGOGO AND SHOW YOUR SUPPORT. CAMPAIGN LINK: https://igg.me/p/2165733/x/17027489. I'm a tech and food enthusiast and also a Soccer Player. I love…

When you hear Automatic Lights, we generally assume it to turn on and off at a particular time. But sometimes it so happens that even after say 6 P.M. there is enough of natural light and you wouldn't need your lights to turn on. Or sometimes too dark during day time.

What if we make a device that will automatically adjust the brightness of a bulb according to the brightness of the room? That's exactly what I'm gonna show in this Instructable.

This will reduce the wastage of electricity and also contribute to improvement of your home towards a smarter, better home. Here, I will be using an LED for demonstration, but the same applies even if we connect an actual bulb to it.

Step 1: Components Required

For this you will need:

  • An LDR (a.k.a. Photo-resistor).
  • Arduino UNO.
  • LED.
  • 10K Resistor.
  • Jumper Wires.
  • BreadBoard.

That's all you need to have to build this smart lighting system. So let's get Started.

Step 2: About the LDR

An LDR (Light Dependent Resistor) is a device whose resistance varies with the change in amount of light incident on it. Hence this is majorly used in Light Sensitive Circuits.

A light dependent resistor works on the principle of photo conductivity.

Photo conductivity is an optical phenomenon in which the materials conductivity is increased when light is absorbed by the material.When light falls i.e. when the photons fall on the device, the electrons in the valence band of the semiconductor material are excited to the conduction band. These photons in the incident light should have energy greater than the band gap of the semiconductor material to make the electrons jump from the valence band to the conduction band. Hence when light having enough energy strikes on the device, more and more electrons are excited to the conduction band which results in large number of charge carriers. The result of this process is more and more current starts flowing throgh the device when the circuit is closed and hence it is said that the resistance of the device has been decreased. This is the most common working principle of LDR

Step 3: The Connections

Follow the Schematic and build the circuit.

Make sure that the leg to which the

Note: You can use a resistor in series with the LED if you're using smaller voltage rated LEDs.

Step 4: The Code

Before you use the actual code, find out the value of the LDR for different brightness levels. This can be done by using the AnalogRead program in the example sketches.

If you're wondering how the brightness gets adjusted, then go through the Fade program in the examples.

Once you have the values, map it to the code and upload it. Here, I'll be using a torch to increase the amount of light falling on the LDR.

I have used the constraint() function and map() function for mapping the analog values from the LDR to the digital values which control the brightness of the LED.

int ledpin = 9;
int ldrpin = 1; int value = 0;

void setup() {

Serial.begin(9600);
} void loop() { value = analogRead(ldrpin); value = constrain(value,400,500); value = map(value,400,500,255,0);

Serial.println(value); analogWrite(ledpin, value);

delay(200); }

Step 5: Output

After verifying the code, upload it on to the board. Now you'll see that the LED will be off in complete brightness, and as the brightness in the surrounding decreases, the LED begins to glow brighter.

If you want to play with the brightness of bigger bulbs which are connected to 120 Volts or 220 Volts, you will need to use a relay to control it. I'll show that in another Instructable in future.

That's All Folks !! Follow Me for More DIY !!

Keep DIY-ing !!