Go Down

Topic: pins for audio via piezo (Read 1 time) previous topic - next topic



What pins on the Zero can I use for driving audio to a piezo speaker (ADA-1739) without interfering with serial console, a serial gps, I2C serial or milis() function, etc?
Goal is to generate beeps for a variometer.
I'd like to use a library to simplify stuff.

Would the audio be loud enough for using up in the air while having the speaker nearby?
Would I use digital or analog? PWM?
Would I use two pins in anti-phase to generate more volume?

Please share your insights.

Kind regards,


Jan 08, 2017, 01:46 pm Last Edit: Jan 08, 2017, 05:04 pm by udo1
In the M0 Adalogger pin layout diagram (or whatever you call this) I read:

Absolute MAX per pin 10 mA
recommended 7 mA

Thus my piezo speaker can consume 7 mA max.
What is the impedance of this piezo?
Or should I use a 0K47 resistor?


You could use a transistor for safety. In fact, depending on the samd core used, some pin are not set to use "high" current mode (7mA), but only something like 2-3mA. (See this issue on github)
By using a simple transistor circuit, you can safely drive a piezo speaker, even at 12V like the one you're talking about.


You could use a transistor for safety. In fact, depending on the samd core used, some pin are not set to use "high" current mode (7mA), but only something like 2-3mA. (See this issue on github)
Ah! Very interesting. Thanks for this tip.
So I should find out which pin to use, and also how to set Output Driver Strength bit (DRVSTR) for the pin to 1.
Then I can test the sound volume and then perhaps implement the transistor circuit.
Or switch speaker to get one that delivers more volume with the same Arduino. (impossible?)

Who can tlell me about the pin to use? (that does not conflict with console serial, gps serial, i2c, milis(), etc)
And who knows about setting Output Driver Strength bit (DRVSTR)?


Nobody with infos or advice on these issues w.r.t. the Zero?
I need to produce decent volume with the piezo nearby.
Can I achieve that without using an amplifier?


Using a cheap, simple bipolar transistor circuit is really the best solution IMHO : you can use whatever voltage you want to drive the piezo and get maximum power.

Anyway, here is a patch that should enable the high drive current mode :
Using the latest SAMD core, in wiring_digital.c, add the following line to the "OUTPUT" case in the pinMode function.

Code: [Select]
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit. DRVSTR = 1 ;


It is unsafe to use a single transistor as buffer, with no emitter current limit resistor as well. An accidental short in the output, or any other mishap,could easily burn the transistor out and send 12 V or whatever voltage used directly to the Arduino pin, provoking disaster.

Much better use a cheap audio amplifier IC, with protection built in, which would drive the speaker to nearly 1 W with no problem at all, such as, for example, the TDA7052: PDF enclosed. It uses virtually no external components, so it is very easy to mount it on a standard blank shield.


On the software side:
What is the code to use for maximum power?

The for hardware: how to safely connect the ADA-1739 piezo speaker?


If you are considering using the TDA052 IC, there is no sofware, just hardware connections. The loudspeaker is rated for 8 Ohm impedance, so there is good match to the IC output. I can draw the hardware schematic, if you need this info.


I would like to try first without additional hardware to see what functionality I get.
That is why I considered a simple piezo as no HiFi is necessary.


Mar 12, 2017, 03:36 pm Last Edit: Mar 12, 2017, 03:45 pm by glovisol
Just for testing you can use a small piezo (I did this test myself). To be on the safe side, first measure the load of the piezo with an ohmter: you should get an "infinite" reading: e.g. the piezo has infinite impedance, so that there is no danger of damaging/overloading the pin.

I tested it with a 50% duty cycle squarewave @ 2 KHz on pin 7 of an Arduino zero and the output tone is low volume (only 3.3 V peak to peak) but distinctly audible. To increase the volume, you can tape the metal surface of the piezo to one of those thin plastic boxes used for vegetable packing. Using this baffle with a larger surface the volume will sigificanltly increase.

 Of course much higher volume with amplification bringing the drive to 12 VPP.

Go Up