# Using a microcomputer in the drive circuit of a piezo buzzer

I am interested in the use of a microcomputer in a drive circuit for an external drive piezo buzzer. I was reading the FAQ page on the website of a piezo buzzer manufacturer

http://www.murata.com/products/sound/faq/piezo_sound/index.html#q01

Under the heading "Please give me an example of the drive circuit for a Piezoelectric Sounder or a Piezoelectric Diaphragm (External Drive Type)." they said "Examples of typical drive circuits are broadly divided into case 1 where a transistor circuit is used and case 2 where the product is driven directly from a microcomputer." and gave the following image as an example.

I am a novice with electrical engineering and I am trying to understand exactly what components are needed in this external drive piezo buzzer drive circuit. The supplementary comments for this circuit diagram suggested people "consider connecting a Zener diode in parallel with the piezoelectric sound component and Rp if necessary." Based on this, my understanding is that the necessary components of this drive circuit are - the microcomputer, the diode, the resistor (Rp), the buzzer, and a power source.

Is this correct? Is it possible to build a drive circuit for a piezo buzzer with only these components, or do I something else?

You said you were a novice, so here is something simple:

The page you linked to turned out not to be a datasheet, so we don't know anything more about the piezo speaker than what you say. The above circuit should work well enough for most piezo speakers, although it can possibly be driven from a higher voltage, which would yield higher volume.

R1 limits the current thru the base of Q1 when the digital output is high. Figure the B-E junction drops 700 mV, so that leaves 4.3 V accross R1, which causes 4.3 mA base current and will draw that much from the digital output. Most digital outputs can source that much without issue. Check your datasheet. If not, make R1 higher. You most likely don't need as much base drive as this.

When the digital output is high, Q1 will have 4.3 mA of base current, which should easily give it enough current sink capability to pull the collector as low as it can go. Figure you can count on a gain of 50, so that means 215 mA of collector current, which should be way more than required.

D1 is there to give the kickback current of SP1 a place to go when Q1 turns off suddenly. Piezo elements have a significant inductive component as viewed from the driving circuit. If you don't give the kickback current a place to go, then the voltage can get high enough to fry Q1. R2 cause some back voltage to this current to make it die down more quickly, helping the high frequecy response. R2 can probably be a lot lower, but again, you didn't supply a datasheet so all the component values are just rough ideas or guesses at best.

I have been struggling for hours with this circuit. Using Diode 1N4148 and ON Semiconductor NPN transistor PN2222ATA. The transistor output is only 50mV with square wave iput of 600mV after the 1K resistor. This piezo I am using is Murata PKLCS1212E20A0-R1 which is not active. Driving with square wave shown below. Works great when running directly without tansistor circit. Using this circuit, the transistor output is so low that piezo is barly audible.

After searching Stack Exchange for hours, reading a lot, saw it being recommended that the diode be parallel to the R2. I did that and works beautifully. Nice Solid 5v feeding the piezo. Sound is loud and clear.

Schematic updated

Should a diode or capacitor be used in some way to protect the circuit at VCC and the transistor from voltage spikes from the piezo since it can generate spikes when jolted?

• You are using a piezo but your schematic shows a speaker that is completely different. Remove the diode and connect the 1k resistor from the collector to +5V and connect the piezo parallel to the 1k collector resistor. May 7, 2020 at 17:06
• @Audioguru I updated the schematic. Should a diode or capacitor be used in some way to protect the circuit at VCC and the transistor from voltage spikes from the piezo since it can generate spikes when jolted? May 8, 2020 at 11:11
• If you jolt the piezo with a hammer then you do not know if it produces a positive or a negative voltage. Besides, I think its impedance is so high that the 1k resistor R2 will prevent a high voltage spike. May 8, 2020 at 21:58
• Ok. Thanks for your help. May 9, 2020 at 11:44

As a general rule:

• If your sounder/audio indicator is PIEZOELECTRIC, you must use a discharging resistor (suggested range 470R to 2K) with no diode, so that the piezo buzzer sounds properly.
• If you use an ELECTROMAGNETIC sounder ("speaker"), then you should use an anti-parallel diode, with no resistor. Here, the diode protects the rest of the circuit from excessive flyback voltages generated at the coil every time the transistor switches off.

The application you referred to unhelpfully showed a speaker symbol rather than a piezoelectric sounder/buzzer.

A 'piezo' is nothing more than a rather poor capacitor that makes a noise or creates a voltage in response to some form of pressure if used as an input.

You'll need to program an output pin on the micro to produce a squarewave at the frequency desired.

Also make sure that the pin in question can pull up as well (or thereabouts) as it can pull down.

Microprocessors/controllers don't like driving a capacitive load much, so add a series resistor (the precise value will influence volume but 220 ohms is a sensible start) to the piezo sounder and connect it from the output pin to either GND or VCC/VDD. As the piezo is basically a capacitor it doesn't care whether you use either supply minus or plus.