My house is pretty dark at night – especially the bathroom. There isn’t a street light outside so if you get up for a pee in the middle of the night you can’t see a thing. And at my advancing age I do get up for a pee in the middle of the night! I’d found a very cheap MSP430 USB stick development kit on eBay and had got as far as setting the IDE and compiling “blinky”. I needed a simple project to force me to use it properly.

Then I noticed a nice MSP430-based PIR board – also on eBay. Olimex had made a nice board based on a TI example and it already flashed a LED when it sensed movement. Couple that with some dreadfully underpowered LED light that I had lying around and a light level sensor and I had the perfect starter project. It wasn’t too tricky but would force me to learn about the MSP430’s timers, interrupts and ADC. I can throughly recommend John Davies’s book if you’re embarking on a similar project.

The hardware

Most of the tricky stuff was done. All I had to do was add a LDR to measure light levels and a transistor to let me switch the LED. Along with a couple of resistors and a PP3 9V battery clip that was it. The 9v made the 12V LEDs (sealed units) even dimmer but that turned out to be perfect. The only tricky bit was working out what pins I could use from the MSP430. Olimex had broken out a 6-pin header intended for SPI communications. Out came the soldering iron and some stripboard. The header shown on the left of the photo mates to the 6-pin connector. The 2 pins on the top right match up with the 14-pin programming header. They’re not connected to anything but that was a convenient way to solidly mount the PIR sensor on the board. I’m afraid I don’t have a schematic for the design, but it’s pretty simple and I did create a schematic for v1.1 (to be added later).


The existing code was a great starting point. Both the hardware and software seem to be based on a TI reference design SLAA283 – Ultra-low Power Motion Detection using the MSP430F2013. They had a timer setup and this checked the PIR level via ADC. If it differed significantly then the LED was toggled. Nothign complicated but it covered the basics. I say basics – after being spoiled by the ease of programming on the Netduino just getting an ADC reading seemed like hard work! My code simply merged in a second ADC reading to check the light level and would switch the LED light on for a set period of time if there was movement and it was dark.

I’ll attach the code once I find out how best to attach/show a C source code file in WordPress.


The coding was done in the Eclipse-based Code Composer Studio IDE. I managed to get a full version (including upgrade to version 5.0) for only $25 (rather than $450) after heading about a promotion for the Piccolo ControlSTICK over on TI often do great deals on their hardware. 430oh is a brilliant resource for MSP430 info.

To connect to the PIR board I used the emulation side of the EZ430-F2013 I already had. The PIR sensor used the same F2103 variant of the MSP430. The only tricky bit was connecting to that 0.05″ header. You can see in the photo that some iffy soldering and hot glue did the trick. To be honest a better way would have been to use a Launchpad. This amazing kit includes a programmer and 2 microcontrollers for an unbelievable $4.30 – and that includes international shipping. Details on how to use it as an external programmer are here.

The final product

Well, once it was complete the only thing left was to mount it neatly in the bathroom ceiling. I frequently final at the final hurdle of completing a project. Once the difficult stuff is done, I know I can do it and only the implementation remains I can lose interest. And to be honest this probably wouldn’t have been completed if my son Adam was born on time. This was done whilst my wife was overdue and waiting to be rushed into hospital.

I wanted to get it finished as I’d foolishly promised to enter a project in Project of the Month contest and posted about it here. I placed exactly where I expected to – i.e. last – but it was fun to enter. The guys on there really know their stuff and produce some great projects.

Weirdly enough my little project caught the imagination of Hack a Day, then Lifehacker – two sites which I tend to check almost daily. I’m under no illusion that it’s the toilet humour rather than the quality of my creation that was responsible for this, but it was nice all the same!

Version 1.1

I have since made version 1.1 which you can see here.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s