Everyone likes getting trophies. They're shiny, have a nice heft, and feel great to hold in your hand. They're visual and tactile, but decidedly lacking in the auditory department. Let's fix that, shall we?
The video above should give you a pretty good idea of just how sensitive you can get your circuit to be. Just the slightest motion causes it to break out in A-ha's Take On Me (sorry, I couldn't find an RTTL version of We Are the Champions).
Step 1The first step in your path to musical trophy greatness is to prepare the vibration switch. I prefer the "fast" model, but if you don't want your circuit to be as sensitive you can order a medium or slow variant from Adafruit. Take the switch and solder a small piece of wire to the very thin wire coming out of the switch. This will allow us to put it in the breadboard.
To make the whole thing more rigid you can apply a small dollop of hot glue as shown in the photo. It also serves to insulate the two connections from each other. You're now ready to start wiring!
Step 2The next thing to do is breadboard your circuit on your mini breadboard. If your AA battery holder has leads that cannot be stuck in the breadboard you may need to solder on some solid-core wire. The circuit diagram is shown above. It is also available at circuits.io.
Where the button is in the breadboard you're going to use the vibration switch. Connect one of the pins to ground and the other to pin 2 on the ATtiny.
Step 3Now that you have your circuit wired you can upload the code to the ATtiny85. The Arduino file is in the "Attachments" section. This tutorial is a great resource that shows you how you can program your ATtiny with an Arduino Uno. Just make sure the AA batteries aren't connected when your Uno is connected! If you give the breadboard a shake the tune should start playing.
Some ATtiny cores do not come with the tone() function built-in, which is necessary for this project. I know for a fact that the following board manager URL core has it built in: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json. You can add this to your list of board managers URLs, then using the board manager install this ATtiny core.
A quick little side note here about power: the ATtiny is using something called pin change interrupts to save power. While the ATtiny is sleeping and waiting for an event from the vibration switch it's hardly using any power at all. In fact, your tiny can sleep for years on the power provided by those AAs. My multimeter isn't even sensitive enough to measure the tiny amount of current flowing through it! As shown in the YouTube video, the circuit draws about 6mA when active and making noise. Just turn on the batteries and forget about it!
Pin 2 is connected via software to a pull-up resistor, meaning that when there's no electrical connection between some voltage level (either 3v, ground, etc) the pin is "pulled" to a logic high, which in this case is about 3 volts. When the spring on the inside of the vibration switch comes into contact with the lead (the trophy is shaken), the pin is briefly pulled low, which triggers a pin change interrupt on the ATtiny. This then wakes it up from sleep. Cool, huh?
Step 4Now that the wiring is done you can prepare the trophy! My particular one is a chess trophy that I won a few years ago - there's a small nut in the bottom that allows the whole thing to be disassembled. Pretty much any relatively large trophy will do. Start by taking yours apart.
In order to get the breadboard to fit I needed to cut away some of the internal support material of the trophy. This can be accomplished with a pair of scissors.
I then placed my breadboard and battery in the notch I cut and affixed the whole thing with some hot glue.
The rod running down the center of my trophy takes up a lot of space, so I decided to just scrap it and hot glue the whole trophy together. This thing is a lot weaker without that rod holding it together, so don't go dropping it. The hot glue is strong enough to allow you to shake the trophy vigorously, however.
Helpful TidbitsThat vibration switch is more sensitive along some axis than others. Take a look at the below image from Adafruit of the sensor cut open:
As you can see, the entire sensor is just a spring wrapped around a rigid lead. It's consequently more sensitive along the x-axis and y-axis than the z-axis, so plan your placement accordingly.
Going FurtherOf course, Take on Me is not the only song you can play. The sketch attached in this thread has a ton of other songs. You can even create your own using an online MP3/MIDI to RTTL converter. In order to make your circuit much smaller you can scrap the breadboard and switch to a perfboard or a protoboard. This will also make the circuit much more resistant to breaking. You could even design a PCB to eliminate having to wire components! Thanks for reading, and let me know below if you end up making this!
Comments