Light Dependent Lamp

Introduction: Light Dependent Lamp

In this instructable you will learn how to wire a light dependent lamp, but first we need to know what that is. A light dependant lamp uses a LDR(light dependant resistor) to check the light available in the area it's in, using this it will tell the light bulb when to turn on and off using an arduino microcontroller. In this case the light will turn on when the room is dark. First let's gather the materials:


  • Light Bulb x 1
  • LDR/Photoresistor x 1
  • 1k ohm resistor x 1
  • Relay (SPDT) x 1
  • Arduino Uno R3 x 1
  • Power Supply 5v x 1
  • Assortment of jumper wires

Now we are ready to start wiring.

Step 1: Wiring the LDR

Supplies needed for this step:


  • LDR/Photoresistor x 1
  • 1k ohm resistor x 1
  • Arduino Uno R3 x 1
  • Assortment of jumper wires

First we will connect the LDR to the arduino board, so first take your LDR choose one of the legs, either work as the component is not polarized, using preferably a black jumper wire connect this leg to the ground pin found on the left side of the arduino board next to the 5v and 3.3v pins. Next, using another jumper wire, connect the other leg of the LDR to the A0 pin found on the left side of the arduino board, 2 pins down from the ground pin you used for the other leg. Then connect the 1k ohm resistor to the same leg of the LDR you used in the last step. Now using a jumper wire connect the opposite end of the resistor to the 5v pin on the left side of the arduino found above the ground pin. Now the LDR is fully connected and we are ready to connect the relay.

Step 2: Wiring the Relay

Materials needed for this step:


  • Relay (SPDT) x 1
  • Assortment of jumper wires
  • Everything created in last step

In this step we will connect the relay to the arduino board. First using a jumper wire connect terminal 8 found on the left side of the relay and is the middle pin, to any of the digital pins that line the right side of the arduino, yet don't use digital pin 0 or 1 for this connection. Next using a jumper wire connector terminal 5 of the relay which is found in the middle on the right side, to the ground pin of the arduino which is found on the left side of the arduino. Now the relay is connected and all we have left to do is connect the lightbulb and power supply.

Step 3: Wiring the Light Bulb and Power Supply

All supplies needed for this step:


  • Light Bulb x 1
  • Power Supply 5v x 1
  • Assortment of jumper wires
  • Everything created in the past two steps

In this step we will connect the lightbulb and power supply to the relay. First using a jumper wire connecting either pin of the light bulb to terminal 7 of the relay, terminal 7 is found on the top left side of the relay. Next, using a jumper wire connect the otherside of the light bulb to the positive pin of the power supply. Next, using another jumper wire connect the negative end of the power supply to terminal 11 of the relay, found on the bottom right side of the relay. Now all the wiring is done we can write the code.

Step 4: Writing the Code

In this step we will simply be writing the code for the microcontroller, the code should be written as seen below:

int ldr;

void setup()

{

pinMode(A0, INPUT);

pinMode(5, OUTPUT); }

void loop()

{

ldr = analogRead(A0);

if(ldr > 500){

digitalWrite(5, LOW);

}else

digitalWrite(5, HIGH);

}


How this code works is the arduino reads the amount of voltage that is flowing through the LDR. The voltage flowing through the LDR depends on how much light it has contact with, so if there is no light in the room then the LDR has minimal to no voltage running through it. This value then gets run through an if statement. If the value received from the LDR is above 500 then the light bulb is set to low so it will not turn on, and when the LDR value is under 500 meaning there is minimal light in the room the light bulb is set to turn on.

Step 5: Finished

Now you have a functioning light dependent lamp that automatically turns on when it's dark. This is great for in the house as a night light or even out on the patio to light up the night.

Be the First to Share

    Recommendations

    • Fandom Contest

      Fandom Contest
    • DIY Summer Camp Contest

      DIY Summer Camp Contest
    • Metal Contest

      Metal Contest

    Comments