pwm pitches


I’m building a prototype toy that plays small melodies, and all I’ve found that’s really working when it comes to clean tones is the standard description on the Arduino Playground pages
What if I want other pitches above and below this example? I’ve found a way to count out the frequencies, but the pwm in Arduino don’t really make sense to me, and the examples in my Physical Computing book also operates with other programs (and other numbers) - is there a logical formula to interpret sound frequencies into pwm for arduino? Anybody who’s done something like this before maybe? I get along, but some of my tones sound like they’re not exactly on spot…

Best Wishes


You can take the given octave and extrapolate from there. Each octave up is twice the frequency, half the period of the one below. If you sound a bit out of tune at higher pitches, you might consider that each digitalWrite() call takes about 5 microseconds.


That’s a really good advice :slight_smile: I did not see that the frequency was exactly the double, and the period half the value of the previous octave. I guess the extra microseconds may cause some dilution in tone purity, but now at least I feel that I have a good ground to explore out from.

Have a nice day!