Simple 400Hz generator for 20 sec on and 29 sec off

Hi,

Looking for a simple generator that generates 400Hz for 20sec on and 20sec off.

It must drive a 0.5W speaker.

Must admit I only searched for 10min, but hopefully someone have a quick solutions.

Thank

Waveform?

The Arduino tone function

and some kind of amplifier

google for another ten and you’ll be there.

a7

void loop()
{
  tone(SpeakerPin, 400, 20000ul); // 20 seconds on
  delay(29000ul); // 29 seconds off
}
1 Like

Thanks

int buzzer=7; //connecting buzzer to pin 7
void setup()
{
pinMode(buzzer,OUTPUT); //setting up buzzer pin as output
}
void loop()
{
int i;
for(i = 1; i < 20; i++){
tone(buzzer,400,100); //freq 1000 Hz,delay 100 ms
delay(1000);}
delay(20000);
}

You can simply combine the tone() function and the Blink Example.

Note that the regular Arduinos don't have a true analog output so tone() puts-out a square wave.

The Arduino can't put-out enough current to directly drive a 4 or 8-Ohm speaker. The minimum resistance/impedance is 125 Ohms so you need an amplifier.

Or, you can put a (approx) 120-Ohm resistor in series. (A series resistor will greatly cut-down the volume but you should still be able to hear it.)

Amplifier options -
Regular "powered" computer speakers will work.

...If you have amplified/powered computer speakers handy that's a good way to test your Arduino & software before you build any hardware.

You can buy a small amplifier (example).

You can buy a small amplifier board (example).

You can build your own amplifier from a chip (The LM386 is a popular, easy to use, low-power amplifier chip.)

1 Like

Thanks,

The square wave output is 100%, no need for a sin wave.

I will add the 120-ohm as I actually don't want the output audible for human.

What is the max Hz for the tone?

65535 Hz?

"After all is said and done, because play() only accepts unsigned integers for frequency, the maximum frequency that can be produced is 65535 Hz - which, after rounding, results in a 65573.77 Hz "tone" on a 16 MHz part. Even if play accepted larger values for frequency, you couldn't achieve better than around 80KHz with the Tone library because the pin toggling is done in software. Each toggle, in software, requires AT LEAST 50+ cycles."

1 Like

This is for a pest control project.

Gofers , molls need around 400Hz and rodents don't like 30kHz to 50kHz.

So a Uno or the like will be suitable for the project.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.