Creating sound with Sine Wave on Arduino UNO board

Hi

I want to create sound for specific durations but I want the wave sound to be sine wave.

tone() function creates sound with square wave but I want sound with sine wave

In fact, I want something that create sound like the code below but with sine wave:

tone(11, 3000)
delay(1000)
noTone(11)
delay(2000)

Hello fvfar,

do you need an audio tone or a low-frequency signal ?

If you need a low-frequency, then you can use the PWM outputs followed by a low pass filter. Basically, you can generate any waveform from a PWM signal, as long as you follow two conditions :

  • the PWM signal must be low-pass filtered
  • the PWM signal frequency must be at least 50 times greater than the reconstructed signal, if you want to have a good quality

If you want directly an audio signal, then you must add an external DAC. The easiest solution is a SPI DAC, but you can also use a parallel DAC, connected directly to I/O pins (you will need probably a Mega Arduino, to have enough I/O pins, everything depends on the resolution you want). In this case, you will probably also need to deal with direct port access of the AVR (using the PORTx registers) to have the best possible value.

To generate the sinus, the easiest solution is a wavetable filled with the sinus samples (you can replace it with any waveshape) read at sampling frequency speed. This cost nothing in term of CPU power and you can easily deal with audio rate sampling

Benoit

Thank you for your response.
I have already read Arduino DDS Sinewave Generator - Audio - Arduino Forum
but my problem is that how turn on and off the sound repeatedly

but my problem is that how turn on and off the sound repeatedly

Disable the interrupts to turn it off, enable them to turn it on.