Circuit 06 – Piezo Tunes
Having explored Motion, Light and Electrons we are now going to look at Sound using a simple circuit consisting of a single Piezo element. Even though the output of the Arduino is digital because of its speed it is possible to produce music by pulsing a piezo element at the right frequency.The tone of each note is calculated using:
timeHigh = period / 2 = 1 / (2 * toneFrequency)
which allows us to produce the following notes:
note | frequency | period | timeHigh |
c | 261 Hz | 3830 | 1915 |
d | 294 Hz | 3400 | 1700 |
e | 329 Hz | 3038 | 1519 |
f | 349 Hz | 2864 | 1432 |
g | 392 Hz | 2550 | 1275 |
a | 440 Hz | 2272 | 1136 |
b | 493 Hz | 2028 | 1014 |
C | 523 Hz | 1912 | 956 |
The following code will play Twinkle Twinkle little star. The four functions are generic but the four lines at the top are what determines the tune played. For example, the following is the first line from Happy Birthday
char notes[] = {"ccdcfeccdcgf "}; int beats[] = {1,1,1,1,1,2,1,1,1,1,1,2,4};

