Go Down

Topic: Piezo is making a soft sound after having played a tone() - how can I stop it? (Read 3585 times) previous topic - next topic

local_dani_21

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

robtillaart

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Jiggy-Ninja

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.
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

Grumpy_Mike

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

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

Jiggy-Ninja


Quote
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.
Code: [Select]
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);
}
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

eatcircuits

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:

Code: [Select]
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.

MarkT

@ 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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up