Google+ Facebook Twitter Pin It Reddit

Motion Sensing LED

DIY Pulsing LED Motion Sensor

Pimp Your Box of Chocolates with Arduino IDE and ATtiny13

Difficulty: Beginner
Time Required: 2 hours
Designer: eLABZ aka Dmitriy Abaimov

The ATtiny13 is small enough to be hidden inside a box of chocolates to create a blinking twinkling LED pattern when someone touches the box and sets off the rolling ball tilt sensor. The project uses a very small number of components and requires only basic soldering skills.

Charlieplexing is used to drive up to 12 LEDs via 4 I/O pins of the ATtiny13. The original project and the software are based on 10 LEDs but it's easy to increase the number to 12. The ATtiny will go into power-down mode after every blinking cycle and battery life of several months can be expected from small batteries like LR44. The same can't be said for your chocolates.

Build your own Pulsing LED Motion Sensor

Required Tools and Components:

ATtiny13
1MΩ resistor
Bright red LEDs
Silver Oxide Battery 1.55V
Rolling Ball Tilt Sensor
30 AWG wire
120Ω Resistor
SPDT Slide Switch
16-Pin IC Socket
Soldering iron and solder
Tweezers
Wire strippers
Wire-cutters
Hot glue gun/glue
AVR Programmer

Check out the blinking box of chocolates video here.


Step-by-Step Instructions

Step 1 - Prepare the LEDs

Solder 8-12" leads of 30 AWG wire to each LED. You need approximately 8-12" for each LED because their locations will be picked at random, so the wire has to reach anywhere in the box. Cut the LEDs own leads to 1/8" (3mm). Make sure to mark one of the wires: polarity matters a great deal in Charliplexed LEDs.

Prepare the LEDSPrepare the LEDS

The Egg Kit SchematicResistors and tilt switch

Step 2 - Solder the resistors and the tilt switch

Mount and solder all components except for the ATtiny13 MCU onto the 16-pin IC socket. Mount the four current limiting 120Ω resistors on top of the IC socket and solder them to the socket. Mount the tilt switch and its pull-up resistor to the underside of the socket (see the picture)

Step 3 - Solder all circuit connections

Complete the circuit by adding the I/O pin connections and soldering LEDs.

Circuit DiagramCircuit diagram (click for larger image)

Be extra super careful soldering LEDs to make sure the polarity is correct. Troubleshooting and fixing such a small circuit is very difficult. Don't use too much solder for the first LEDs - each of the I/O pins will receive six LED leads, so use only a little solder to prevent build-up. When you're mounting the tilt switch (the gray cylinder at the top of the picture), bear in mind its final position in the box. For better battery life, it should always be in an OFF position when the box is resting on a level surface. So, it's better to have it leaned onto the OFF side. On the other hand, the closer the body of the tilt switch is to the level position, the more sensitive it is. If it's nearly perfectly level, just walking past the table with the box on it will set it off. Experiment with the best tilt switch position during this step and also when you mount it inside the box.

Solder circuit connectionsSolder circuit connections

Step 4 - Program the ATtiny13 and insert it into the socket

Use your favorite programming tools to burn the program into the MCU. I used AVRISP MKII programmer, but there's a wide variety of hardware available to do the task - from an Arduino running in a programming mode to various AVRISP clones and original programmer design, some of which Jameco sells. As far as the program to control the programmer, you can use avrdude, but because I used Arduino IDE for development, I've set it up to recognize ATtiny13 and program it. It is a rather lengthy topic, please read about it at: eLABZ.

The Arduino sketch we'll be compiling and burning is here: http://elabz.com/wp-content/uploads/2012/04/Charlieplexing_Tiny13_softPWM.ino_.zip

Please check out this page http://elabz.com/pimp-your-chocolates-with-arduino-ide-and-attiny13/ for tips on modifying the program, should you find the blinking pattern, speed or the number of LEDs in need of change.

Charlieplexing in Arduino IDECharlieplexing in Arduino IDE

Step 5 - Solder the battery and test everything on the bench

Solder the battery to the corresponding pins of the IC socket and if you like, use the optional slide switch on the battery's positive lead. The goal of this step is to test everything before mounting in the chocolate box (or whatever enclosure you've chosen). Make sure everything works before you start wielding the hot glue gun!

Troubleshooting will become progressively more difficult after this point.

Completed circuit ready to installCompleted circuit ready to install

Installing LEDs in chocolate boxInstalling LEDs in chocolate box

Step 6 - Glue the components in place

Be careful not to touch the hot gun to the plastic insert! It melts very easily.

Remove the plastic insert from the chocolate box, flip it over and use a hot glue gun to glue the components in place. Randomize the LED positions. There are plenty of ridges and valleys on the back of the plastic insert to mount all components. Sink the LEDs into *random* valleys and let the glue drop on them to hold them in place when set. The largest spaces are around the perimeter and this is where the larger components - battery and MCU circuit will go.

Step 7 - Put everything back (including the chocolates) and enjoy!

Put everything back, turn it on (if you used switch, otherwise it's always on). When done, set it on a table for your special someone to discover. When they take the box to open it, the tilt switch will change its state and set off the blinking sequence. Enjoy!

Chocolate box