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:

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

About CDB 360 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.