Introduction: Under the Bed Nightlight

A automatic light for under the bed.

It activates on motion, the sensors are placed so that they wont activate when you are in the bed. But when you step out of the bed or aproach the bed. They turn of after there has been no motion after a set time.

Because i dont need them to go on when its is light in my bedroom i added a ldr to measure the ambient light.

Step 1: Leds

U used a cheap white led strip from ebay (search for led strip). I didnt used rgb because i just wanted to have light when i go to bed and when i get out of bed.

I mounted the ledstrip to the bed with the adhesive backing of the strip itself. I used alcohol to clean the area where the ledstrip would go so it would stick better.

My bed is made of wood, normally i would advise to mount a ledstrip on some aluminum for cooling. But because the leds are only on a couple of minutes or less its not necessary.

Step 2: Hardware

I used an arduino for my prototype. (i have made a fritzing drawing). Currently i am using the prototype to fine tune the timings that i like.

Because i want a more permanent solution i also have made a pcb drawing that uses a smaller avr micro controller(attiny13/25/85). I havent added a programming header to the board(i just program it in a breadboard and then stick it in the pcb).

The pcb has a 7805 for the 5v for the attiny. the capacitors are 100n decoupling caps.

Eagle schematic and board file are included.

The ldr im using is 50k with a 10k resistor. just had a 50k ldr. It doesnt really matter what ldr you use because u need to adjust the value that defines light or dark in the code(more on that in the software part).

To drive the ledstrip i use a TIP122 it is connected to the arduino trough a 1k resistor.

The ledstrip is connected to the Vin of the arduino. I am powering the arduino with 12v beacuse the ledstrip requires 12v.

The power supply depends on the length of ledstrip you use. I got about 3.5 meter ledstrip that is rated at 0.4A/meter so 3.5x0.4=1.4A. Im using a 2A power supply again just because i had it. But i this case a 1.5A should do fine.

Step 3: Software

The code is included. I should work with minimum adjustments. It has a few settings.

#define ldr_pin A5 // the pin of the ldr
#define led_pin 9 // the pin of the TIP122 for the led strip

const int numberOfPirs = 1; // Number of pir sensors
const int pir_pins[numberOfPirs] = {8}; // Pins of the pir sensors Example = {pin,pin,pin}

const int led_time = 10; // Time to have the leds on (no an exact timing) (in Sec)
const int on_delay = 20; // Delay to turn the leds on (in mSec)
const int off_delay = 1; // Delay to turn the leds off (in mSec)

const int ldr_value = 500; // Value to make the differene between dark and light

const int led_max = 180; // Ledstrip max pwm value
const int led_min = 0; // Ledstrip min pwm value (0 recommended, else it wont turn off)

Because the amount of pir sensors depends on your bed and the way you like it. But 3 should be always enough. i have made a array for the pins of each pir sensor.

led_time is the time the led stays on after the last detected movement.

on_delay is the delay it uses for dimming the led to its max value.

off_delay is the delay it uses for dimming the led to its min value.

ldr_value is the value that makes the difference between dark and light you need to adjust this for your room.

led_max is the pwm value it uses for on i set it to 180 because i didn't need full brightness.

led_min is the pwm value for off. my advise it to leave this 0 because if you increase this value the ledstrip wont turn completely off.

This is the code i use for my arduino protoype. if you make the pcb version it is necessary to adjust the pins for the correct pin out of your micro controller.

Step 4: Parts

Arduino version

  • Arduino (uno)
  • bit of protoboard
  • LDR
  • pir sensors
  • 10K resistor
  • 1K resistor
  • TIP122
  • 12V ledstrip

PCB version (requires pcb etching)

  • attiny13/25/85
  • pcb
  • LDR
  • pir sensors
  • LM7805
  • 3x 100n Capacitor
  • 10k resistor
  • 1k resistor
  • TIP122
  • 12v ledstrik
  • Power jack

Both versions require 12volt power supply (for current see hardware section).

Microcontroller Contest

Participated in the
Microcontroller Contest

Epilog Challenge VI

Participated in the
Epilog Challenge VI