I find that the measure of a good Instructable is the ideas that it inspires, which is why I enjoyed Liam.great98's Instructable titled "Give Your Bed Underglow!" I never would have thought of adding an LED strip to the bottom of a bed otherwise, and I immediately wanted to do this for my kids.
I wanted to go a bit beyond what Liam.great98 did and add the ability to have the lights turn on when needed and off again after a period of inactivity, so I decided to try my hand at hacking the LED strip to do just that. This instructable will show you how I went about hacking my LED strip to add a microcontroller and motion sensor. Hopefully the ideas you find here will serve as a launching point for your own ideas and improvements.
Step 1: Theory
(This step is a discussion of my approach to hacking the LED strip, and may not necessarily be well described. If you just want to get on with the instructions already, feel free to skip to the next step.)
The LED strip I purchased (found here: http://www.banggood.com/Wholesale-5M-RGB-3528-LED-...) came with an LED controller and remote control, which I think is quite common.
The idea is to be able to add a microcontroller that can control the power to the LED strip (turn it on and off as needed), without losing the ability to control the color and pattern with the remote control. There were two options, as I saw it:
- Build an entirely new control circuit.
This would require integrating the remote control receiver into the new microcontroller, reverse engineering the remote protocol, adding MOSFETs to control power to each of the LED channels (and, probably, a MOSFET control chip), and programming the light values and patterns into the microcontroller.
However, that's quite a lot of work and a lot of additional electronic components. To be honest, and let's be clear about this, I'm far, far too lazy to do all that work, which leaves option number...
- Wire the microcontroller into the existing circuitry.
This is the approach I took for this Instructable. and will be described below.
Somehow the circuit needs to be modified to allow the microcontroller to control the power supplied to the logic portion of the LED controller circuit board.
A quick look at the LED controller circuit board shows that there are two black ICs. The upper IC in the pictures is the brains of the controller. It changes the LED color, does pulse-width modulation (PWM), and controls the light patterns. I'm guessing that the lower IC is a MOSFET control chip, which turns power on and off to each of the LED power lines (I could be wrong about this, however). There's also a ground plane (highlighted red in the third picture), a +12 volt power rail, and a +4.7 volt power rail (highlighted in blue). There are several potential solder points (highlighted in yellow).
The LED controller accepts commands from the remote control, allowing the LED colors to be set and for different display patterns to be selected. The controller is able to remember the LED settings when power is removed and reapplied, which will be very helpful.
I measured the current being drawn by the two ICs at about 1 mA, which is well within the current sourcing abilities of most microcontrollers, so a transistor or MOSFET will not be needed and the ICs can be powered directly from the microprocessor. All that is required, then, is to disconnect the two ICs from the +4.7 volt power rail (by cutting the circuit board trace at the black line), tie the microcontroller to +4.7 volts and ground, and connect one of the microcontroller pins to the power pins of the two ICs on the LED controller circuit, so that the microcontroller can power the ICs at will.
A simple and cheap PIR motion sensor can be easily connected to the microcontroller to detect motion, and the microcontroller can easily be programmed to timeout after a specific period of time.
Seems simple enough!
Step 2: Parts and Tools
Here's a list of what I used to do my hack. Note that you can use substitutions for most of the parts listed here, but this Instructable will be written specifically with these parts in mind. I will try to provide enough information that you can customize the steps, if needed.
1) An LED strip.
I used the same RGB LED strip suggested in the Liam.great98's Instructable, which is cheap and works great for this project. It can be found here:
This strip comes with a controller for the strip and a remote control to change the color and light pattern.
2) Power Supply.
Check the requirements for your LED strip. The one I'm using called for a 12 volt power supply capable of supplying 2 amps of current for the 5 meter strip. I found a suitable power adapter at a local thrift store for $3, but you might have one already lying around.
3) A PIR Motion Sensor.
These are pretty easy to find. I found a good deal on a pack of 10 on eBay. You can also get them at Fry's Electronics, Radio Shack, or various places online (like this one from SparkFun:
https://www.sparkfun.com/products/8630). This should have three pins, one for power (3.3-5 volts), one for ground, and an output pin that goes high when motion is detected.
Some good information on using PIR sensors can be found here: http://learn.adafruit.com/pir-passive-infrared-pro...
4) An Attiny85 microprocessor and a Programmer.
This will be used to provide the brains of the hack. It will provide power to the LED strip controller when motion is detected, and remove it when there has been no movement for a period of time. I used an Attiny85, but an Attiny45 should work just as well as long as it's physically small enough to fit inside the existing LED controller case. You can certainly use another brand of microcontroller (ie. a PIC), but you'll have to supply your own code.
You'll also need to have a way to program the microcontroller. I use one that I built, and there are many Instructables that can show you how to make your own. I will provide both a .hex file to directly program the Attiny85, and source code, if needed.
5) Various electronic parts (not shown)
The values of these parts do not have to be exact, and some may not even really be needed. Here's what I used:
1 4.7 kΩ resistor.
1 10uF capacitor.
1 100uF capacitor.
1 3-pin SIP socket to plug into the PIR sensor (like this from Sparkfun: https://www.sparkfun.com/products/115).
1 DIP socket to allow the microprocessor to be removed for reprogramming, if needed (optional but recommended).
1 prototype board (I got a good deal on some 5x7 cm prototype boards on eBay similar to these from Radio Shack: http://www.radioshack.com/product/index.jsp?produ...
3 small lengths of wire (I used some telephone wire I had on hand).
6) Soldering Iron, Solder, and a Steady Hand (not shown)
Yes, this project involves soldering. There's not too much of it, but it is a bit detailed, so you should have some experience with it.
7) A drill and a 1/16" drill bit (not shown)
I used these to make wire holes in the PCB, but you could conceivably do without.
Step 3: Open Up the Controller
The first step is to get access to the LED controller circuit board. I was able to easily pop the bottom off of the control box with a flat head screwdriver.
Step 4: Modify the Circuit Board
So, the controller is designed to provide power to the electronics constantly. In order to be able to turn the strip on and off with the microcontroller, some modifications need to be made to the circuit board.
First, the two ICs need to be disconnected from the +4.7 volt power rail. This can be done by (carefully!) using a sharp knife to cut the circuit board trace as indicated by the black line in the picture.
Second, wires need to be added to circuit board to allow power from the board to be used to power the added microcontroller and to allow the microcontroller to supply power to the two ICs as needed. The three convenient solder points have been highlighted in yellow in the picture.
The black dots in the picture show where I drilled 1/16" holes in the circuit board to run the wires through. I did this because I felt it would make the wires more secure, but it is not strictly necessary, if you're careful about not pulling your wires too much.
Step 5: Add Wires
This is, probably, the trickiest part of this hack and, really, it's not that bad.
Wires need to be soldered to the solder points identified in the previous step. The wires should be cut to about 3 inches or so, and then stripped on one end and soldered as shown. Take it easy here and be careful not to get solder anywhere it's not supposed to be. If you take your time here, you shouldn't have a problem.
I used hot glue to secure the wires into place a bit more securely (shown in the third picture), and I would advise you to do the same, if you can.
You'll also want to label the wires somehow to make them easier to identify. I will be referring to them as "Power" (the wire supplying +4.8 volts from the circuit board to the added microcontroller), "Control" (the wire supplying power from the microcontroller to the IC chips on the board), and "Ground".
Step 6: Program the Microcontroller
The .hex file for the Attiny85 is included below. This file is my compiled program. As long as you're using an Attiny85, are using the same pins as shown in the circuit diagram, you should be able to use it to program the microcontroller and be good to go. Feel free to skip to the next step if this is the case.
However, if you need to recompile the code for a different microprocessor, change the pins around, alter the timeout period, or make other modifications, you'll need the .ino file, also attached.
My preferred method for coding for the Attiny85 at the moment is to use the Arduino platform. You don't need to own an Arduino board, but to use the attached code, you will need to download and install the Arduino IDE from here: www.arduino.cc.
You can find instructions for setting up the Arduino IDE for the Attiny85 (and other Attiny microprocessors) here: http://highlowtech.org/?p=1695.
The actual programming instructions are beyond the scope of this Instructable. A quick look around this site should provide a number of excellent Instructables. You can build your own USB programmer using this Instructable: https://www.instructables.com/id/VUSBTiny-AVR-SPI-P..., or build a programming shield for the Arduino board following this Instructable: https://www.instructables.com/id/Stripboard-Arduino.... There are probably many other ways to do it as well.
I've attempted to comment the code to make it clear what it does and where to change things. The pins and power-off time period can be changed at the top of the file.
Step 7: Build the Circuit
The microcontroller circuit diagram is shown above. I would strongly recommend breadboarding it before soldering it to make sure everything is wired up correctly.
Note that I'm using a DIP socket so the the Attiny85 can be removed from the circuit for reprogramming. I highly recommend doing this because it will prevent the microcontroller from being damaged by the soldering process and will enable you to make changes in the future, but it is not strictly necessary.
Note also that I've terminated the three wires going to the PIR sensor with a 3 position female header that matches the three pins on the sensor. This makes it possible to connect and disconnect the sensor as needed, but could potentially be left out if you just want to solder the wires directly to the sensor instead. Make sure to match the wires to the correct pins!
There should be plenty of room in the LED control box to fit the additional circuit board, but the prototype board will probably need to be cut down to fit.
You'll want to test the circuit before moving on from this step. It may be more convenient to reprogram the microcontroller to power off after a shorter amount of time in order to make sure the timer code is working correctly.
Step 8: Repackage
At this point, everything is nearly ready to be repackaged in the original case.
All that's left is to cut a slot for the wires for the PIR motion sensor. Use a sharp knife,cut away from yourself, and be careful!
Step 9: Attach the PIR Sensor
At this point, you can attach the PIR sensor by either plugging it into the header or soldering it to the wires. Again, make sure to match the wires to the correct pins.
I attached the sensor directly to the LED controller case, but you can leave it hanging loose if it's easier.
Step 10: Enjoy!
Honestly, what you do at this point is entirely up to you. I followed Liam.great98's lead and installed the LED strip under my daughter's bed. See his Instructable (here: https://www.instructables.com/id/Give-Your-Bed-Unde...) for more instructions on how to go about it.
Enjoy your hacked LED strip. I would love to see what uses you come up for it in the comments below!
harnon made it!