Author Topic: How to connect a piezo speaker to a microcontroller?  (Read 10649 times)

0 Members and 1 Guest are viewing this topic.

Offline zaptaTopic starter

  • Super Contributor
  • ***
  • Posts: 6228
  • Country: us
How to connect a piezo speaker to a microcontroller?
« on: January 17, 2014, 06:41:01 am »
I have an AVR atmega328P MCU that generates 5V square wave 2-4Khz and I would like to connect to it a no name 10mm piezoelectric passive sounder I picked at a local surplus store. It measures as 10nF but don't know its inductance.  I read somewhere that the MCU needs protection because mechanical impacts on the piezo, will send high voltage back to the MCU and damage it. 

I am looking for a simple way to safely connect the piezo the MCU. Any suggestion how to do it? For example is this a safe and reasonable way?  Should I add a serial resistor between the diodes and the piezo to limit the current due to the piezo's capacitance?

 

Offline miceuz

  • Frequent Contributor
  • **
  • Posts: 387
  • Country: lt
    • chirp - a soil moisture meter / plant watering alarm
Re: How to connect a piezo speaker to a microcontroller?
« Reply #1 on: January 17, 2014, 07:54:35 am »
Piezo element is capacitive, so you want to drive it via a transistor as it takes relatively big gulps of current on every on and off.  That and possible high voltage spikes as you've mentioned


Offline zaptaTopic starter

  • Super Contributor
  • ***
  • Posts: 6228
  • Country: us
Re: How to connect a piezo speaker to a microcontroller?
« Reply #2 on: January 17, 2014, 04:51:45 pm »
Thanks miceuz, that's simple enough. I will give it a try. 

I saw also similar circuits but with a additional diode in parallel to the resistor.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27384
  • Country: nl
    • NCT Developments
Re: How to connect a piezo speaker to a microcontroller?
« Reply #3 on: January 17, 2014, 06:36:24 pm »
Piezo element is capacitive, so you want to drive it via a transistor as it takes relatively big gulps of current on every on and off.  That and possible high voltage spikes as you've mentioned


If you replace the R* with an inductor then you double the swing.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline zaptaTopic starter

  • Super Contributor
  • ***
  • Posts: 6228
  • Country: us
Re: How to connect a piezo speaker to a microcontroller?
« Reply #4 on: January 17, 2014, 10:01:58 pm »
If you replace the R* with an inductor then you double the swing.

How do I choose the inductance?  (assuming frequency and piezo's datasheet are given).

 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27384
  • Country: nl
    • NCT Developments
Re: How to connect a piezo speaker to a microcontroller?
« Reply #5 on: January 17, 2014, 10:18:36 pm »
If you replace the R* with an inductor then you double the swing.

How do I choose the inductance?  (assuming frequency and piezo's datasheet are given).
Somewhere around 5mH to 10mH should do. You should do the math to determine how long you can turn the transistor on without saturating the inductor. The duty cycle should also be less then 50%.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19681
  • Country: gb
  • 0999
Re: How to connect a piezo speaker to a microcontroller?
« Reply #6 on: January 17, 2014, 11:20:40 pm »
You should be able to drive a piezo directly from an MCU output and don't worry about the diodes, the MCU has them built in. Just connect the piezo directly to the MCU IO pin.
 

Offline Baliszoft

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: hu
Re: How to connect a piezo speaker to a microcontroller?
« Reply #7 on: January 17, 2014, 11:23:28 pm »
I am also driving the piezo directly from the mcu pin thru a 100n cap without any problems.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19681
  • Country: gb
  • 0999
Re: How to connect a piezo speaker to a microcontroller?
« Reply #8 on: January 18, 2014, 01:55:16 pm »
A series capacitor is not a bad idea is it blocks DC which can be bad for piezos.

For more volume, connect the piezo between two I/O pins and drive them out of phase with one another.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf