Piezo is making a soft sound after having played a tone() - how can I stop it?

Hi

I connected a piezo speaker to a ATMEGA32U4 (pin 9). The other piezo-pin goes to ground

When I power up the board, the piezo is completely quiet. I then play a tone using tone(9,500,1000);. After having played the tone (and also after having executed noTone(9)), there is a soft hissing noise coming from the speaker.

Does anyone have any idea how to stop the noise?

Thank you,
Dani

1 Like

Is there a measurable voltage?

Post your sketch.

I suspect this. When the sketch first powers up, all pins are in INPUT mode. This high Z input impedance causes there to be no current flow through the speaker, causing absolutely no noise.

When tone() is run, the pin is forced to OUTPUT. After noTone(), the pin is still OUTPUT, but written LOW. This is a low impedance output that can cause some currents and noise to flow.

After noTone(), try setting the pin to INPUT and see what happens.

After noTone(), try setting the pin to INPUT and see what happens.

Yes, or write a logic LOW to the pin after the noTone.

Grumpy_Mike:

After noTone(), try setting the pin to INPUT and see what happens.

Yes, or write a logic LOW to the pin after the noTone.

noTone() already does that.

void noTone(uint8_t _pin)
{
  int8_t _timer = -1;
  
  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
    if (tone_pins[i] == _pin) {
      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
      tone_pins[i] = 255;
    }
  }
  
  disableTimer(_timer);

  digitalWrite(_pin, 0);
}

Hi,

I faced this buzzer hissing sound even after a call to noTone(pin);
The module was getting hot.

I figured out the buzzer module control pin is active low.

the inbuilt noTone() code is:

void noTone(uint8_t _pin)
{
int8_t _timer = -1;

for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
  if (tone_pins[i] == _pin) {
    _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
    tone_pins[i] = 255;
  }
}

disableTimer(_timer);

digitalWrite(_pin, 0);
}

According to this code the buzzer control is made low, which is active in this buzzer module.

The solution would be to call digitalWrite(pin, HIGH);

This stopped the hissing sound and no heating of the buzzer module.

@ eatcircuits: you have a buzzer module, this thread is about a bare piezo element I believe.

@ local_dani_21: #2 is the reply to try first - you are hearing supply rail noise I think.