Go Down

Topic: tone() (Read 742 times) previous topic - next topic


Hi all.

Arduino documentation states that the tone() function generates a frequency in Hertz equal to the second parameter passed to the function.

But I tested in two boards: MEGA and MAGA2560, and concluded that this is not the case. For example: tone(21,0) generates a frequency of about 60Hz at pin 21.

More generally, tone(p,k) seems to generate a frequency of about k*60 Hz at pin p.

Any comments?

Thanks in advance.



Tone seems to be intended for audio tone generation.  I would not expect it to work properly for frequencies outside the range of human hearing (roughly 16 Hz to 20 kHz).  It's not that the ATmega chips are not capable of very hight and very low frequencies.  It's just that sometimes that takes extra effort.

If you want to generate a 0 Hz output the proper command is:  digitalWrite(21, HIGH);   :)
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Thank you John.

In fact I don't want zero Hertz. I was just amazed by the fact that tone() didn't work as described. In fact, integer multiples of 60Hz are great.

Best regards,



I think the lowest possible frequency is 30.517578125 Hz  (16 MHz clock / 1024 prescaler / 256 counts of the 8-bit timer / 2 because it toggles).  I don't know what to expect for frequencies below that.

If you set up Timer1 (a 16-bit timer) the frequencies could go much lower.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Yes, you are correct. The frequencies of tone() are multiples of 30.5 Hz, not 60 Hz as I stated before. Thanks for the explanation.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131