getting a piezo louder using 2 GPIOs?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
kr0815
Normal user
Posts: 136
Joined: 18 Nov 2015, 18:24

getting a piezo louder using 2 GPIOs?

#1 Post by kr0815 » 25 Apr 2021, 20:56

I have a project with several ESP8266 - each has (passive) piezo buzzer attached

Unfortunatelly, they are not loud enough

I read in another forum - best way would be to connect them not to Ground, but to 2 GPIOs, switching them both alternatively on / off

Does anybody see any chance how this could be done with the PWM function?
Stupid Idea: maybe 2 much higher frequencies, in the end they mix together as one lower frequency?

I have no idea how PWM is generated over more than one output, are they synchonous?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: getting a piezo louder using 2 GPIOs?

#2 Post by TD-er » 25 Apr 2021, 21:26

It is a bit tricky how the ESP8266 PWM is generated.
There are I believe 3 timers for PWM and you may set (not in ESPEasy, but in C++) some pin to use a specific timer.
If you switch them at different PWM and still use the same base frequency, you essentially double the number of cycles or depending on the differences between the duty cycles and capacity of the wires you may generate some kind of interference pattern which may have a slightly different frequency which may be closer to the resonance frequency of the piezo.

I suggest to try experiment with the PWM frequency to see if you can find the specific resonance frequency of your piezo as that's probably more likely to 'suddenly' increase the volume.

Another thing that could be happening is that GPIO pins may sometimes source a higher current than drive (deliver) it (especially if there is some pull-up or pull-down resistor connected to it) and that may make a difference too as you may end up sending a higher current through the piezo.
But I guess using a transistor to drive the piezo is then making more sense as a piezo is electrically just a capacitor.

The volume of a piezo element is mainly determined by the voltage applied.
One thing you can do is just like the old fashioned bobine in an engine.
Just draw some current through a coil and suddenly interrupt this current. The coil will then give out a much higher voltage.
So if you place a coil in series with a transistor and place the piezo in parallel on it, the piezo may get a high voltage spike when you open the transistor.
You should use a transistor which can withstand a high voltage of 60 - 100V. (Vce on an NPN transistor)
Since the piezo acts as a capacitor, it takes time to 'charge' it.
So the duty cycle determines the volume of the piezo.
As value for the coil, you may need to experiment. Somewhere between 22mH - 47mH I would expect.

One thing to keep in mind;
Piezo elements don't like to be driven with DC, so make sure the transistor is never constantly closed (open at rest)

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: getting a piezo louder using 2 GPIOs?

#3 Post by ThomasB » 28 Apr 2021, 20:25

FWIW, using two GPIOs out of phase would double the drive voltage. So this trick makes the Piezo louder. However, ESPEasy's PWM command does not allow you to specify the driven signal's phase.

Here's a suggestion for a possible workaround (not tested):
1. Connect the Piezo with one GPIO pin and find the PWM frequency that creates the loudest sound. This is the Piezo's resonant freq.
2. Next connect the Piezo to two GPIO pins. Drive one pin at the resonant freq and the second pin at a higher freq. Just experiment: For example, try 1.5X and 2X resonant freq on the second pin.

With luck this trick will provide a bit more volume and a pleasantly modulated sound. Or maybe not.

- Thomas

seersucker
Normal user
Posts: 24
Joined: 11 May 2020, 17:01

Re: getting a piezo louder using 2 GPIOs?

#4 Post by seersucker » 12 Sep 2021, 03:10

I don't think paralleling GPIOs would do much apart from possibly providing more drive current, which at most would give 3dB more audio output. The outputs themselves are either 3.3v or ground, so differential drive isn't possible, anyway I believe those piezo sounders are polarized.
Instead, use the GPIO to drive a small transistor from either 3v or even a 5v source. (with the sounder in series between the supply and collector, just like in a relay drive circuit.)

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: getting a piezo louder using 2 GPIOs?

#5 Post by ThomasB » 12 Sep 2021, 19:17

Driving a piezo using two out-of-phase MCU GPIO pins to make it louder is a real thing. There's plenty of discussion on the web about this drive method. For example, here's a Piezo library that does it: https://forum.arduino.cc/t/toneac-twice ... ary/138440

ESPEasy does not have a plugin to do this. That is why I suggested the workaround posted earlier. Might work, might not.

- Thomas

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 22 guests