Musical arduino

arduino with piezo element for sound

arduino with piezo for sound

Time for another arduino project – project 6 in the kit uses the piezo element to make sound.  While I fully admit to not knowing how the sound works, the program supplied with the kit maps note names to tones, meaning that it’s easy to adapt the lists for notes and beats to play whatever tune you want – as long as it’s in the key of C with no sharps, flats or really odd beats, that is! (although I’m sure it would be simple enough to either find a list of notes mapped to tones or experiment to find the right frequency)

The program originally plays twinkle twinkle little star, but I altered it to play Doe a Deer, by matching the correct list of notes and the correct list of beats.

void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
char notes[] = "cdececedeffedf "; // a space represents a rest
int beats[] = { 3, 1, 3, 1, 2, 2, 4, 3, 1, 1, 1, 1, 1, 2, 4 };

The sound itself could do with amplifying, as it’s a little quiet, but that’s really not a drawback at this stage, possibly more of a mercy!

The code provided could easily be amalgamated into a larger project, I’m sure, making it easy to develop the system into something useful and interesting.  For now, I’m just learning about the different things the arduino can do.

While the coding is fairly straightforward, however, I still don’t have much idea yet of how to join my own components together in a circuit.  Ah well, another five projects to go from the starter kit, then there are plenty more resources out there.