Making music with a microcontroller can be fun and simple! For this project, we're using a pushbutton to trigger a melody played over a piezo speaker, à la Kraftwerk, Pocket Calculator. I'm sure you remember how it goes, "by pressing down a special key it plays a little melody" (Karl Bartos, Ralf Hütter, Emil Schult, © Sony/ATV Music Publishing LLC, Warner Chappell Music, Inc.). The model here is more a faithful representation of a basic door bell, rather than a calculator. Simply push a button and a chime or melody will play.
For this project you will need:
1x Arduino Uno R3 microcontroller
1x piezo speaker
1x resistor (10kΩ)
several jumper wires
Assemble the circuit in accordance with the diagram below:
Here's the code for you to hack (view content in browser to see code example). Lines 13 through 20 make up the melody. After each tone() function is called, a delay() function is used to determine the duration of the tone.
Try creating your own melody and have fun!