Teensy 3.5 driving a piezo buzzer

Status
Not open for further replies.

1980s

New member
What is the best way to drive a piezo for trying to use it as a basic lo-fi speaker for playing samples? Which pin type would be best and do I need to make any special electrical provisions for it? Just checking since I am new to Teensy's, but familiar with Arduinos and other MCUs.
 
The current limit of 20 mA will place some constraints there, as does the 3.3V drive. If you find a suitably speced piezo you can direct drive, and even H-bridge it between pins to get ~6v delta voltage but don't believe there is any library for that.

The Teensy audio library does offer a single channel PWM output.
https://www.pjrc.com/teensy/td_libs_Audio.html
which may do what you want, possibly with the addition of a driver to give a voltage step up or by doing a 180 phase invert onto a second pin for a cheaters h-bridge.

For a slightly better approach you can use the DAC out, possibly with the prop shield or similar class D amp module to give quite reasonable mono sound.
 
I am looking at this piezo, not sure what the current requirements are though: http://www.digikey.com/product-detail/en/tdk-corporation/PS1240P02BT/445-2525-1-ND/935930 I have 5V available as a power source, could I somehow sink it to ground while toggling the pin? It doesn't need to be very loud or high quality, I want to replicate some kind of mechanical ticking noise, like drive access sounds for a computer. I think I tried an H-bridge circuit before, but it seemed to use a significant amount of current. Maybe I set it up wrong, but I would like to keep the design simple. The 180 phase invert sounds interesting, is there somewhere I can find more info on it?
 
Running the piezo off 5V won't help directly, since it will just get a swing from 5V-0v (5V) and 5V-3.3V (1.7) so your piezo only gets 3.3V worth of swing, and some model teensies might blow up just for extra fun (3.5 should be 5V tolerent). If you use a transistor drive you can PWM fine and get a 5V swing, and may be easier than trying to get a 6.6V swing by using pins driven in opisition. When you say that you had tried an H bridge, was that using a driver or just trying to have pins going in oppiste polarity? Getting that without bitbanging would be tricky since things like PWM will most likely be starting the on time together so you would need to hack into the PWM code a bit.

The 180 inversion I suspect won't work thinking more about it, since it would require the PWM output to be more complex than I suspect it is. For the basic application you are trying suspect getting a 3.3V piezo (which I think the linked one is intended for) and driving it single ended will get you beeps and such. If it's not loud enough then go for more exotic double ended drives later.
 
I have done it several different ways.

When experimenting sometimes I simply hook up the buzzer directly to IO pin and GND. The one I often use(d) in circuit boards is:
http://www.digikey.com/products/en/audio-products/alarms-buzzers-and-sirens/157?k=102-1155-ND

When I used them on boards I often used it with a transistor, cap... Or I also experimented with simple RC circuit.

But sometimes I simply jamb the two pins of it into a servo expansion cable and then plug the other side into a board that has RC servo pins. I have one right now while helping someone out up on Trossen Robotics with an AVR board.

As for generating the sounds. You can use the Arduino tone command. Some of my programs also have my own hacked up code that I can pass in multiple sounds (duration and frequency) and it plays them one after another. My code is real dumb and simply uses delayMicroseconds and digitalWrite to generate the tones...
 
The piezo you linked to is only capable of making a loud tone when 5v is applied across it. I do not think it is suitable to reproduce sounds. You may get a 'ticking' sound from it if you just apply brief pulses of power to it. Try connecting it to a power source and swipe one set of connections together to determine if it makes the 'clicking' sound you require.
 
I ordered the Teensy 3.5, so I can try out some of these ideas. One concern I have on the software side is generating sounds might not be practical if playing the sound holds up the other more essential operations. This SCSI emulator project got me interested in the Teensy and I thought I could add a mod for some sounds to replicate an old drive. https://hackaday.io/project/18974-tiny-scsi-emulator

Here's the piezo amp circuit I tried that seemed to use too much power, at least for the battery powered board I was working on. It uses too many components anyway.
PiezoAmp.png
 
Your bias network keeps both Tx's (slightly) on. You need to break the connection at the 4.7k / 4.7k / 1uF junction. add another 1uF from the digital pin to the lower 4.7k and keep the connection of the upper 4.7k to the 1uF cap. That way the Tx's are off and only provide power to the piezo when Digital Pin is switching. Get yourself something like LT Spice to simulate you circuits to figure out where their faults are. It's free and there is a Yahoo users group that is excellent, just like the folks on this forum know their Teensy's.
 
There is an excellent and very compact piezo driver and piezo speaker combo build by One Horse on Tindie

It amplifies from 3.3v (or 5v) at 2x,2x or 3x and implements full +- range with great sound in a smaller size than the smallest piezo speaker
 
Thanks for the excellent advice, grease_lighting!

Is this what you meant about breaking a connection and adding a second capacitor?

PiezoAmp - improved.png

Also, should the capacitors be electrolytic or ceramic for this application?
 
I have the same question as the OP (except I'm using T3.6) The circuit above will be difficult to fit on my PCB.
Is it really bad to try and drive the piezo directly?

My application is for a callibration acknowledge/confirmation tone, so low-use, but must be VERY reliable as it forms part of an expensive system.
The piezo I'm testing is a 3Vo-p PS1740P02CE https://product.tdk.com/info/en/catalog/datasheets/piezoelectronic_buzzer_ps_en.pdf

Here is the suggested application circuit:recommended_circuit.jpg
But I'm not sure whether the C1815 is suitable for the teensy. (Ideally I'd like a transistor that was smaller, and in an SMD package)
I also do not understand what the parallel resistor does in this circuit.

Currently it's working great just with a series resistor of 1 KΩ directly connected to a pin on an UNO board and PWM'd at 4KHz using the Tone library (so 5mA current on the pin?).
Can I safely do the same with the T3.6 and a 660Ω resistor or am I totally missing some detail?

Advise / thoughts as always very much appreciated.
 
@Darcy . . . You could probably use a 2n2369, 2n4401 or a 2n3904 NPN or even a BSS123 n-mosfet for the drive transistor. Also it appears the TDK piezo does not have its own oscillator and relies on the drive frequency to make the noise. I've used a Mallory Sonalert ASI12N35MTRQ (3.5kHz) in some of my projects. Can't say much about its reliability but after 3-years it has not failed. I just modulate the 'on' time for various events.

That resistor provides charge to each side of the piezo element when active and quenches the oscillation when inactive.
 
Thanks - I will certainly consider the Sonalert.
Loss of variable pitch is not a deal-breaker, but it might be a little too tall a package. I have 3 PCBs stacked: main board + teensy + display and my enclosure is only 12mm internal. I'll try to find a solution in CAD.

I ordered some BSS123 to trial with my piezo.
They also look like a good go-to component to have around to PWM things like LED backlights etc.

Many thanks for the suggestions.

Darcy
 
I just tried the version that uses a pair of capacitors, but it doesn't appear to work properly.

PiezoAmp - not right.png

I might have done something wrong, but I soldered it up and the piezo element was barely audible. Hooked up my oscilloscope, and sure enough, the voltage across the piezo was just milliamps. I then simulated it using the wonderful circuitjs simulator at falstad.com, which suggests that the single capacitor version ought to work better than the two cap version.

single cap: http://tinyurl.com/yamnv9s8
dual cap: http://tinyurl.com/yazbr8fa

Next, I will solder up the single cap version and make sure it works before I report further.

-- Will
 
Okay, I breadboarded the single cap version, and it works great. Not super loud, but definitely audible from across the room, and very low current draw. This is the circuit that works for me:

PiezoAmp - right.png

-- Will Bain
 
Status
Not open for further replies.
Back
Top