Introduction: Under the Bed Nightlight

Picture of 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

Picture of 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

Picture of 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).


billybouy1 made it! (author)2017-04-18

I made this, but I found the LDR only worked in the daylight and not the dark. I:E The leds came on in the daylight and were not activated in the dark. So I redid the board and schematic using Eagle. Now it all works as it should be, the Led strip now comes on in the dark.

zila90 (author)2017-04-07

Could someone please send me the gerber files of this board. Thanks.

billybouy1 (author)2017-02-26

after putting this together I noticed that the LDR and 10k resistor are wired in reverse, the LDR should go to grd and the 10k resistor should go to the vcc side. check the Arduino diagram then look at the board diagram and check how the LDR is orientated.

Congratulations! your I'ble made the "Top 10 Kickass Arduino Projects" @

Top 10 Kickass Arduino Projects

rf3141 (author)2015-12-13

Can you give us a link for the motion detector you used? Also would it turn on the light if my cat walked into the room?

billyprefect (author)2015-03-20

Thank you for this! I am in the process of making this RIGHT NOW. Parts are ordered, waiting ever so impatiently for delivery. The floating bed, altered into a queen sized fitting, is going to look AWESOME floating in a green light.

TimothyB1 (author)2014-09-26

I'm attempting to build this (I've never tried anything like this before), but your schematic fails to show where the motion sensor(s) are connected. Will you add that information please? The PIR sensor I purchased (just one for now) has three interface pins, labeled "VCC", "OUT", and "GND". I assume these are to be connected to the Arduino, but I have no idea how.

Also, would you mind explaining in a little more detail how multiple motion sensors would be connected? Thanks - cool little project!

bigmattyc (author)TimothyB12014-10-06

If you look at the board layout as pictured above, the topmost pin of each of the bank of PIN array is connected to Vcc (+5V), the bottommost pins are all connected (through vias) to ground, and the center pins are the signal that carries to the Attiny. If you connect multiple motion sensors, just expand the array and count of digital input pins (pir_pins[numberOfPirs] = {8}) to include the PIRs you're using, and also note that a value of '8' as listed is completely invalid for an Attiny.

bigmattyc (author)2014-09-18

Can you supply the correct pinouts for the board as drawn?

Using one PIR, on JP3, I've done the following, but I want to make sure it's correct:

#define ldr_pin 2

#define led_pin 3

const int numberOfPirs = 1;

const int pir_pins[numberOfPirs] = {7};

Do you think that's correct?

bigmattyc (author)bigmattyc2014-10-04

So I think your initial code is a little bit buggy. Your mileage may vary, of course, but I've fixed it up and put a project on github. Anyone who's doing this project should take a look:

bigmattyc (author)bigmattyc2014-09-18

You may infer by this comment that I have had your boards printed. You would be correct. :) I used OSH Park to get the boards for ~$5 USD each, with about a 10 day turnaround.

stephejosephnbishop (author)2014-09-07

I like it, maybe adding a ambient light sensor to detect if the LEDs are needed would be a good idea?

It has and ldr to measure ambient light.

DougM2 (author)2014-09-02

Sounds like a fun project.

Or, you can go to Home Depot and buy one of the many 120 VAC motion detector for security lights that have a built in light sensor for night-only operation for about $10 (more if you wish). Then plug an led strip into it.

VeryEvilBetty (author)DougM22014-09-03

Yes that could be a solution but than i have less freedom in time settings. And when its activated it slowly increase light.

yhtomitsy (author)2014-09-02

cool project. I will try it out

JasonD2 (author)2014-08-31

Is it possible to wire multiple motion sensors so that, no matter what side of the bed detects motion, it will switch on?

VeryEvilBetty (author)JasonD22014-08-31

Yes in the code you can increase the number of sensors and add the corresponding pin to the array. Look at at the software section for a more detailed explanation. I haven't tried multiple sensors parallel to a single pin because i only have a single sensor at the moment. Im waiting on a delivery with new sensors

sanmahaan (author)2014-08-29

Could the hardware assembly part be explained more in detail for the non technical people.

VeryEvilBetty (author)sanmahaan2014-08-31

I will try to do that in the next couple of days

tamberg (author)2014-08-28

Cool! Built an EL-wire variant some time ago

yun14u1 (author)2014-08-28

integrate with a real-time clock (RTC) and you will have a winner. the LED's only activate at night.

selp (author)2014-08-25

it would be better with warm white led (and not cool white)

VeryEvilBetty (author)selp2014-08-28

Yes that probably would be better. But the thing is i ordered the ledstrip a couple of weeks ago and at that time i didn't had an idea of what to do with it. And i became this. And until now i haven't had a problem with the cool white.

seamster (author)2014-08-25

Great idea!

VeryEvilBetty (author)seamster2014-08-28

Thank you.

boatingman (author)2014-08-27

But what do you do when you see the shadows moving? The monster under the bed doesn't lie still.

VeryEvilBetty (author)boatingman2014-08-28

As long as the monster stays under the bed it stays dark. The sensors are mounted on the edge of the bed and point out so they don't detect movement under the bed. And when he crawls out from under the bed he has some light to see where he is going. No need to always be unfriendly against the monster under the bed.

MadMuz (author)2014-08-27

Love it! Orginal and useful, gets my vote :)

About This Instructable




More by VeryEvilBetty:Under the bed nightlight
Add instructable to: