In this tutorial, I will show you how to build a musical birthday cake. The project uses a 3D printed cake to house a simple circuit with an ATtiny13A microcontroller. It uses a reed switch that triggers the Happy Birthday tune whenever the cake is placed on top of a magnet.
Bill of Materials
- 3D printed cake (The one I used)
- ATtiny13A
- Reed switch
- Piezo buzzer
- 8-Pin DIP socket
- Magnet
- Perf board
- 2 x LR41 batteries
- Electrical tape
You can find most of these materials on eBay or Amazon. You’ll have to 3D print the cake yourself or get creative and make one out of cardboard.
Programming the ATtiny13A
You will need to program the ATtiny13A with the code that plays the Happy Birthday tune. See this tutorial from SparkFun if you need help programming an AVR chip.
For this you will need:
- Programmer such as the AVRISP mk.II or USBasp
- Atmel Studio 7
- Happy Birthday Tune source code
You don’t have to use Atmel Studio 7, you can use avr-gcc with AVRDUDE from the command line if you know what you are doing.
Use Atmel Studio or avr-gcc to compile the Happy Birthday Tune source code to produce a HEX file. Use the programmer to flash the ATtiny13A with the HEX file.
Simple Circuit Schematic
This circuit uses pin 5 to drive the speaker. It is very simple to build. You will need to place the reed switch on pin 8.
Building
Follow these steps:
- Cut the perf board into a small circle that will fit inside the cake. See the picture above.
- Cut two wires for the battery connections.
- Place the 8-pin DIP socket and the piezo speaker from the top of the perf board and solder per the schematic.
- Place the reed switch from the bottom of the perfboard and connect one end to pin 8 (VCC) and the other end to the positive wire.
- Put the ATtiny13A chip into the 8-pin DIP socket. Be careful not to bend the leads.
- Tape the 2 LR41 batteries together and attach the positive and negative wires.
- Put everything inside of the cake.
- Assemble the cake then put it on top of the magnet to start playing the Happy Birthday tune.
Final Product
You can modify this circuit and source code to play just about anything. The ATtiny13A has limited memory but it can be swapped out for an ATtiny85 for longer tunes. I used a modified version for the Death Star the plays the Imperial Death March that I built for my son.
Pingback: Build a Custom Toy Traffic Light | Ruben's Thoughts