Introduction: Animated LED Heart
This is a battery-powered LED heart with several different animated flashing sequences, selectable with a push button. I designed and built it for my girlfriend this Christmas. While waiting for the parts to arrive, I went through several redesigns, particularly because I couldn't find a good tradeoff between a good LED layout and low complexity.
I finally settled on a layout that uses 14 LEDs, two 8-bit shift registers and an ATtiny85V(though even a lowly ATtiny25 would probably work if I simplified the code, I wasn't sure how much program space I'd need and the cost difference is negligible). I've used a socket for the microcontroller so I could test different patterns and animation speeds. After running for 50 straight hours(with a somewhat above average "load" animation), my generic AA alkalines(fresh when the test started) were measured at 1.71 volts. It was still working, albeit with very low light coming from the LEDs.
So here is my first Instructable, for your enjoyment and/or education. See a video of it in action here(it doesn't actually "fade"; that's just my camera being slow) and showing off newer patterns here(sorry for the color balance). Hopefully my girlfriend likes it, and I hope you do, too! Please let me know if anything is too confusing or if you have any questions. If you decide to make one yourself, or if you're inspired to build something similar, I'd enjoy seeing your results!
Step 1: Parts
The following is the parts I've used in my design. You may wish to use a different shape with more or less LEDs, and most parts can be substituted. Prices are all before any taxes.
* Grid PC Board; I got mine at a local independent electronics shop, but it's very similar to RadioShack's #276-158. You can probably find one on Digi-Key, but they are needlessly expensive($10+ for a board this size), as they only carry boards designed for repeated resoldering. I'd avoid a stripboard unless you know what you're doing and are familiar with them. RadioShack's is $3.19.
Note that you could prototype this project on a solderless breadboard(and I did all of my microcontroller programming/testing on one), but the "heart" or other shape aspect will be mostly lost, obviously.
* AAx2 battery holder; I also got this from my local retailer, but you could also use RadioShack #270-408 for $1.99.
You could instead choose a low voltage(<5.5 volt for most AVR microcontrollers) power adapter instead, or a higher voltage(maybe a 9V battery, but you wouldn't have much run time) supply with a regulator.
* 3mm red LEDs - 14 pcs.; Mine are low current(2mA, but they handle up to ~30mA) from Digi-Key(754-1245-ND), and cost just under six cents each in a bag of 100. I should warn you that this exact part is actually red-orange when lit up. RadioShack part 276-026 is very comparable, and they're truly red, but cost $1.69 per pack of 2. Ouch. Converted cost for this project is $0.83($1.26 if you don't go for the 100 pack)for the Digi-Key LEDs and $11.83 for the Shack's LEDs.
Color is up to preference, but other colors have different voltage drops. More information below.
* 330 ohm resistors - 14 pcs.; Power rating and resistive element type don't make a difference, but carbon film are cheapest. RadioShack sells these in packs of five(#271-012) for $1.19 each. Digi-Key CF14JT330RCT-ND are eight cents each, individually, but if you're working with a lot of LEDs, you might wanna buy a 100 pack for $2.19 total. Amazing deal, if you ask me. RadioShack, $3.57(with one lonely resistor left over); Digi-Key, $2.19(with 86 resistors partying in your spare parts container afterward).
I calculated this resistance to provide between 2-5mA to the LEDs over the life of two alkaline AA batteries(3.2 volts fully charged, ~2 volts nearly dead). If you'll be using a different power supply and/or different LEDs, you should use an online calculator to find the value you need. Assuming you're still using batteries, find the charged and depleted voltages to ensure your LEDs look good over the life of the batteries. Here is a good calculator, but be sure to change the "how many connected" field from 2 to 1, unless you want to run multiples(do so at your own risk and with experience). Keep in mind that shift register pins don't like to supply more than about 25mA each.
* 47k ohm pull-up resistor; This lets us use the button reliably. It doesn't have to be as high as 47k, but I chose it to draw as little current as possible, as I'm running from batteries. You only need one, but RadioShack #271-1342 will get you five for $1.19 and Digi-Key S47KQCT-ND will run you $0.08 apiece.
If you already have a resistor greater than 10k, you could use it, but try not to go too far above 47k, or your microcontroller may not get enough current to be held high. Experiment on a breadboard if you have any doubt!
* 74HC595 shift register - 2 pcs.; These are each capable of driving 8 outputs, although one output on each is awkwardly on the other side of the chip. Since I'm using 14 LEDs, I just left those "odd" outputs unconnected and wrote my code to match. I used 2 296-1600-5-ND from Digi-Key at $0.63 each. RadioShack doesn't seem to sell shift registers, so my recommended Digi-Key alternative is SparkFun(COM-00733) who will charge a modest $1.50 each. Totals are $1.26 for Digi-Key's or $3 at SparkFun.
* DIP-8 IC socket; I highly recommend one for making adjustments to the code after assembly. Even if you don't intend to write or modify your own code, if there's some problem, you'll want to be able to diagnose it. I used a Swiss-milled gold-plated socket I had lying around, but it really doesn't make a difference for this. Digi-Key A100204-ND is $0.14 and RadioShack #276-1995 is $0.59.
You don't necessarily need one, if you're confident with your assembly and soldering skills. An alternative, if you'd still like programming access afterward, is to use pin headers to connect an ICSP(in circuit serial programmer). Heck, maybe you wanna use both.
* ATtiny85V; This little 8 pin microcontroller has 8K of program space, which is lovely for prototyping. I've found I don't need that much, and could get away with an ATtiny45 or possibly even a 25. I chose the "V" version because it reliably runs on voltages as low as 1.8 volts, so it's ideal for battery use. RadioShack doesn't sell microcontrollers alone, but SparkFun has the standard(not low-voltage) version COM-09378 for $2.84 and Digi-Key sells the ATtiny85V(ATTINY85V-10PU-ND) for $2.26.
Just about any microcontroller can be used here, as we only need 3 pins for shift register control and one pin for button input. If you want to forgo the shift register wiring(and coding, if you don't use my code), you should go with a controller that has enough pins to drive all of your LEDs. You can greatly increase the number of LEDs a chip can drive with charlieplexing, but that's a topic for another Instructable. Also be sure to get a different socket size if your microcontroller uses more pins!
* Power switch; I won't recommend a specific switch here, because there are thousands of valid options, and what you pick depends on what case you put this in, if you use a case at all. SPST or SPDT will work, but SPDT may be easier to find. Spec the voltage rating for your power supply, and calculate your worst-case scenario for current. Most switches will provide more than enough, but for the record, my design here will consume no more than 60mA. I paid about $4 for mine, a panel-mount paddle switch.
* Push button; This will be used to switch to the next pattern animation. Like above, there are far too many options to recommend one. I prototyped with a standard, breadboard-compatible button, but my final design uses a panel-mount button. A four pack cost $3.69.
* Enclosure; If the button/switch had a lot of options, this is just crazy. You could put this in a cardboard box, or mounted to a piece of wood or plexiglass, or even leave it exposed. Put it in a custom wooden case or hang it on the wall. Just be sure that nothing shorts out on the bottom of the circuit board. If you mount on metal, use standoffs or a lot of electrical tape. I used a tin that has a clear, plastic window in its lid. My mom had this lying around, so it cost me nothing.
Step 2: Tools
You'll need a few, basic tools to complete this project, and maybe some more if you want to put it in a case.
* Soldering iron and solder; Be sure to have a fine tip, or you'll probably make a mess on the board and even short out some connections. I used a basic 40 watt iron and had no troubles. There are lots of Instructables about soldering, so I won't cover it here.
* Diagonal cutter; These are used to trim excess LED and resistor legs. I used a small precision pair, but larger ones should work. If your wire cutter has its cutting portion at the very front, you may be able to just use it.
* Wire cutter/stripper; As you might guess, this is for preparing wire to connect components on your board and likely when programming your microcontroller.
* Digital multimeter; It's pretty difficult to find out why a circuit isn't working if you can't test it with one of these.
* Microcontroller programmer; Many AVR chips can be programmed using an Arduino, but you'll have to check which yourself. In fact, you might even end up using an Arduino as your microcontroller itself. Alternatives are Microchip's PICkit for PICs and... Sorry, I'm not familiar with any other types. Instructables' fabulous community can probably help you with any other chips, though!
* Wire; Yeah, it's a material, but it isn't a "part" and it goes with the wire cutter/stripper. 22-24 AWG works well in breadboards and on the soldering perfboard, but 24 gauge wire will not stay in an Arduino's pin headers well.
* Helping hands; You'll definitely want this when soldering. It's no fun chasing your board around a table, so use this to hold it in place. Additionally, you'll need something to hold LEDs at the right angle if you want them to look uniform. This can do that for you.
* Drill and bits; Only if you want to put this project in a case. Be sure to use a hole gauge if you don't know the diameter of the parts you need to drill holes for. A file may come in handy if the holes end up with rough edges, but the part might cover them up for you.
Be sure to have lots of light when soldering, and always quadruple check your placement and rotation of parts before soldering!
Step 3: Plan!
I can't stress this enough: plan as much of your project as you can. I spent at least twice as much of my time planning where everything would go and work together than I did actually assembling it. I probably should have spent even more time planning.
Anyway, determine your limiting factors(mine was complexity) and work from there. I considered using eight LEDs with one shift register, but that layout didn't even look like a heart. So, I kept plotting points on a grid in the shape of a heart, using different amounts each time. Note that the LEDs, when placed in your perfboard, won't form the exact shape plotted out unless you put a lot of space between them, or have some rotated 90 degrees. As you can see, the LEDs on the far left and right are spaced slightly more than the rest, because they're the only ones that aren't diagonal to their neighbors.
Be sure you have enough board space to fit all of your components. This may seem obvious, but there's a lot that can be overlooked. Standard 1/4 watt resistors will cover a total of four contiguous holes, when placed flat. My board had just enough room for the LEDs, shift registers(and access to their control pins), and four holes between each shift register and their closest LED. If you wanna get crafty(and risky), you can try other layouts, or even solder the resistors vertically to save room. I wanted as little sticking up as possible, so that wasn't an option for me.
Hopefully, this schematic will do a better job at showing how things are connected than my pictures and descriptions in the following steps.
Step 4: Assembly: Shift Registers and LEDs
Most of the "Assembly" steps can be completed in some different order. This the just the order I've found easiest.
Solder in the shift registers, taking care to have them lined up as planned. I wanted the "middle" LED on each side to be lined up with the "middle" output pin on each register. This is known as "QE" or pin 4(if you don't know how to locate a numbered pin, learn now; Google can provide many answers that are better than I could explain). Also make sure there will be room for resistors between each pin and its respective LED.
Now we get to solder in the LEDs, which is a difficult part, in my opinion. Make sure each side's LEDs are in the same direction. If you're using my code, this means the anodes(positive, longer leg) will all be closer to the shift register than the middle. You could do it the other way, but my patterns are written for common-cathode, and the display will be inverted with a common-anode array. Also remember that the upper 7 LEDs will face the opposite direction to the lower 7, assuming you put the shift registers in the same places as I did.
To get them to stay uniform and upright, I did one at a time and held one leg with the helping hands while positioning the board. If you don't have access to helping hands, you could also use tape on the other side to keep it aligned while you solder. Be careful when soldering not to bump it out of alignment. This gets more difficult when more metal legs are sticking up in your way, but don't clip any yet!
Step 5: Assembly: Resistors
There's not much to say here. These will be the only things(no wires or anything) connecting our shift registers to our LEDs. Bend the leads at a distance that looks close, then push them through. On the connection side, carefully bend one lead around the anode(or cathode, if you're doing your circuit that way), parallel with the board and perpendicular with the LED's leg. It doesn't have to go all the way around, just make sure it's not touching any other pins or legs.
Push the other leg of the resistor down against the pin of the shift register you're soldering to, again taking care not to let it touch other pins. Solder both leads to the pads they come in through, then to the LED and shift register. Clip the LED's leg close to where you soldered, then trim the excess resistor leads. Repeat!
Step 6: Assembly: Unite the Cathodes!
As the title implies, this is the point where we connect all the cathodes together. Bend them over, one at a time(except for the first two, of course), and solder together. If it looks like a leg might get in the way, trim it just as much as you need to, but having extra room to solder to is nice.
Be sure not to bend too close to the solder joint, and avoid letting any contact the anodes at all costs(well, it won't be a problem until the circuit is powered; sorry for being a drama queen). We don't want shorts! Check that each LED's cathode is connected to each other's. Use a DMM's(digital multimeter) continuity mode if visibility is low. If yours doesn't have that mode, use the lowest resistance setting. Less than a few ohms is good enough to count as "continuous".
There's no need to check every pin against every other. That would be 182 checks! Just knowing that one pin is continuous with each other is good enough.
The result of this step may look ugly, but if it isn't sticking out very far, it should work fine.
Step 7: Assembly: IC Socket and Wiring
This is my least favorite step, as it makes an otherwise "pretty" board look ugly and distracting. I'd wire on the underside, but my board only has pads on one side and I don't like soldering on the same side as the component. I'll stop whining now!
First, I soldered the socket. I tried to put it where I would have plenty of room to connect to it. Down in the corner, away from the edge, turned out to fit the bill. Pictures and their annotations will do much of the explanation for the rest of this step.
Next, I connected power wires to their pins(VCC and ground) and to pins that need tied either high or low.
I then soldered in the shift register control wires. Serial clock on both registers is connected to the same pin on the microcontroller(pin 6, digital 1), and register clock on both registers is connected to the same pin(pin 7, digital 2). Serial data(pin 5, digital 0) is only connected to the data input of the first shift register, due to the way they work. When you shift more than 8 bits into a shift register, the oldest bits(that were shifted first) are output from QH'(note the single apostrophe), pin 9 on the chip. For this reason, we connect "QH'" from the first register to the serial data input of the second.
Remember when wiring that form is as important as function in this project. It may look a little silly to have wires go out of their way around the board, but that's better than covering up the LEDs.
Step 8: Assembly: the Button
You know you love the button. You know it's fun to press. Now we get to use it.
We connect its leads to ground and our microcontroller's input pin. With an ATtiny85V and the code I provide, that's pin 3, digital 4. We also have to connect our pull-up resistor from VCC to the input pin. Don't leave this resistor out or jumper it, or you'll short circuit whenever you press the button!
Step 9: Programming
This step was much of the project's working time. Lucky for you, if you use the same circuit as me, I've done the work for you. It may be horrendous for a skilled programmer to look at, but it does work. Sorry to people not using AVRs, because this code is meant for use in the Arduino IDE.
To those that want to change the patterns, pay attention to the sequenceLengths array. It should accurately represent the lengths of all other sequence arrays. If you want to add or remove any, adjust sequenceTotal to match, change sequenceLengths to the correct number of patterns, and add a "case" to findAndWriteStep().
Feel free to ask if I've been unclear in my comments or above.
Step 10: Enclosure and Power
Use alligator clips from your power source to VCC and ground on the circuit to test it. Once you have it working how you want, you may decide to mount this project in an enclosure. You're on your own here, but be sure you can push your power switch through before soldering it to anything. Mine has a little bevel that can't be removed, so it must be pushed into the enclosure, whereas the push button can be pushed out from the inside. I don't yet have the proper mounting hardware, so you'll have to wait if you want to see how this looks in my enclosure.
After these potential problems are worked out, solder the negative(or ground) side of your power supply/battery holder to your circuit's ground. Solder the positive wire to your power switch's common pin(or lug). If it only has two(an SPST switch), it doesn't matter which you use, but if it has three pins/lugs(like an SPDT switch), use the middle one. Then attach a wire from the other pin(either, but not both of an SPDT switch) to VCC of the circuit. You're done!
Here's a video of mine, if you're interested. It actually changed states instantly; the "fading" in that video is a camera effect.
Update: I changed the code a bit to tweak the animations and disable the random one(though it's still there; you just have to enable it). I recorded a new video to show these changes.