1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Buzzer/Speaker...What's the diff?

Discussion in 'Microcontrollers' started by Urahara, Jul 26, 2008.

  1. Urahara

    Urahara Member

    Joined:
    Jun 9, 2008
    Messages:
    157
    Likes:
    0
    Hi

    This may be a basic question, but I guess I am still new to all this.

    What I want to do is to produce a beep, a sound quite similar to those produced on a PC when u press, say, a wrong key. I believe I hv a piezzo buzzer and do not seem to be able to produce such a sound.

    Is there a difference btw a buzzer and a speaker for me to produce such a sound? I just wanted something that you can connect directly to the pin of the uC and if not possible, at least as few components as possible and importantly, does not consume a lot of power, as I am trying to see if it works with a battery-operated project.

    Thks!
     
  2. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,180
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    This question is often asked.

    The piezo sounder requires a square wave drive signal to produce a sound.
    The output of a 555 timer can be used as a driver.
    You can drive a small speaker from a 555, using ac coupling and a suitable speaker.

    There are 'tone sounders' that just require a dc voltage,, say 3V thru 15V, to produce a tone.
     
    Last edited: Jul 26, 2008
  3. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    Piezo beepers take very little current to drive. They're very high impedance and can be driven directly by a MCU pin. Pulse the pin at different rates to make different pitches of beep. The beeper will be loudest at its resonant frequencies.

    You can also drive a piezo with a transistor or other method. With more power it'll be louder.

    Here's a simple C function to drive a piezo transducer on pin C13 of a dsPIC30F4013. Very easily modified to work on any MCU:
    Code (text):
    #define piezo   _LATC13

    void beep(int tone)
    {
        int x,y;
        for(x=0;x<80;x++)
        {
            piezo = 1;
            for(y=0;y<tone;y++){}
            piezo = 0;
            for(y=0;y<tone;y++){}
        }
    }  
     
    A buzzer, on the other hand, just needs power to make noise. But you can't control the frequency of the sound it generates. It's fixed.

    Here a couple links:
    http://www.picbasic.co.uk/forum/showthread.php?t=3076
    http://www.maxim-ic.com/appnotes.cfm/an_pk/988
     
    Last edited: Jul 27, 2008
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Hero999

    Hero999 Banned

    Joined:
    Apr 6, 2006
    Messages:
    14,902
    Likes:
    79
    Location:
    England

    I would say if you're using a microcontroller, go for a unit without a built in driver as they're cheaper and it's easy to put a squarewave on an I/O pin.

    If you're using logic ICs, transistors, a 555 timer or just a switch, then you're better off with a buzzer which has a built in driver rather than building your own oscillator.
     
  6. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    A piezo disc has a resonant frequency usually between 1 and 6khz, generally in the 1-3 range. You can test them on a PC sound card by sending a sine wave of increasing frequency until the tone is the loudest. The sound is pretty weak from line out voltages but you should still be able to peg the resonant frequency. Creating a 5 volt square wave to feed the buzzer will work but they're often rated for peak to peak voltages up to 20 volts if you really want some volume.
     
  7. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    You can drive a common speaker like that found on a PC from a uC pin. All you need is a 47uF capacitor between the pin and the speaker. Pin to + on cap - on cap to speaker other speaker terminal to ground.

    It will not draw any power when it is not is use. You can generate the desired frequency using a delay loop, timer, or PWM.

    I pull old speakers from PC's and hot melt glue an axial cap to the speaker magnet. You can even reuse the wires and connector that come with it.
     
  8. Hero999

    Hero999 Banned

    Joined:
    Apr 6, 2006
    Messages:
    14,902
    Likes:
    79
    Location:
    England
    That's a good test but it does get skewed by the response of the human hearing.

    A better idea would be to use two transducers, one transmitter and a receiver connected to a scope.
     
  9. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,213
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    Connect them across two PIC pins, you can feed it with 10V p-p then - I modified an EPE project to do just that, the original only used a single pin and feed it with 5V. One clever point was that they used a frequency sweep to drive the piezo, this ensure it hit the resonant frequency of the piezo.

    My simple (no components used) bridge modification provided four times the power :D
     
  10. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    Hero, he stated his intent was to create a simple beep much like a PC speaker so testing against human hearing response is exactly what he wants to do.

    Nigel I've heard of that bridging piezos/speakers on an UC pin before but exactly how to does it work? How do you get the 10V P-P from only 5V and ground?
     
  11. Hero999

    Hero999 Banned

    Joined:
    Apr 6, 2006
    Messages:
    14,902
    Likes:
    79
    Location:
    England
    Easy, one pin is pulsed anti-phase with the other pin, thus doubling the votage and quadrupling the power.

    There'a no magic involved one pin to 0V gives a p-p voltage of 5V and two pins anti-phase with each other gives a p-p of 10V between them.
     
  12. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    There must be a concept here I do not understand 0 to 5V is always 5V. 5V to -5V is 10V. What am I missing. Do not understand understand how being 180 out of phase would do that ?
     
    Last edited: Jul 27, 2008
  13. saturn1bguy

    saturn1bguy New Member

    Joined:
    Nov 12, 2007
    Messages:
    360
    Likes:
    1
    Location:
    Great Salt Lake
    A charge-pump or voltage doubler: stack two caps, each one gets charged with 5V, netting 10V.

    But perhaps they're speaking of something else...
     
    Last edited: Jul 27, 2008
  14. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    Imagine you are sitting on one of the pins.

    To you, the other pin's voltage is changing from +5V to -5V, so to you only, the change is +/-5V so equals 10V pk-pk. If a device is driven by these two pins, its too will see 10V pk-pk.
     
  15. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    :)
    That does makes sense. The other pin looks like -5 to me when I am +5 and it is 0. The speaker is being driven the other way. About twice the cone displacement. Got it

    To use this I would have to either give up on the capacitor used for AC coupling or maybe use two with diodes to keep them out of the circuit when the current was reverse to the cap polarity?

    This may also make the speaker sound a bit different. With the 1 pin setup the cone is either pushed or pulled, with this it will be driven both ways. Not a big thing just curious.
     
  16. Urahara

    Urahara Member

    Joined:
    Jun 9, 2008
    Messages:
    157
    Likes:
    0
    Hi

    Did some tests with different parameters to test out the tones with the codes below. Would like to share my observations and hear your comments. The thing with hearing sound is, after a while, they all seem to be quite the same and inconsistencies begin to appear. Perhaps someone can give, at least the theoretical aspects of what each parameter should adjust, since I may be one of those quintessential tone-deafness :D sufferer!!

    Code (text):

    #include <p18f4550.h>
    #include <delays.h>
    #pragma config FOSC = HS
    #pragma config PWRT = OFF
    #pragma config WDT = OFF
    #pragma config MCLRE = ON
    #pragma config PBADEN = OFF
    #pragma config LVP = OFF

    void init(void);
    void PWM(unsigned char i);

    // Initial
    void init(void)
    {
        CMCON=0b00000111; // Close Comparator
        TRISA=0b00010000;
        TRISB=0b00000001;
        TRISC=0b00000000;
        TRISD=0b00000000;
        TRISE=0b00001000;
        ADCON1=0b00001111; // Configure Digital Channel

        CCP1CON=0b00001100;
    }

    // Set PWM Mode
    void PWM(unsigned char i)
    {
        CCPR1L = 25*i;         
    }
     
    // Main Programmer
    void main( void )
    {
        unsigned char i;

        init();

    //test1
    // Sound 1
    /*  T2CONbits.TMR2ON = 0; //0=timer2 is off, 1=timer2 is on
        T2CONbits.T2OUTPS3 = 1;
        T2CONbits.T2OUTPS2 = 1;
        T2CONbits.T2OUTPS1 = 1;
        T2CONbits.T2OUTPS0 = 1;
        T2CONbits.T2CKPS1 = 1;
        T2CONbits.T2CKPS0 = 1;
        PR2 = 255;         
        TRISCbits.TRISC2=0;     // set RC2 (buzzer) port an output
        T2CONbits.TMR2ON = 1;
        for (i=0;i<2;i++)
        {
            PWM(4);
            Delay1KTCYx(150);
            PWM(0);
            Delay1KTCYx(150);
        }
    }
     

    Played with the following parameters to create "different" sounds:
    1. Sound A : Pre-scaler=11, Post-scaler=1111, PR=255, CCPR1L=4*25
    2. Sound B : Pre-scaler=00, Post-scaler=0000, PR=255, CCPR1L=4*25
    3. Sound C : Same as Sound A except different CCPR1L=8*25
    4. Sound D : Same as Sound B except different CCPR1L=8*25
    5. Sound E : Same as Sound A except different PR=30
    6. Sound F : Same as Sound B except different PR=30

    My observations as follows when I compare the sounds :
    a. Sound A vs Sound B : Sound A has higher tone
    b. Sound A vs Sound C : Same tone, but sound C is louder
    c. Sound B vs Sound D : Same tone, but sound D is louder
    d. Sound A vs Sound E : Sound A has higher tone, Sound E is louder
    e. Sound B vs Sound F : Sound F has higher tone and is louder

    Preliminary conclusions :
    i) Pre & Post scaler affects tone.
    ii) CCPR1L affects loudness
    iii) Am not sure abt PR though...perhaps my tone-deafness kicks in by then.
     
  17. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,213
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    It's a VERY comon technique called 'bridging', almost all car radios use it these days.

    Having a capacitor in series makes no difference whatsoever, it's an AC signal, so passes through regardless - but it does give the advantage that you don't require a capacitor.

    No different at all, unless you don't have a capacitor on the single ended method, where the cone only moves one way - with bridging, or single ended with a capacitor, the cone moves both ways as it should.
     
  18. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Thanks Nigel.

    Without a cap the speaker will need a current limiting resistor. To limit it to 25mA that would be 200 Ohms less the speaker impediance.

    For anyone wanting to try this. The quality of the speaker has a huge impact on what comes out of it. The ones removed from a PC are fun to play with but they are or very poor quality.
     
  19. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,213
    Likes:
    640
    Location:
    Derbyshire, UK
    ONLINE
    If you don't need a resistor when you have a capacitor, then you don't really need one without either - although bridging does effectively feed each half of the speakers impedance from each pin.

    But for an occasional beep or two, it's not likely to be a problem - and for piezos it's no problem at all of course.
     
  20. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,180
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    Last edited: Jul 28, 2008
  21. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    There's no need to use a coupling capacitor on a speaker if you're just producing a single tone. I've seen many projects that use a speaker directly on an I/O pin.
     

Share This Page