help using peizo buzzer

having troble with my buzzer. cant get it to make some decent noise. made a video as it was easier

https://www.youtube.com/watch?v=d5RKsvLv67o

//    FILE: start lights
//  AUTHOR: Josh Sams
// VERSION: 0.1.00
// PURPOSE: RC race start lights
// DATE:29/01/2015
//
// COPYRIGHT: Released to the public domain for non profit use only. (copyright: JCStech 2015)
//


#define LEDRED 9   //pin to turn on RED led
#define LEDORANGEA 8    //pin to turn on ORANGE led A
#define LEDORANGEB 7   //pin to turn on ORANGE led B
#define LEDORANGEC 6   //pin to turn on ORANGE led C
#define LEDGREEN 5    //pin to turn on the 
#define RESET 10   //pin to read reset button
#define GO 11     //pin to read START

#define BUZZ A0



int val = 0;
unsigned long TIME;



void setup() 
{
  pinMode(LEDRED, OUTPUT);
  pinMode(LEDORANGEA, OUTPUT);
  pinMode(LEDORANGEB, OUTPUT);
  pinMode(LEDORANGEC, OUTPUT);
  pinMode(LEDGREEN, OUTPUT);


  pinMode(RESET, INPUT);
  pinMode(GO, INPUT);


  delay(800);
  digitalWrite(LEDGREEN, HIGH);
  tone(BUZZ, 1500, 200);
  delay(250);
  digitalWrite(BUZZ, LOW);
  delay(250);
  digitalWrite(LEDGREEN, LOW);
  digitalWrite(LEDORANGEC, HIGH);
  tone(BUZZ, 1500, 200);
 delay(250);
  digitalWrite(BUZZ, LOW);
  delay(250);
  digitalWrite(LEDORANGEC, LOW);
  digitalWrite(LEDORANGEB, HIGH);
  tone(BUZZ, 1500, 200);
   delay(250);
  digitalWrite(BUZZ, LOW);
  delay(250);
  digitalWrite(LEDORANGEB, LOW);
  digitalWrite(LEDORANGEA, HIGH);
  tone(BUZZ, 1500, 200);
   delay(250);
  digitalWrite(BUZZ, LOW);
  delay(250);
  digitalWrite(LEDORANGEA, LOW);
  digitalWrite(LEDRED, HIGH);
  tone(BUZZ, 1500, 200);
   delay(250);
  digitalWrite(BUZZ, LOW);



}
void loop(){    

 delay(1000);
   

    
}   
//END OF FILE

If I can recall correctly, the ‘trick’ with the piezo was to be able to pull the live side back down to ground very quickly. If I understand it correctly, the piezo disk only makes a sound while it is being energised ( ie. moving from 0 to Vcc ). After that, you need to pull it back to Gnd and re-energise it again - all very fast.

I found the solution for the piezo horn I was using was two part :

  1. used the toneAC library, which is able to alternate the current to the piezo. So instead of waiting for the piezo disk to return to the ground state, it would be pushed from both sides. Kind of like batting a ping pong ball up into the air, and waiting for it to fall back down, compared to batting it up so it hits the ceiling and it returns a lot faster.

  2. because my piezo was rated up to 35V, I used a SN754410 QUADRUPLE HALF-H DRIVER to do the driving in both directions. Depending on the current, you may be able to drive yours from the Arduino pins, but I am no expert on that - don’t take my word for it.

Volume was greatly increased with the Driver chip.

You should find the samples in the library folder.
The one I can find was this code :

// ---------------------------------------------------------------------------
// Connect your piezo buzzer (without internal oscillator) or speaker to these pins:
//   Pins  9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc.
//   Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega
//   Pins 12 & 13 - ATmega1284P, ATmega644
//   Pins 14 & 15 - Teensy 2.0
//   Pins 25 & 26 - Teensy++ 2.0
// Be sure to include an inline 100 ohm resistor on one pin as you normally do when connecting a piezo or speaker.
// ---------------------------------------------------------------------------

#include <toneAC.h>

// Melody liberated from the toneMelody Arduino example sketch by Tom Igoe.
int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 };
int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 };

void setup() {} // Nothing to setup, just start playing!

void loop() {
  for (unsigned long freq = 125; freq <= 15000; freq += 10) {  
    toneAC(freq); // Play the frequency (125 Hz to 15 kHz sweep in 10 Hz steps).
    delay(1);     // Wait 1 ms so you can hear it.
  }
  toneAC(); // Turn off toneAC, can also use noToneAC().

  delay(1000); // Wait a second.

  for (int thisNote = 0; thisNote < 8; thisNote++) {
    int noteDuration = 1000/noteDurations[thisNote];
    toneAC(melody[thisNote], 10, noteDuration, true); // Play thisNote at full volume for noteDuration in the background.
    delay(noteDuration * 4 / 3); // Wait while the tone plays in the background, plus another 33% delay between notes.
  }

  while(1); // Stop (so it doesn't repeat forever driving you crazy--you're welcome).
}

I can't watch the video right now.

If it is a bare piezo element that requires a driving AC signal, it is typically called a piezo transducer, or piezo speaker.

If it contains the circuitry to generate the beep and you need only supply it with 5V, it is called a piezo buzzer.

Even better is if you make sure and tell us which one it is. As DaveO says, a piezo speaker must be supplied with an AC signal or it'll only make a "click".

Can you make it play the Star Spangled Banner ?

raschemmel: Can you make it play the Star Spangled Banner ?

As DaveO is in S. Africa and I'm in the UK, why would we even want to do that?

not getting into the blatantly obvious trap of discussing the choice of tune requested, but I did come across code to play tunes with a piezo buzzer.

http://forum.arduino.cc/index.php?topic=8409.5;wap2

If you have the music knowledge or find the notes required, you can make it play anything you want.

You removed the resistor? What do you think it was for? How do you know that removing it makes it louder?

That was not a piezo, that is a little electromagnetic speaker. The transistor is a driver transistor, and the resistor is base current limiting.

You’ve probably burnt out the transistor, and possibly damaged a pin on your Arduino. The fact that the PCB for the sounder is getting warm is a huge clue!

Is that 0.21mA, or 0.21A? I find it hard to believe an entire Nano is running from 40uA, and find it much more likely that the Nano is using 40mA, and the sounder board is drawing an additional 170mA. It is not going to heat up from 170uA. And why did you wait so long in the video to mention this?

The one you’ve replaced it with is probably a piezo, and won’t work with just a single driver transistor. Signal is obviously getting through, but without a schematic I have no idea how you’ve wired it up.

For instance, do you have current limiting resistors on your LEDs? I notice it is loudest when the blue LED is lit up. Blue LEDs drop more voltage. If your LEDs are dragging the 5V line down, it makes sense that the sound would be weakest when lower voltage LEDs are lit up.

You should give all the details in your question. If you force people to watch a video to figure out all you’ve done, they are less likely to respond. The video is a good thing, don’t get me wrong. Just don’t be so sparse in the details in your post.

It is a very bad habit, plugging and unplugging with power applied.

I also strongly recommend you stop now, stop using delay to time things. Look into using millis() for timing. Check out the "BlinkWithoutDelay" sketch in the examples folder of your Arduino software.

It is one of my pet peeves that so many books (most of them) never stop using delay() for timing. It is like teaching someone to drive by using the emergency brake to control speed.

polymorph: I also strongly recommend you stop now, stop using delay to time things. Look into using millis() for timing. Check out the "BlinkWithoutDelay" sketch in the examples folder of your Arduino software.

It is one of my pet peeves that so many books (most of them) never stop using delay() for timing. It is like teaching someone to drive by using the emergency brake to control speed.

it letrely times one thing! why would i bother with all the extra code when it makes no difference whatsoever!

polymorph: You removed the resistor? What do you think it was for? How do you know that removing it makes it louder?

That was not a piezo, that is a little electromagnetic speaker. The transistor is a driver transistor, and the resistor is base current limiting.

You've probably burnt out the transistor, and possibly damaged a pin on your Arduino. The fact that the PCB for the sounder is getting warm is a huge clue!

Is that 0.21mA, or 0.21A? I find it hard to believe an entire Nano is running from 40uA, and find it much more likely that the Nano is using 40mA, and the sounder board is drawing an additional 170mA. It is not going to heat up from 170uA. And why did you wait so long in the video to mention this?

The one you've replaced it with is probably a piezo, and won't work with just a single driver transistor. Signal is obviously getting through, but without a schematic I have no idea how you've wired it up.

For instance, do you have current limiting resistors on your LEDs? I notice it is loudest when the blue LED is lit up. Blue LEDs drop more voltage. If your LEDs are dragging the 5V line down, it makes sense that the sound would be weakest when lower voltage LEDs are lit up.

You should give all the details in your question. If you force people to watch a video to figure out all you've done, they are less likely to respond. The video is a good thing, don't get me wrong. Just don't be so sparse in the details in your post.

It is a very bad habit, plugging and unplugging with power applied.

you like a moan dont you! i dont think you payed much attention ether

i dont know the resistor makers it louder but it may have stoped the transistor from working properly

im pritty sure its a piezo.

sorry 21ma and 4ma without the buzzer

no droping resistors. was told the arduino can only put out a certain current so direct leds will be fine

DaveO:
If I can recall correctly, the ‘trick’ with the piezo was to be able to pull the live side back down to ground very quickly. If I understand it correctly, the piezo disk only makes a sound while it is being energised ( ie. moving from 0 to Vcc ). After that, you need to pull it back to Gnd and re-energise it again - all very fast.

I found the solution for the piezo horn I was using was two part :

  1. used the toneAC library, which is able to alternate the current to the piezo. So instead of waiting for the piezo disk to return to the ground state, it would be pushed from both sides. Kind of like batting a ping pong ball up into the air, and waiting for it to fall back down, compared to batting it up so it hits the ceiling and it returns a lot faster.

  2. because my piezo was rated up to 35V, I used a SN754410 QUADRUPLE HALF-H DRIVER to do the driving in both directions. Depending on the current, you may be able to drive yours from the Arduino pins, but I am no expert on that - don’t take my word for it.

Volume was greatly increased with the Driver chip.

You should find the samples in the library folder.
The one I can find was this code :

// ---------------------------------------------------------------------------

// Connect your piezo buzzer (without internal oscillator) or speaker to these pins:
//  Pins  9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc.
//  Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega
//  Pins 12 & 13 - ATmega1284P, ATmega644
//  Pins 14 & 15 - Teensy 2.0
//  Pins 25 & 26 - Teensy++ 2.0
// Be sure to include an inline 100 ohm resistor on one pin as you normally do when connecting a piezo or speaker.
// ---------------------------------------------------------------------------

#include <toneAC.h>

// Melody liberated from the toneMelody Arduino example sketch by Tom Igoe.
int melody = { 262, 196, 196, 220, 196, 0, 247, 262 };
int noteDurations = { 4, 8, 8, 4, 4, 4, 4, 4 };

void setup() {} // Nothing to setup, just start playing!

void loop() {
  for (unsigned long freq = 125; freq <= 15000; freq += 10) { 
    toneAC(freq); // Play the frequency (125 Hz to 15 kHz sweep in 10 Hz steps).
    delay(1);    // Wait 1 ms so you can hear it.
  }
  toneAC(); // Turn off toneAC, can also use noToneAC().

delay(1000); // Wait a second.

for (int thisNote = 0; thisNote < 8; thisNote++) {
    int noteDuration = 1000/noteDurations[thisNote];
    toneAC(melody[thisNote], 10, noteDuration, true); // Play thisNote at full volume for noteDuration in the background.
    delay(noteDuration * 4 / 3); // Wait while the tone plays in the background, plus another 33% delay between notes.
  }

while(1); // Stop (so it doesn’t repeat forever driving you crazy–you’re welcome).
}

thanks daveo
great info there

i couldnt actualy find cheep passive piezos so iv got myself some self driven ones in the post. if they still too quite ill go get a driver chip :slight_smile:

I don't want to bother you with my "moaning", so feel free to help yourself.