Inconsisten sounds pitch on a buzzer.

Short version

What can cause a buzzer to produce a different sound with the exact same tone() call?

Longer version

I have a buzzer like this one:

I honestly have no idea of the exact characteristics of it, I salvaged it from something but I don't remember what.

What I do know is that it uses very little current, in the order of 3 mA compared to the 20 mA or so (depending on resistors) I get from other buzzers I have laying around... So I like it a lot. :slight_smile:

But the thing is, it produces an inconsistent pitch and I was wondering if it's about to die or I'm doing something wrong... And since I'm completely ignorant about these things (i know there are different kinds of buzzers), I thought I'd ask.

The buzzer is connected to pin 11 on a Nano, via a 100 ohm resistor, and then ground obliviously, and the code to make it work is this:

void SonarAlarma() {
  for (byte i = 1; i <= 3; i++) {
    for (byte j = 1; j <= 2; j++) {
      tone(PINBUZZER, 440);
      delay(200);
      noTone(PINBUZZER);
      delay(200);
    }
    delay(200);
  }
}

So beep-beep... beep-beep... beep-beep.

Now here's the thing. It sometimes makes a different beeping sound, one or two of those tone(PINBUZZER, 440) make a lower pitch beep. :frowning:

So that's the question... what might be going on here? :smiley: I really absolutely and positively would hate my life if after assembly I have to go and change the buzzer because it died. :frowning:

(not a rhetorical question)

Are buzzers supposed to be fed a "tone?"

I always thought a buzzer was just something you supplied steady DC to and it buzzed at whatever frequency it was designed to buzz at. With that in mind, I sort of wouldn't be surprised if a buzzer didn't like being fed a square wave or something else. Perhaps its internal oscillator and the tone you're feeding it are interfering in unpredictable ways.

What I understand is that there are two types of buzzers/piezos, those that take a PWM and those that don't.

I don't know how to check which one I have. It does change pitch if I change the parameter to tone(), so there's that. :slight_smile:

What happens if you feed it dc?

Allan

hmmm... you mean just 5v straight from a pin? I'll try later when I get home.