# How to generate a sine wave 88 Hz

Hi,

I would like to make a cine wave of 88 Hz.

Can someone help me ?

There is a [u]sin()[/u] function so the software is easy (note that it used radians rather than degrees).

Of course, you'll need a time reference (sample rate). If you don't know what I'm talking about, the Audacity website has little [u]tutorial[/u] showing how an analog signal is sampled in time, then re-constructed by "connecting the dots". (You don't need to sample (analog-to-digital) because you are generating the waveform in software, but you need to understand timing is important in digital-to-analog conversion.)

BUT.... Unless you're using an Arduno Due, the Arduino doesn't have an analog output. You can approximate an analog output with PWM ( [u]analogWrite()[/u] ) and a low pass filter, but you'll probably need to increase the PWM frequency to get a good result at 88 Hz.

Note that the Arduino can't put-out a negative voltage, so you'll need to bias/offset the output, and then you can filter-out the DC bias with a capacitor to get an AC waveform that goes negative.

P.S. If you don't need a "hardware box" that generates 88Hz, Audacity can generate a WAV or MP3 file that you can play on your computer or MP3 player, etc.

I have already seen ,the site Grumpy_Mike referred, but I did not understood much…

I would like an easy way to generate this sine using arduino uno and not due as this is a part of one project I already run.

I suppose that 88 Hz is not too fast as a frequency and it can be produced relatively easy using only arduino uno, just using a pwm pin but I am not sure how to do this.

I know that the Arduino can't put-out a negative voltage but this is not a problem for me as I do not have a problem the sine to be generated between 0 and 5 volt (2.5 V to be the 0 point).

Also I know that pwm will give square picks but this is something I can fix using a filter.

What I just want is to produce this square sine.

I have already seen ,the site Grumpy_Mike referred, but I did not understood much…

Who's fault is that?

I would like an easy way to generate this sine using arduino uno and not due as this is a part of one project I already run.

This is an easy way, it does exactly what you want. There are no easier ways of doing this.

What I just want is to produce this square sine.

Yes we know and we are telling you how.

If you want the same technique explained by me then I do it in this book:- http://www.apress.com/9781484217207

However it is basically the same technique. I understand you can get the book as an eBook at the moment.

Alternative say what bits of that page you do not understand and we will try to make it more clear, but this is the technique to use.

This is an excellent source with a working sketch.

charliesixpack: This is an excellent source with a working sketch.

charliesixpack, Thank you ! I test it yesterday and it works perfect ! I would like to make you another question ! How can I stop producing this sine when I want, and how to start producing it again ?

How can I stop producing this sine when I want, and how to start producing it again ?

There are several ways to do this.

You can turn off the output pin by changing the pinMode from output to input. And change it back to output to start again.

Or, you can turn off the underlying timer by setting all the prescaler values to 0. You have set it up this way

``````// Clock prescaler = 1
sbi (TCCR2B, CS20);      // 001 = no prescaling
cbi (TCCR2B, CS21);
cbi (TCCR2B, CS22);
``````

You will be able to turn the time off and on with

``````cbi (TCCR2B, CS20);//will turn timer off
sbi (TCCR2B, CS20);//will turn it back on
``````

Thank you cattledog !

That was exactly what I needed !

I know I'm digging an and oldie, but could you tell me how to use the following code to turn the time on/off on a specific delay?

For example, I would like to play the sine wave for 6 seconds, and off for 6 seconds, rinse and repeat.

Is this possible?

cattledog: There are several ways to do this.

You can turn off the output pin by changing the pinMode from output to input. And change it back to output to start again.

Or, you can turn off the underlying timer by setting all the prescaler values to 0. You have set it up this way

``````// Clock prescaler = 1
sbi (TCCR2B, CS20);      // 001 = no prescaling
cbi (TCCR2B, CS21);
cbi (TCCR2B, CS22);
``````

You will be able to turn the time off and on with

``````cbi (TCCR2B, CS20);//will turn timer off
sbi (TCCR2B, CS20);//will turn it back on
``````

For example, I would like to play the sine wave for 6 seconds, and off for 6 seconds, rinse and repeat. Is this possible?

Yes. Look at the 'blink without delay" example in the ide at File>examples>02.Digital>BlinkWithoutDelay

Instead of turning the led on and off turn the timer on and off. Instead of doing it every second, do it every six seconds.

For more information on millis() based timers see http://forum.arduino.cc/index.php?topic=223286.0 and http://forum.arduino.cc/index.php?topic=503368.0