Introduction: Musical Card (ATtiny85)
One of my team was leaving and I thought what better way to wish her all the best than with a singing card.
- Passive piezo buzzer
- Lithium Button Cell Battery (CR2450)
- Momentary button (type commonly used with an Arduino)
- 10uF Capcitor (used when programming the ATtiny85)
- Glue (PVA & Craft glue)
- 4mm Plywood
- Card (A5)
- Paper (A4)
- Soldering Iron
- Wire cutters/strippers
- CO2 Laser cutter
- CNC Machine
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Preparing the Music
Disclaimer: I am no musician and so do not know the names of the notes or part of music scores hence please bear with my poor description below.
Load the MIDI file into MuseScore (or a program that will allow you to edit MIDI files) and then edit the music as follows:
- Whenever there are notes in the same column, keep only the top note, remove all notes beneath it.
- Remove the bottom set of notes
In this way you would have reduced the music to single notes.
Export the new music score to a new MIDI file. This file will now needed to be converted to the appropriate Arduino code.
This was achieved using: https://extramaster.net/tools/midiToArduino/
Step 2: Programming the ATtiny85
Before the Arduino can be used to program the ATtiny, it needs to be set up as a programmer. To do this, Open Arduino IDE and load the ArduinoISP file found in the examples (File -> Examples -> ArduinoISP). Once loaded, upload it to the Arduino
Connect the Arduino to the ATtiny85 as follows:
ATtiny ----- Arduino
- Pin PB2 (SCK) ----- Pin 13
- Pin PB1 (MISO) ----- Pin 12
- Pin PB0 (MOSI) ----- Pin 11
- Pin PB5 (Reset) ----- Pin 10
- Plus (VCC) ----- +5V
- Minus (GND) ----- GND
- 10uF Capcitor: Across Arduino pins: RESET ----||---- GND (note -ve capacitor pin goes to ground)
As I will want to make more of these cards, I decided to build a shield as found in https://www.instructables.com/id/ATtiny-Programming-Shield-for-Arduino-1/.
You now need to install the ATTiny code. Initially I installed a depreciated library without realising it which caused me days of pain. Go to File -> Preferences and copy the following URL to Additional Boards Manager URLs:
http://drazzy.com/package_drazzy.com_index.json (the following no longer seems to work https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json).
Then go to Sketch -> Include Library -> Manager Libraries and install "ATTinyCore by Spence Konde".
Once complete set the Tools settings as shown in the image i.e.
- Board: ATtiny25/45/85
- Clock: "8MHz (internal)
- Confirm the correct port
- Programmer: "Arduino as ISP" (NB NOT ArduinoISP)
With the ATtiny connected, choose Burn Bootloader (under the tools menu). This will set the clock to 8MHz.
Load the Arduino MIDI code, ensuring the the tonePin is set to the correct pin. In my case this was 1.
Step 3: Testing the Code
Connect the ATtiny85 as per the diagram. You should now hear Auld Lang Syne being played in a repeated loop.
Step 4: Creating the Card
Using the attached SVG files, the card was cut and etched, as was the plywood. The desired images and fonts where downloaded from the web, with InkScape being used to manipulate them and put it all together.
Step 5: Embedding the Electronics
Using FreeCAD I created the tracks where I wanted my components and wires to lie. This was the exported to a STL file and then cut out using a CNC machine.
In the end some sections were too tight and so I needed to use a chisel to make the spaces bigger. Unfortunately in doing so I penetrated the surface of the plywood is some places. Fortunately I was able to camouflage these holes but it was disappointing.
I forgot to photograph the final component placements and so I have simply illustrated them here. It was really challenging soldering the wires directly to the battery and so next time I will see if I can find a compact battery holder or do more research to see if there is an easier way to do this.
Originally I wanted to create a switch that would trigger the music whenever the card was open but I run out of time to work on this. I therefore resorted to a momentary button that doesn't quiet protrude through the plywood. The reader can then push the button while reading the card in order to play the music. I have found some small N/O & N/C reed switches that look perfect for this sort of thing and so next time I will trigger the music automatically using these switches with a small magnet (or should I say, "I will give it a try").
Step 6: Putting It All to Gether
In order to hold the components and wire in place I used a quick-setting gel glue (can't remember the name or type). To attach the plywood and construct the envelope, I used PVA glue.
I also cut the attached envelop out using the laser cutter.
All in all I enjoyed doing this project. The electronics are simple and easy to build meaning that going forward I can create more interesting cards for the grand kids :)
Step 7: Final Comments
So with so many people pushing the button when signing the card, the battery went flat before we could give it to the recipient. I therefore had to cut a whole in the back, replace the battery and then cover the hole with a round sticker; not ideal but it worked. I did not resolder the battery but simply used the sticker to hold everything in place so that contact with the batter was maintained. This did not work too well, resulting in it being necessary for the reader to apply pressure to the back of the card when pushing the button. This said, the given layout made the process really easy.
Going forward I will see it I can build a slimline battery holder or change the way the battery is held in the card in order to make replacement easier.
I have since discovered the following Copper Piezo Discs that will also work. They are much thinner making it easier to embed in the wood or card.