Christmas time is just around the corner and so is the next tinkering project:
it has to do something with Christmas...
it has to do something with software...
it has to do something with electronics...
…Ermm, so the first idea was to put a bunch of colourful LEDs around a Christmas tree. Indeed, that is innovative as putting coloured paper around a gift. So I came up with the idea to make a jingle bells playing light-up piano keyboard by utilizing …well, a tree and LEDs but additionally there‘ll be a speaker ;o)
So, here‘s a little sketch about the idea:
The first challenge is the keyboard design. We need to know how to play jingle bells on a keyboard. As you might know or see on YouTube tutorials, there are several ways to play this song. The easiest way is to use a single note at a time by just playing the melody of verse and chorus. The lowest key I used for playing is a D and the highest key is the E on the next octave. Between those two keys we also need E, Fis, G, A, B, C, D (on the next octave). But keep in mind, you could also transpose the melody to higher or lower notes. So, after figuring out which keys we need I started drawing a keyboard in Gimp. To make things easier, I wrote the name of the note on each key and marked the notes that have to be player with a red dot. Some more keys than necessary a there for a clean look.
Now that we have finished the outer design of the keyboard we need the interior. There was a small non-etched copper circuit board in the tinkering box since years. So this is a good starting point. We can carve a circuit (respectively the boundaries of the tracks) into the copper board by using a box cutter. Then, soldering small SMD LEDs and resistors across the tracks (right over the cut of the box cutter) to connect them to the appropriate nets. This doesn’t only sound like a mess but it also looks like a mess.
Now let‘s put the keyboard design and some descriptions on this messy photo to see what has been done here. Since very small SMD parts were used its quite hard to see. Yes, it‘s even harder to solder. Be a little smarter than me and use bigger parts :-)
Here is an appropriate schematic design.
The next thing to prepare is a speaker. If you are lucky you find one in an old walkie talkie device, phone, toy, etc. My speaker looks like this.
I decided to use a NPN-transistor to connect and disconnect the speaker to the voltage source. The idea is to do this with a frequency that equals the musical notes of the song. This will result in a square wave sound which is the very loud and sharp. R1 is used to make the sound more quiet. Push a jumper at position X1 to get out the maximum volume but be sure your speaker can handle the power :-)
Now it‘s time to put things together. We have 9 control lines for the LEDs and 1 line for the speaker signal. We want the device to start playing if a push button is pressed and when done playing the device shall be switch off automatically. For this, we use a pushbutton in parallel to a relay switch which is controller by the ATmega. If someone presses the push button then the ATmega starts running and holds the relay closed. This way the user who pushes the button only has to hold for a few milliseconds until the system runs. If the song has been played then the ATmega shall release the relay signal so that the relay opens and the battery gets disconnected.
The electronic part is ready, now it‘s time for the software to put life inside. The song is an array of 16-bit values (uint16_t song) and each value represents the wave period of the appropriate piano key sound. Now, the software just has to iterate through the array, light up the appropriate LED and change the PWM settings according to the current value as read from the array. Additionally, there is a delay function for the timing to switch off the PWM between the notes to make it sound like as if the piano keys are pushed down and released in a very simple rhythm. Here is the source code.
A small fake fir tree that can be found in a typical decoration store besides tons of other useless stuff makes a great stand for the keyboard and gives a real Christmas touch to it.
Now, here is my realization of the plans above. The front side shows the keyboard and a push button. The push button is at the bottom in between the red ribbon.
The back side shows the 9 volts battery, the speaker and the perfboard which holds the ATmega, the 7805 voltage regulator, the capacitor, the transistor and two resistors.
You may wonder where the relay is gone. I only had a 250V relay in my tinkering box which is kinda big. So I fixed it with a cable tie to the tree. Indeed, this is like using a sledgehammer to crack a nut but the part was already there :-)
Here is a video of the tree in action. Unfortunately, in the video it is quite hard to see that the LED illuminates one key instead of all keys nearby. This looks better in real.