Make: Projects

Arduino-Controlled Night Light

Make a night light that automatically goes on when you turn off the lights.

Arduino-Controlled Night Light

Using a light sensor, some wire, and LEDs you can easily create an automatic night light that will turn on when you turn off the lights.

Steps

Step #1:

PrevNext
Arduino-Controlled Night LightArduino-Controlled Night LightArduino-Controlled Night Light

These are the parts and tools you will need.

Step #2:

PrevNext
Arduino-Controlled Night LightArduino-Controlled Night LightArduino-Controlled Night Light

Connect the ground pin on the Arduino Uno to the ground rail on the breadboard. This is usually the first step in any project I do just so I can draw ground from any part of the rail.

Step #3:

PrevNext
Arduino-Controlled Night LightArduino-Controlled Night LightArduino-Controlled Night Light

Plug in your LDR Light Sensor into pin F 51 and F 53. Then connect a 10k resistor to G 51 and and G 46. Then a short wire from the ground rail to H 46. Then take a wire from the 5v pin on the Arduino to G 53. Then take a wire from digital pin 7 on the Arduino to H 51.

Step #4:

PrevNext
Arduino-Controlled Night LightArduino-Controlled Night LightArduino-Controlled Night Light

Now take a wire from the ground rail to I 40. Put a 330 resistor into H 40 and H 34. Take a wire from digital pin 1 on the Arduino to H 33. Since LEDs have positive and negative you will need to plug the longer end of you LED into G 33 and the shorter into G 34.

Step #5:

PrevNext
Arduino-Controlled Night Light

Repeat the process with another LED but this time use digital pin 2 instead of digital pin 1.

Step #6:

PrevNext
Arduino-Controlled Night Light

And repeat it again but use digital pin 3.

Step #7:

PrevNext
Arduino-Controlled Night LightArduino-Controlled Night LightArduino-Controlled Night Light

Now plug the red wire of the battery clip into the Vin of the Arduino and plug the black wire into the GND pin on the Arduino.

Step #8:

PrevNext
Arduino-Controlled Night LightArduino-Controlled Night LightArduino-Controlled Night Light
  • The Arduino code for the night light can be found in the PDF file above. Copy and paste it into the Arduino IDE, then upload it.
  • Now your lights should turn on when the light sensor senses no light.

Conclusion

You can take this project further by adding code to slowly fade the LEDs on and off in different patterns, or by adding a timer to fade the night light off after a set period of time.


  • Galina Orlova

    Hey, where is the arduino code for this project? There is no pdf file here :-(

  • http://thirdpersons.wordpress.com thirdpersons

    Here is some simple code if you wish for a single LED. Just a simple if/else statement. I connected my LDR to the analogue input and had the serial print just to have a look at what sort figures I was getting. You can then make the if/else statement a lot more complicated from this.

    int led =7;
    int ldr= A0;

    void setup() {
    pinMode(led, OUTPUT);
    Serial.begin(9600);
    }

    void loop() {
    int sensorValue= analogRead(A0);
    float voltage= sensorValue * (5.0 /1023.0);

    if (voltage>=3.0)
    {
    digitalWrite(led, LOW);
    }
    else
    {
    digitalWrite(led, HIGH);
    }

    Serial.println(voltage);

    }

  • nikki Bayar

    where is the code for this project? it would be extremely helpful if someone could post it. Thank you!

  • http://gravatar.com/andrebrilliant andrebrilliant

    Sorry guys, I guess it disappeared! I posted some but now it is gone. I will get some code up soon though.

    • lo

      Any chance you’re putting the code up soon?

    • julian

      would you be able to send me this code soon? or where is it?

  • https://www.facebook.com/calin.dragosgeorge Calin Dragos George

    very good tutorial (I added a link to my article http://www.intorobotics.com/interfacing-programming-light-sensors-tutorials-resources/) and I’m waiting new and innovative ways where light sensors are used in robotics applications

  • Pingback: Project #2 planning | Caitlin Fancy()

  • Pingback: Touch Lighting: Practical or Pointless? - Danville Personal Training()

  • Matt

    Where is the code

  • BSB

    yup where is code ?

  • Nekloth

    Seems nice, but difficult to understand without a schema (Fritzing) … and the code !

    Can you share that please ?

  • Pingback: Automação com Arduino: Luzes e Iluminação | Fazedores()

  • Anupam Singhal

    One change: in step 3, connect photo resistor to analog pin A0 (instead of digital 7). And a single LED is enough. Code is below for a single pin. You can add lines for other pins. The threshold may have to be modified for your case.

    // Code

    int sensorPin = A0;
    int ledPin = 1;
    int threshold = 400;

    void setup() {
    Serial.begin(9600);
    pinMode(1, OUTPUT);
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    }

    void loop() {
    int val = analogRead(sensePin);
    Serial.println(val);
    if (val < threshold)
    digitalWrite(ledPin, HIGH);
    else
    digitalWrite(ledPin, LOW);
    }

    • Guest

      It’s val=analogRead(SsnsorPin); I think

    • Jubilee Rideout

      I think it is supposed to be val = analogRead(sensorPin);

  • Pingback: Automação com Arduino: luzes e iluminação |()

  • Ted hong

    where is the code