Is there any way to make sounds using an Arduino without using the tone function?
It must be possible via this new method to control frequency of sound.

  • Do you want "sounds" or do you want "notes"? Apr 19 '15 at 14:36
  • I'm not sure, but does analogWrite(200); make a sound for you?
    – Paul
    Apr 19 '15 at 15:06
  • 2
    Why would you want to? Pretty much the only way, is to create a 50% duty cycle PWM at a certain frequency. And that is exactly what tone does. If you are interested in how it does that, you can look at the source code (github.com/arduino/Arduino/blob/master/hardware/arduino/avr/…)
    – Gerben
    Apr 19 '15 at 18:22
  • 1
    @Gerben reasons not to use tone: timer clash with other libraries; (apparently) increased code size; and potentially just to understand and explore the low level engineering Jul 5 '15 at 0:59

I've used a somewhat more complex method with some success, which uses 2 timers to play 8kHz sampled audio. The idea is that one of the timers runs at 8kHz to determine the PWM duty cycle of the other, which runs at as fast a frequency as possible.

While the original code uses a short stored sample (On an Arduino, you could store maybe 3 seconds of audio that way), my usages involved computing the audio on the fly by overlapping several sine waves or using table lookups with varying strides. As long as computation is kept simple, this just barely works.

  • You wrote that? Thanks!! That helped me so much a few months ago!
    – NobodyNada
    Apr 20 '15 at 14:52
  • To clarify: I did not write the code on arduino.cc, but I used a modified version of it in some projects of my own. Apr 22 '15 at 17:20

Thanks a lot, but anyway, I got an answer myself.
I can use the simple delaymicroseconds( ) .
Also, I can use timer interrupts to do basically the same thing
And these are a lot less complicated than the other answers I got.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.