Project: Bed Lights

A few months ago, my wife and I were in the market for a new mattress. We popped into a local mattress store and spent the better part of the afternoon stretching out on almost everything they had. Before we left, we tried a really nice, we’ll-probably-never-afford kind of bed. It had controls for firmness and head and foot elevation. There were temperature and massage controls. Memory foam. There were even ground lights. That’s right. Ground lights! What a brilliant idea?!

We left the store empty handed. But the thought of those ground lights stuck with me. How fantastic it would be to have such a thing for a midnight pee run. Something bright enough to help you find your way, but dim enough as to not wake the blanket-stealing snore-machine sleeping next to you (To My Wife: Baby, your snores are like lullabies. Truly.). Of all of the things that fancy bed had, it was the ground lights I wanted the most.

So I decided to make my own, but with a couple of enhancements. I definitely wanted motion activated lights. Who wants to bother feeling around for a on/off button at 3 AM? I also wanted an adjustable brightness control. It’s hard to gauge how bright is too bright until you actually start to use it. I knew it would need to be tuned.

This blog describes my little bed-lights project. I’ll detail everything you need to know to build your own. Note that if you attempt this project, some of your parts will probably vary. As a result, you’ll need to adjust values of other components accordingly. I’ll try to help you out where I can.

[Disclaimer: If you choose to tackle this project, I take no responsibility for any bad things that might happen. If you wire something up wrong or take a shortcut that results in a fire, that’s not my fault. As the folks keen on legalese say, this blog is for informational purposes only.]

Parts List

Here is the parts list for the project

Component Qty Approx. Price
½” 10’ PVC Pipe (Home Depot or Lowes) 2 $5
½” PVC End Caps (Home Depot or Lowes) 4 $1.50
LED Holders, 5mm 12 $1.50
2.1mm Female DC Power Barrel Connectors, Panel Mount 5 $15.00
2.1mm Male DC Power Connectors 4 $6.50
20 AWG wire 1 Spool, 100ft. $10.00
20 AWG 25′ Hook-Up Wire(For convenience in building power cables. Not entirely necessary. You could just use wire from the previous item. You’ll definitely have plenty of leftover if you buy 100′. ) 1 $4.30
Rustoleum Flat, Black Spray Paint 1 $6.00
Heat Shrink Tubing 1 Pack (Won’t Use It All) $7.00
9V 2.1mm wall wart, at least 500mA 1 $11.00
500mA Fuse 1 $2.20
Fuse Holder 1 $1.00
White LEDs, 5mm 3Vf (Mine came from EBay in a 300pcs assortment pack) 12 $0.25
330 Ohm Resistors 14 $1.40
2.2k Ohm Resistors (Specific to the current needs of my light rails – see notes below on how you might need a different value) 2 $0.20
2N3904 Transistors (NPN) 2 $0.50
1N4001 Diodes 2 $0.50
1 M Ohm Potentiometer 1 $5.00
Adafruit PIR Sensor 2 $20.00
Perfboard 1 $3.00
Enclosure for Controller 1 $6.00
Enclosures for PIRs and lids 2 $3.50
Velcro Straps 1 Pack $4
Velcro Tape 1 Pack $5

Total Project Cost: ~$120.00

Granted, this is just an estimate. All of the passive components I had laying around. You might find much of what you need by poaching old busted electronics.


There are 3 basic components to the bed lights. The first, and most obvious one, is the pair of light rails – one for either side of the bed. The second component is the motion sensor (PIR). There are two of these as well. The third component is the controller box. This is where power gets distributed, motion sensor input is handled, and lights get switched on. It’s also where the control knob for the brightness control lives. The basic configuration is like so.

Something that’s not obvious from the sketch is that each PIR controls both light rails. If one of the PIRs is triggered, both rails light up. And if both PIRs are triggered at the same time, both rails still light up.

Building the Light Rails

The first step to building the light rails is cutting the PVC pipe down to size. The ½” pipe that I bought came in 10 ft. lengths. That’s way too long for my bed. So, using a hacksaw, I cut both pieces down to 7ft.

Next, I drilled 6 evenly spaced holes for the LED holders in each pipe. The trick here is to initially start with a small drill bit and then work up to larger ones, testing the LED holders as you go. It was important that the LED holder was able to pop in, feel somewhat snug, and then pop out easily again.

For each pipe, I planned to cap both ends. But in the cap for one end, I drilled a center hole large enough to accommodate one of the female 2.1mm barrel connectors. This is where power will be supplied to the rail. Actually mounting the connectors and attaching the end caps should happen last, after the rail is wired up and ready to report for duty.

At this point, I painted both the pipes and the end caps by applying a couple of coats of flat black Rustoleum spray paint.

Next up – the wiring.

Each LED on the rail has an associated 330 ohm resistor and each LED/resistor combination is wired in parallel. If one LED dies, the rest will continue to light up. As shown in the photo below, I merely soldered a resistor to one of the legs of the LED and then connected wire as appropriate (Note: The PVC in the photo below is unpainted. This photo was taken as I was still experimenting.) I then tidied things up with heat shrink tubing.

I should point out that it’s much easier to snake the wire through the pipe a segment at a time between holes and wire up the LEDs in-place, than it is to try to wire up everything outside of the PVC pipe and then to try to snake the whole thing through the PVC in one fell swoop. I learned this quickly. Trying to assemble everything outside of the PVC pipe just leads to headaches as you try to fish the LEDs/resistors out through the holes. It’s time consuming and not worth it.

It’s important to make sure the LEDs are wired up properly. They have polarity. And because we’re wiring things up in parallel, 5 of the 6 LED combinations will be connected to 4 wires. If you’re having trouble visualizing this, here’s a diagram to help you out. 5 of the 6 LED/resistor pairs have an incoming positive connection as well as an outgoing positive connection. The same is true of the negative connections. Only the last LED/resistor pair has single connections for the positive and negative terminals.

After the LEDs were wired up, I tested each rail with a nine volt battery to ensure everything lit up. I then popped the LEDs in their holders, put a dab of superglue on each holder, and pushed everything down in their holes. Some LED/resistors didn’t appreciate being pushed down into tight quarters, so I tested the LEDs again as I went along to ensure I didn’t break something or short a connection.

Next up, the DC power connectors. I soldered the leads appropriately to the power connectors, being careful to get the polarity right. A multimeter is handy for that. If you’re uncertain what’s negative and what’s positive, plug in your power supply directly to the jack and find out. If you don’t have a multimeter (God, help you), you can always test using another LED resistor pair separate from your light rails. If everything is connected up properly, the LED should light right up. If it’s backwards, the LED will go up in smoke or won’t light at all.

With the jacks wired up, I mounted them into the PVC end caps and superglued all caps to the pipes. The light rails were finished.

Building the Controller

As mentioned before, the controller serves three purposes – 1) Distribute power to all the other components. 2) Switch on the lights when the motion sensors are triggered. And 3) provide a mechanism that allows me to adjust the brightness of the light rails. All three of these goals are accomplished in the following circuit

Click to Enlarge

How It Works

Power is distributed to the light rails and PIRs after passing through the 500mA fuse. The fuse is there just in case we get a short anywhere. It would probably be better to go with a fuse closer to the current rating of the actual circuit. 500mA is what I had on hand.

The negative sides of the light rails are connected to the collector of an NPN transistor. In my configuration, the transistor works like a switch. When the appropriate voltage is applied to the transistor’s base, current will be allowed to flow from the collector, through the emitter, and on to ground. This will allow the light rails to light up.

I should note that transistors could have been replaced with simple relays. If you prefer to go that route, you won’t need the resistors attached the the transistors’ bases. However, relays are clicky. And this is a bed/sleep related application. The sound of relays might be a little annoying in the middle of the night.

Determining the resistor values for the transistors’ bases depends entirely on the power needs of your light rails. On paper, each rail draws 109mA each at 9V. The magic formula for determining the base resistor value is:

R = switching_voltage * Hfe / (1.3 * load_current)

The switching voltage is the signal voltage from the PIRs (3.3v). I’ll have more to say about the PIRs shortly. I have to confess, the Hfe of a transistor is somewhat of a magic number to me. Technically, it’s the ratio of the load current to the base current. Given I didn’t know my base current, I wasn’t quite sure how to calculate this. Most folks on the Interwebs claim that 100 is a good number to use for the 2N3904. So that’s what I went with. Plugging the numbers into the formula gives us:

R = 3.3V * 100 / (1.3 * 0.109A)
R = Approx. 2329 Ohms

I didn’t have such a resistor in my Box-O-Electronic-Thingamabobs, so I went with a combination of a 2.2k Ohm and a 330 Ohm to get me close. Better to be over than under (I think).

The diodes in the circuit are used to protect the signal pins of the PIRs. These may not actually be needed. I’m not entirely sure. Without them, I worried that if one PIR goes high and the other is low, a voltage would be placed across the signal pin of the low PIR and damage it. Would this actually happen? No clue. But I decided to play it safe and add diodes to the mix. The diodes allow current to flow in only one direction – out through the transistor.

The 1M Ohm potentiometer is used to limit the current that can pass through the transistor’s base. This component allows the transistor to work like an amplifier as well as a switch. By decreasing the amount of current through the transistor’s base pin, we decrease the amount of current that can flow in from the light rails and out through the emitter. Turning the potentiometer clockwise increases the resistance on the transistor’s base. Increasing resistance lowers the current. And, voila, we have an adjustable dimmer.

Assembling the Controller

With regards to the circuit, I can’t really give much advice. Just follow the circuit shown above and arrange the components in a way that works for you. I used a perfboard without any traces. I connected components using a combination of jumper wires and solder bridges. None of the power connectors, nor the potentiometer were mounted directly to the perfboard. If I had a perfboard that was perfectly fitted for my enclosure I might have gone that route, but I didn’t. So those components were connected using wire.

As for the enclosure, I strongly recommend planning out the component positioning before going anywhere near it with a drill. It’s EXTREMELY frustrating to drill a bunch of holes only to discover that there’s not enough space inside the enclosure to fit everything safely. Space on the inside fills up quickly.

A fellow by the name of John Cooper has an excellent YouTube tutorial on using Sketchup to layout enclosures for guitar effects pedals. I do something similar for my enclosures using 3DS Max. I encourage you to check out John’s video, learn something new, and apply this practice to all of your enclosures. It’ll save you a world of pain.

I discuss the PIR sensors below. But I should mention here that I didn’t have any compatible connectors on hand that I could mount onto the enclosure. The PIRs require three pins – power, ground, and signal. All of my connectors are of the two wire variety. So I just drilled a couple of holes in the side of the enclosure for the PIR cables and soldered them directly onto the perfboard. As a result, the PIR cables are the only cables that aren’t detachable from the controller enclosure. I may fix this at a later time. Or I may not. It’s not that big of a deal.

Motion Sensors (PIRs)

The motion sensors I selected for this project are $10 PIR sensors from Adafruit. PIR sensors detect changes in infrared light. You can find them at just about any electronics outlet. The Adafruit version is interesting in that it has 2 adjustment pots – one for sensitivity and one for a time delay. Adafruit’s website recommends these things be powered at 5v, but claims that 9v is an acceptable upper limit. Since I’m running everything else off of 9v, that wins by default. There’s always a risk I’ll burn these things out quicker. Time will tell, I guess. If you’re following along with my project and you’d rather go with the suggested 5v, just create a voltage divider out of 2 resistors.

The sensitivity adjustment seems to correlate to range. The most sensitive setting comes in at around 20 ft.

The time delay adjustment affects how long the signal will remain high after the PIR has stopped detecting motion. I’ve adjusted both of mine to be around 15 seconds. By using two sensors (one for either side of the bed), this gives a person plenty of time to get from one side of the bed to the other and out of the room before the light rails shut off.

The Adafruit PIRs come with a 1ft long 3-wire 26 AWG cable attached to a 2510 Molex connector. 1 ft. is obviously not long enough, so I fashioned extension cables out of leftover wiring from the light rails and some heat shrink tubing. If you want to get fancy, find yourself some more 2510 Molex connectors for your controller enclosure so you can have detachable PIR cables. I didn’t have any available. As I said before, I just soldered the cables directly to the controller board. Not pretty, but it works.

The enclosures I used for the PIRs weren’t ideal, but they were the best I could find. Here’s a picture of what they look like.

With a stepper drill bit, I drilled holes in the front of the enclosure large enough to accommodate the PIR sensor. A used a dremel to carve out a hole in the back just big enough for the Molex connector. Once everything was connected, I taped the thing shut.

Light Rail Cables

The last thing you’ll need to construct is a set of power cables for the light rails. You might be able to find some long 2.1mm male/male cables online if you’d rather not fuss this step. But creating power cables for the light rails is probably the easiest part of the entire project.

For a single cable, all you need are 2 2.1mm male DC connectors and some 20 AWG wire. The connectors unscrew to reveal terminals for soldering. Make sure you wire one end of the cable up the same way as you do the other end (negative to negative, positive to positive).


Attaching the setup to the bed involved lots and lots of velcro. Both the controller and the light rails were attached with velcro straps. The motion sensors were attached to the footboards using velcro tape.

The light rails were angled such that the light pointed down and away from the bed. The PIRs were mounted near the headboard, but angled so they pointed towards the footboard and slightly out. Hopefully that shows in the photos below.


All in all, this is a pretty simple project. And a lot of fun. We’ve been using these bed lights for well over a week now. I think I can say this project has been a tremendous success. The brightness level took a little tuning. It’s amazing how bright light can seem once your eyes adjust to darkness. It took three nights of dimming the LEDs before I found a brightness level that didn’t wake one of us up. But I found it. No more feeling around for the cell phone to light my way to the bathroom in the “wee” hours (cue rimshot).

Something I hadn’t anticipated, but worth mentioning, is the psychological effect of having the lights switch on in the middle of the night when they shouldn’t have. Ghosts? Mice? Dust bunnies on the move? It stirs up anxiety, which doesn’t bode well for the sleep-deprived mind. Just be aware that if you’re sensitive to such things, you’ll probably need to adjust the sensitivity of the PIRs (glad we only taped those shut :-)).

Some specs you might find interesting. When idle (the light rails off), I measured the current draw at around .1mA. That’s barely anything. With the lights on at full brightness, the current draw is around 130mA. That’s almost half of my original full-on value for both rails. I’m sure there was a fudge factor in my transistor base calculation. The lights could have been a bit brighter. But that’s fine. Even at max power now, the light rails are too bright to be practical.

Timelapses with Android

My wife and I decided to add a deck to our home. It’s something we’d been discussing for years. Should it run the length of the house? Or should it be shorter? Narrower? Do we want to allow space for a future hot tub (which we’ll probably never get)? Built in pergola? Big stairs? Little stairs? It’s a conversation I think we could have kept having for many more years if we had indulged ourselves. But sometimes you just have to know when it’s time to make a decision and move on.

So we settled on a design, talked to contractors and code enforcement folks, and finally scheduled the build. I really, REALLY wanted to do a timelapse of the whole thing, but I wasn’t sure what to use. I considered using something like CHDK on my DSLR. The idea of leaving the camera out in the elements for days on end didn’t appeal to me. So I dismissed that idea fairly quickly. I had an old Samsung Galaxy S3 sitting in a drawer collecting dust and wondered if I might use that instead. It took decent photos. And if it died in the middle of the build, I wouldn’t be terribly heartbroken about it. So that’s the path I went down.

As a software developer, the instinct is to write software solutions for your own problems. I began listing out the things I would need in order to do the timelapse in Android – wake locks, a Service, an Activity for starting/stopping captures, a preview surface, camera code, storage code, etc. And then I began writing the app. No sooner had I started than I realized I only had 3 days before the builders began their work. So I backed away and began looking at what was already in the Play store.

That’s when I stumbled upon Lapse It Pro. It did everything I needed. And it allowed me to save full-frame, 8 megapixel image sequences as opposed to just a video – a bonus because I wanted to stitch the video together outside of the phone. I installed it on the S3 and had it working in no time. The UI is straightforward. And the entire capture process can be configured – frequency, video/image format, image size, etc. I fell in love with it right away. (I’m already thinking of new projects I can use it on.)

The next thing I needed to figure out was power. I would be placing the phone in or near trees, far away from any electrical outlets. As a test, I charged the phone completely and started a 1 frame per 30 second capture using just the phone’s battery. It lasted about 3 hours before it died. I next tried using a 4400mAh battery pack I picked up from Adafruit a year or so ago. That bumped my capture time up to about 6 hours. Good, but not good enough. It was also a 1A pack, so it couldn’t charge my phone as fast as the phone was discharging. I really needed about 10 hours of life with a 2A supply. That’s when I found a 18000mAh pack on Amazon for $33. It had a port that could deliver 2A. And so it was perfect for my needs.

The video above is the fruit of my labor. The 3D modeling was done using 3DSMax. The morphing towards the end was done with FantaMorph(another fantastic piece of software). And the whole video was stitched together using Adobe Premiere. I ended up needing to apply the Warp Stabilizer effect to the timelapses because it was windy out and the ladder supporting the phone shook quite a bit.

Push Mowers and Hydrolocking

I topped off the lawn mower’s gas tank, pushed it to the edge of the lawn, and then took a minute to admire what was left of the beautiful, yet hostile, dandelion invasion occupying a tract of land that used to pass for my lawn. “Sorry, fellas. But you’ve got to go.” I reached down and hit the primer bulb on the side of the engine. And then, holding my breath, I grabbed the handle on the starter rope and gave the thing a very enthusiastic tug.


The starter rope stopped short and sent pain shooting straight up my arm. And of course this was followed by a gratuitous, and perhaps somewhat humorous, tirade of cursing and jumping around. “What the #$*&! happened?” After I got over myself, I shyly gave the starter rope a few more tugs just to confirm what I already knew. Something was flubbed up.

I immediately checked the oil. When I was too young to really understand such things, my parents (and step-parent) ingrained into me the notion that oil was the key to all things motorized. Hear a weird knocking noise? Check the oil. Low on windshield wiper fluid? Check the oil. Flat tire? Check the oil. I believe the mantra was something along the lines of, “In the beginning man invented motor oil. After that, he invented the motor.” So I checked the oil. And it was low. But not THAT low.

I then tilted the mower up to look beneath it. “Perhaps something jammed the blade up,” I thought. Nope. That wasn’t it. But that’s when I noticed oil pouring out of the exhaust. “Hmmm…I don’t think that’s supposed to happen.” And then oil started seeping out of a couple of other places. It was bleeding everywhere! I removed the air filter and noticed there was oil mixed in with the gas inside the fuel intake as well. The prognosis didn’t look good. And It took me 15 minutes of tinkering with things before I finally admitted defeat and came inside to consult the interwebs.

Apparently what I had was a case of hydrolock. You mechanical types surely know what that is. But I’m not a mechanical type. So this was a completely new concept for me. Hydrolock occurs when a fluid enters the cylinder head. In my case, it was oil. But it can happen with water if you’re prone to driving your vehicle through creeks and such. Fluids don’t compress like a gas. So your piston can’t move in the direction that would ordinarily result in compression. And the piston can’t move in the other direction because of the vacuum that exists in the cylinder head. So it becomes stuck. And if this happens while things are in motion, it can lead to some very serious engine damage.

After I had wrapped my head around the problem, I went back outside and attempted to get things moving again. I disconnected and removed the spark plug. And then I tilted the mower up and let all of the oil drain out of the cylinder head. I replaced the spark plug, topped off the oil, and then changed the air filter because it was looking kind of rough. After that, the starter rope moved freely.

It took a little effort to get the mower to start. I’d prime it and start it only to watch it immediately die while I choked on a cloud of white smoke. But after some persistence and a lot more smoke, the mower finally stabilized. Once it could keep itself running, I let it idle for a while so that it could burn off any excess oil that was still hanging out in the cylinder head.

Eventually the mower seemed to behave normally and I managed to get the rest of the yard mowed. But I’m still puzzled as to how this whole thing happened to begin with. The scenario suggested by people smarter than me involves tipping or tilting the mower during storage. But the mower had been sitting on flat ground since I had used it the previous evening (without any issues, mind you). And I used it the following day without incident after having stored it the same way. So it’s a mystery to me. Maybe you mechanical types have some theories.