Zac
Zac

Reputation: 3

Arduino whooping siren sound

I am trying to make an alarm system using Arduino. I would like to have the siren connected to the system be able to output two different types of sounds. A low "beep beep" kind of sound which I know how to do, but I can't figure out how to get the Arduino to emit a "whoop whoop" sound using the tone command or a variant of the tone command or a similar command.

Also on this topic, how would I go about driving a higher power siren/horn using an Arduino? Can I do so using a mosfet transistor the same way I would drive a 12v led?

Any help is greatly appreciated. Thanks :-)

EDIT:

This is my main loop that emits the noise:

void loop() {
  int i = 200; // The starting pitch
  while(i < 800) {
    i++;
    tone(buzzer, i); // Emit the noise
    delay(5);
  }
  delay(100); // A short break in between each whoop
}

Every time the noise emits it make a few (about 3-4) small 'crackles', like distortion. Its not really noticeable with a small piezo directly connected to the Arduino but I suspect when I use a larger sounder and an amplifier it will be more noticeable.

Upvotes: 0

Views: 10597

Answers (2)

Goirik Dhar
Goirik Dhar

Reputation: 1

A little modification Thunderbolt 1003 Alternate wail siren. Arduino code ;)

#define speakerPin 11
void setup()
{
  pinMode(speakerPin,OUTPUT);
}
void loop()
{
  // Whoop up
  for(int hz = 300; hz < 1000; hz++)
  {
    if((hz/100)%2)
    tone(speakerPin, hz, 50);
    else
    tone(speakerPin, hz+150, 50);
    delay(6);
  }
  noTone(speakerPin);

  // Whoop down
  for(int hz = 1000; hz > 300; hz--){
    if(!((hz/100)%2))
    tone(speakerPin, hz, 50);
    else
    tone(speakerPin, hz+150, 50);
    delay(6);
  }
 noTone(speakerPin);
} // Repeat

Upvotes: 0

codeflight
codeflight

Reputation: 41

I made some code for this for an April fools joke and here it is:

void loop {
  // Whoop up
  for(int hz = 440; hz < 1000; hz++){
    tone(speakerPin, hz, 50);
    delay(5);
  }
  noTone(speakerPin);

  // Whoop down
  for(int hz = 1000; hz > 440; hz--){
    tone(speakerPin, hz, 50);
    delay(5);
  }
  noTone(speakerPin);
} // Repeat

Where speakerPin is the pin connected to your speaker.

Hope this helps.

Upvotes: 4

Related Questions