This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to connect a buzzer to MSP430 without fear of damage it.

Hello,

I want to get alarm sound from my solution. Solution use battery CR 2032 as a power supply.

How to make construction as cheap (piezo element with or without included oscillator), low power and simple as possible without a fear that MSP430 could be broken.

-Kauko

  • Piezo can be connected directly to a pin. Speaker can be connected via a capacitor ~0.1mF.

  • Thank you Alexander!

    I want to clarify more.

    So if device get shock causing voltage from piezo to I/O pin there would not be any damage to them.

    If using only piezo element both pins of the piezo have to be connected to I/O pins and they can be connected directly and any other components is not needed?

    Which construction is usually used or better, piezo element with or without included oscillator.

    BRs,

    -Kauko

     

     

  • Hello Kauko

    My suggestion would be to use a piezo buzzer which contains the oscillator circuit and thus has only two wires requiring a DC voltage across it to continue sounding.  I would connect the positive of this to a positive supply and connect the negative of this to an NPN transistor's collector.  The emitter of this transistor would be connected to 0 V.  The base of the transistor would connect to the microcontroller's pin via a series resistor (10 k ohm - 10,000 ohms) should do it.  (You could also connect a second resistor, same value, between transistor's base and 0 V, to make sure the transistor turns off smartly.)

    Then to get sound, set the output pin high.  Clear it low to stop the sound.

    The supply connected to the positive of the buzzer need not be the same as the microcontroller's positive supply - it could be higher or lower, to suit the buzzer, since it does not connect directly to the microcontroller pin.  This means you could use a loud buzzer than needs (say) 8 V if you need to.  Also, the transistor will only require a small current from the microcontroller's pin, while being able to drive a larger current through the buzzer.

    While connection directly to the micro pins is possible, if you use a piezo buzzer with integral oscillator circuit (such as the one just described above), then you will need to make sure that the micro's supply voltage is suitable for the buzzer, that the buzzer current is OK for the micro's pin, and you will have to hope that the buzzer does not generate a problematic amount of noise that can get onto your micro's supply line via the pin.  You don't have to worry about that if you drive the buzzer with a transistor.

    Also, if you use the kind of piezo that does not have a built-in oscillator, then you'll have to do the oscillating yourself, i.e. get the micro to waggle its pins at the right frequency.  (You could use one of a timer's waveform generation functions to do this 'automatically' for you.)  But that will tie up some timer functions - I'm sure your micro has more important and interesting things to do!

    And most piezos have a frequency at which they are resonant (depending on their size, material thickness, mechanical springiness etc).  At this frequency, they are loudest.  You would not know what this frequency is without some experimentation.  The self-resonant type of piezo buzzer usually incorporates a circuit that does this part of the job for you.

    I have seen piezo discs connected directly to micro pins before, with the pin oscillating the piezo, but they were very small discs.  Piezos are capacitive in nature and I'd want to know what the characteristics of this were before asking the micro pins to supply the current required.  Being piezo material, bending of the disc (as happens when it makes sound) can generate voltages at its terminals - unlikely to be larger than the voltage which caused the bending in the first place - but I still prefer the transistor-buffered method.

    Hope that helps

    Tony

  • Hi Tony,

    Thank you for many handled aspects. So you refer transistor-buffered method.

    I have seen circuits where N-Channel FET is used. There was also a resistor (example 200 ohm) connected in series with buzzer. In other solution which I have seen there was a resistor (example 1000 ohm) connected parallel with the buzzer.

    FET transistor ( example BSS138) do not need resistors at gate? Do you think using FET is OK and is there sense to use resistor is series or parallel.

    BRs,

    Kauko

  • Hello Kauko

    FET transistors (N-channel) normally turn on when the voltage at their gate is 4 V or so above their source.  They consume no steady current into the gate (although as the gate looks like a capacitor, there is a bit of momentary current flowing to charge it up).  You can connect the gate directly to the micro pin without a resistor, but make sure that the micro pin when high is above the gate threshold (Vgs) for the FET you are using, otherwise the FET will not turn on. (Bipolar NPN transistor will start to turn on around 0.5 V, typical 0.65 V, maybe better for low-voltage micro circuit?)

    The resistor in series with the buzzer is perhaps to drop some voltage across the resistor, to make sure the buzzer sees the correct (lower) voltage compared with what it might otherwise see.  If you don't need this, and it's a bit crude anyway as it depends on a fixed buzzer current, then I wouldn't bother with it.  Same for parallel resistors - I can't see much reason for having this in circuit.

    Not much related to microcontrollers!

    Hope that helps

    Tony

  • msp430 have pretty low pin drive and should never really drive anything above 4mA.
    If your piezo is below that when OK.

    A 74LVC1GX04GW would be better as single mcu pin would create p-p.
    Or a piezo/horn driver that also double the voltage is even better.

  • As you use cr2032 then speaker shall be tiny, so currents shall be small. Check schematics of MSP-EXP430FG4618 and you will see that msp430 can "officially" drive buzzer through 470 ohm series resistor and it's OK :)

  • Tony Payn said:

    ... My suggestion would be to use a piezo buzzer which contains the oscillator circuit ...

    I do not think you need the oscillator circuit. The Timer inside your MSP430 can do that job. Connect the Piezo element across one of MSP430 Timer output pins and ground (or power). Program the Timer to generate a square wave in the audio frequency range and the Piezo element will make sound. Adjust the frequency to your liking. How loud the sound appears depends on (a) the frequency response of the Piezo element, (b) how it is mechanically mounted, and (c) frequency response of your ear. It is perfectly safe and can be loud enough.

  • Using two Timer TA pins of opposite polarity would make a louder sound.

     #ifdef Speaker          

                
                mov.w   #350,&CCR0             ; count from 0 to 350
                mov.w   #175,&CCR1              ; ~50% duty
                mov.w   #OUTMOD_7,&CCTL1        ; reset/set
                mov.w   #175,&CCR2              ; ~50% duty
                mov.w   #OUTMOD_3,&CCTL2        ; set/reset 

                bis.b   #20,&P1SEL                ; select TA0.1,2 mode 
                mov.w   #TASSEL_2+MC_1,&TACTL   ;Sound_on  , use SMCLK and upmode  

                 pause 10seconds 

                 bic.b   #20,&P1SEL              ; de-select TA0.1,2 mode speaker off
                 mov.w   #TASSEL_2+MC_0,&TACTL   ; counter off-mode 
      

  • Hello Tony,

    Thank you, now I have many options to select right way to my solution.

    BRs,

    Kauko

  • An interesting way is applied in the eZ430-Chronos, it’s a kind of Boost converter.

**Attention** This is a public forum