Pimp Your Chocolates with Arduino IDE and ATtiny13
The idea for this project came to me on the way to the trash. I was tasked with throwing away a box that has just been emptied of its original Ferrero Rocher sweetness content by my dear wife. This was shortly after the Valentine’s Day. So, I got to spend 10 seconds alone with this box and realized that it holds some promise, so it ended up on my workbench instead of the trash.
Despite its festive thematic appearance, this is a pretty sturdy box with enough space inside to hold all components of a simple LED light chaser circuit and then some. Looking inside I found locations for 10 LEDs. Having actually completed this project, I now realize that there was space for at least 12 and the MCU chosen for the project – ATtiny13 – can just as well do 12, and no extra components are required. So, there you go: a path to improving my project right off the bat.
Needless to say, for the project to work, you will have to buy Ferrero Rocher chocolates again although this time a simple bulk packaging is just fine 🙂
I am a big fan of Arduino IDE and one of the important parts of this project was to make sure that I can program the smaller AVR chips, such as ATtiny13, using Arduino IDE. I’d like to refer you to a blog post about using Arduino IDE with smaller AVRs and concentrate this instructable on actually constructing the device. Additionally, for some finer points on programming this particular light chaser, such as changing the light pattern or modifying the sketch to include additional LEDs, please see my Pimp Your Chocolates … blog post.
First step – getting parts together >>
Step 1: Get parts and tools together
The project requires just a handful of parts. Note that one of the most important ones is not in the group picture: the ball tilt switch (the shake/move sensor). I extracted it from an old water filter pitcher that also didn’t quite make it all the way to the trash 🙂
Here are the parts:
- 1 x Atmel ATtiny13 (or ATTiny13A) 8-bit AVR MCU;
- 10 x high intensity red LEDs. I imagine yellow would work, too. If you decrease (or remove) the 120 Ohm current limiting resistors, white or even blue might also work. Experiment!
- About 20 ft (6 m) of 30AWG hookup wire. Red color is recommended because the box is transparent and it’s much easier to hide red wires inside the red plastic insert.
- 4 x 120Ohm current limiting resistors. Could be less than 120 for brighter LEDs (though shorter battery time)
- 1 x 10K resistor for the ball tilts switch part of the circuit
- 3 x 1.55V tablet batteries. Could be any type as long as you have a holder for them. I didn’t at first, so I had to devise a one-time battery pack out of a piece of heat shrink tubing (center of photo) and two strips of brass. For an improvised pack the slightly larger 357-type (LR44) batteries would work best. Later on my dog helped me by destroying one of those electronic squeaking pet toys that had a small battery box for three LR1130 batteries. They have smaller capacity but the box lets me replace them easily
- A small slider switch in case you want to be able to switch the blinker off. The program makes the ATtiny13 go to sleep when there was not change in the tilt switch position for awhile and that helps with battery time. Mine worked for about a month from the three 357 batteries. But if you know that no one will use it for a long time, it would make sense to add a switch.
You will need pretty much your regular tools for electronics projects :
- Soldering iron and rosin core solder
- Cutters (snips)
- Needle nose pliers
- Hot glue gun
Although it is also a tool, the AVR programmer deserves a special mention. I used Atmel’s AVRISP MK II because I had it available. But you can stay true to the Arduino toolchain all the way and use an Arduino board as a programmer. Instructables has quite a few ‘ables about using an Arduino as an ICSP programmer, this one for example. Note that most reference ATtiny45 or ATtiny85 MCUs but the pinout and everything you have to do on the programmer side is the same for ATtiny13, the differences are only in setting up the Arduino IDE.
Step 2: Program the ATtiny13
Since there is not much space inside the box, this is a PCB-less project and so the best time to program the MCU is before you start the construction.
If you haven’t upgraded your Arduino IDE install to the current version 1.0, now is the best time to do it! Although it’s possible to program an MCU using a programmer with earlier versions, 1.0 makes it especially easy with convenient menu options. I definitely recommend upgrading before going further, if you haven’t yet done so.
The Arduino IDE comes with a set of C libraries that are optimized for running on various hardware platforms and types of MCUs. By default, ATtiny13 libraries are missing. It’s a very small MCU and not many people program for it, I guess. Fortunately, there are at least two sets of Arduino libraries that either include support for or can be modified to support ATtiny13:
- Damellis’es ATtiny cores and
- smeezekitty’s core13
I ended up settling on Damellis’es libraries because my next project was to include an ATtiny2313 and smeezekitty’s are for ATtiny13 only. I urge you to visit the homepage of the library you chose for a particular set of installation instructions or visit my blog post about them here: http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/ The installation is not a difficult process and basically involves simply placing the library files into the right directory under the Arduino IDE hierarchy and editing the boards.txt file to tell Arduino IDE that you have just added support for another hardware platform.
For more detail: Pimp Your Chocolates with Arduino IDE and ATtiny13
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
Cheapest PCB Prototype: Only $2 for 10pcs 10×10cm PCBs, 24 hours Quick Turn, DHL Delivery in 3 Days