Electronic – Driving piezo buzzer from MCU pin

avrpiezo-buzzerpiezoelectricitytransistors

I'm looking for the right circuit to connect my piezo buzzer to MCU (STM8S in my case). I don't have a partnumber\datasheet for my particular buzzer, but I've found a number of similar schematics in datasheets:

Some of them also have a protection diode (like described in this question) What's the function of the diode in this driver connected to a piezo buzzer?

My buzzer works when connecting directly to MCU pin (measured current is about 3mA).

So here comes questions:

  1. Do I really need a transistor if current through buzzer is so low?

  2. What is a good circuit to connect a non-piezo (magnetic) speaker to MCU? I've tried 8Ohm speaker with 500Ohm series resistor — the sound is very low.

Best Answer

I would recommend to use a transistor, even when the required current is low. A piezo buzzer is highly capacitive, and microcontroller outputs usually can drive only small capacitances.

For the speaker you also want the transistor. The reason why your setup only produces very low sound volume is that the resistor and speaker form a voltage divider, so that the speaker only sees \$\dfrac{8}{8 + 500}=1.5\%\$ of the microcontroller's output voltage. You have to place a flyback diode over the speaker.