PDA

View Full Version : How to connect Buzzer to PIC?



koossa
- 10th January 2006, 06:33
What is the correct way to connect a buzzer to my PIC and do I just put it<br>
HIGH, LOW to switch it on and off or is there a better way of doing this?

And what is the differece between a buzzer and a piezo sounder?

BobK
- 11th January 2006, 04:29
Hi Koossa,

I always use a GP transistor to drive either a buzzer or piezo. I think the differences are 1) the sound they make and 2) buzzers are more mechanical and a piezo is not. I was hoping someone else would jump on your question before me but since that didn't happen I thought I would take a shot at it.

I think the buzzer issue also has to take into consideration what size buzzer you are using and how much current does it draw. This,of course, would then determine the type of driver you will need.

I have some small 6volt buzzers that I bought from Jameco and a 2n2222a is just fine for driving it. I also use the same driver on my piezos.

Hope this helps.

BobK

Melanie
- 11th January 2006, 08:28
A buzzer is a coil with a mechanical interrupter. When you apply a voltage, the coil energises, mechanically moves a core (usually soft iron) which in turn breaks a contact. The core moves back, contact is made once again and the process starts all over again. The core is usually connected to a sounding board (in better buzzers) to produce the noise, or in cheaper buzzers they just let the core movement produce the noise.

The upside of the buzzer is you just apply volts and it works. The downside is that you have a COIL which is being switched on/off by it's own integral interruptor. This means (a) it's relatively power hungry, usually more than the 25mA maximum a PIC can drive, (b) in most cases requires more than 5v to drive to make a decent noise, but more importantly (c) the crappy ones can produce a significant back-emf which can easily destroy a transistor (or PIC pin) if you don't put a suppression diode across them. Connect a junk Buzzer (or use a Relay cross-connected in series with it's own contacts) to a Battery, and put your fingers across the Battery - the result is the kind of thing you use in prisoner interrogation (or job interviews) where they don't have handy AC volts comming out of the wall (you get the best tips and tricks on this forum - mention it in your Resume when you're applying for your next CIA job).

A piezo sounder is a piece of crystal which changes shape (moves) when you apply a voltage across it (kinda like when you get strapped into old sparky). The movement is constant depending on the mechanical properties of the crystal.

The upside of the piezo sounder is (a) low power, they have an impedance of meghoms therefore require next to no current to drive them, (b) they DO require a voltage to excite the piezo material but it can be as low as 1.5v, (c) they make a hell of a noise when you hit their resonant frequency. The downside is (a) they require being pulsed AT their resonant frequency (ie if it's a 4kHz piezo, they need to be driven at 4kHz), and (b) if you don't feed them with their desired frequency as a drive signal, the noise they produce is quite miserable.

I never use buzzers with PICs because they're mechanically large, need suppression, and are power hungry so require additional circuitry to drive them.

However with piezo's, the secret is you MUST hit that resonant frequency. In one application I used to drive a piezo sounder at 35v in order to get the sound output I desired. Only later I discovered my drive was off by some 300Hz, and by adjusting the software and hitting the right frequency I can now get the same output from the sounder at 5v direct from the PIC only going through a 100nF Capacitor.

koossa
- 11th January 2006, 08:47
Hi Melanie

Thank you very much for the explanation, now I understand better.
I think I will defenately use the piezo's.

My piezo only use 1mA.

I'm using the PWM function to produce a beep on a piezo.
Will it be correct if I use the schematic displayed at the PWM section in the Picbasic Pro Manual.

Currently I have connected the piezo directly between PortC.2 and GND and then in my code use <b>PWM PORTC.2,230,7</b>.
Will this configuration of connecting the piezo directly between PortC.2 and GND affect my circuit in any way?

Melanie
- 11th January 2006, 09:20
I normally connect a Piezo via a 100nF Capacitor (same sort I use for decoupling on my PCB's) because I once met a brand of Piezo's that randomly 'hung' when connected directly. See schematic. The Higher drive level option requires having one pin go High and the other Low alternatively. You can achieve this by manipulating the pins directly (you won't drive this conventionally 'as is' by using the PWM or HPWM commands).

koossa
- 11th January 2006, 09:34
Thank you very much Melanie!

steve@lumicycle
- 9th October 2006, 14:37
I read your thread about getting a piezo buzzer to work on the pic. This I have done. However what I don't understand is why you can't drive the piezo very loudly through a mosfet. It doesn't really work at all just a faint noise. however if a 1k resistor is connected in series with the piezo it works ok but not that loudly. I think the frequency is OK. driving a loudspeaker through the mosfet works fine. There must be something about driving a piezo i don't understand. Any help gratefully received.

sayzer
- 9th October 2006, 14:49
I read your thread about getting a piezo buzzer to work on the pic. This I have done. However what I don't understand is why you can't drive the piezo very loudly through a mosfet. It doesn't really work at all just a faint noise. however if a 1k resistor is connected in series with the piezo it works ok but not that loudly. I think the frequency is OK. driving a loudspeaker through the mosfet works fine. There must be something about driving a piezo i don't understand. Any help gratefully received.



Pls read this:
http://www.picbasic.co.uk/forum/showthread.php?t=4796


--------------------

hoops2006
- 1st January 2007, 16:14
Hey guys

im trying to make myself a boxing round timer. Im just about there but im have a bit of trouble with getting a buzzer or sounder loud enough. It needs to be loud enough to be heard over music. im using a 9v battery. My smoke alarm uses a 9v battery and thats loud as hell so the most be some way of doing it. any help much appreciated.

Hoops

sayzer
- 1st January 2007, 16:24
chk the link above.

----------------------

flotulopex
- 15th January 2010, 09:12
I have read Mel's explanation about how to connect piezos.

So I made this project as you can see it here. It is connected in parallel with an electric doorlock.<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3886&stc=1&d=1263546495">
*don't trust the PIC's pins connections on this shema - I used a 12F675 component in EAGLE just for the drawing - I couldn't find a 10F202.

When I power the circuit with 6 to 8V DC for testing, it works fine and the piezo sounds loud and clear.

When the circuit is connected to the AC power supply that goes up to 18VAC, no sound comes from the piezo anymore (?!).

The strange thing is, the piezo seems to affect the voltage regulator ability to provide a stable 5V. In fact, the voltage regulator doesn't supply a constant 5VDC but goes up to 7VDC.

I added a decoupling 100nF (in fact, I connected different capas for test - none did the trick) capacitor in serie with the piezo but this didn't change anything.

I replaced the piezo by a 5V led and then, the voltage regulator has no problem and feeds a steady 5VDC while the circuit is fed with 18VAC.

My oscilloscope shows some disturbances on the output of the voltage regulator when the piezo is connected and nothing with the led. But how do I get rid of them?

Any idea what the piezo does?

My piezo's datasheet is here: http://datasheet.octopart.com/HGP-05A-Star-Micronics-datasheet-580811.pdf

Melanie
- 15th January 2010, 10:58
It's got a COIL - which means it's NOT a Piezo.

What you have is basically a poor-mans Loudspeaker (as opposed to a Buzzer). It's frequency response is dependent on it's mechanical construction.

OHMS LAW... how much current is it going to suck?

Is it going to generate a Back-EMF?

Your poor Regulator at the higher voltage supply is going to have a hard time feeding the PIC and the Sounder which incidentally will most probably introduce a lot of horrible noise on the Supply line adversely affecting the PIC.

This is a poor choice of device for any low-current application. For best efficiency, you're going to have to adjust your circuit and drive the device more like the way you would an Audio Loudspeaker.

flotulopex
- 15th January 2010, 14:04
Thanks Melanie,

I'm feeling stupid not having noticed my piezo ...is not a piezo :(

I better understand all other of my problems with this circuit now.

dompower
- 23rd January 2010, 19:54
Dear Melanie,
You forum has lots of interesting informations. Thanks for keeping upto-date information.
I have a problem. I got a piezo buzzer from a smoke detecting alarm.
I like to use it in my PIC based circuit.
This buzzer has three wires. (red, black & white)
Can you suggest why there are three wires. I guess red for +, and blank for -.
Since this one is sealed I am unable to go thru.

Please help me.

DOminic
Riyadh
Saudi Arabia

Melanie
- 24th January 2010, 00:01
First make sure it's the Piezo you've got - and not the Sensor.

The three wire devices usually employ the third wire to change the tone. When connected to Vdd you'll get one tone, and when connected to 0v you get another. That's the way they get the 'warbling' effect for the Alarm sound.

Other more sophisticated Piezo's allow the sychronisation of several sounders - and they use the third wire for that purpose. You'll know that is the type if the original smoke alarm had an additional conector for connecting to additional alarms.

Experiment and see what you get...

mtripoli
- 28th January 2010, 17:30
First make sure it's the Piezo you've got - and not the Sensor.

The three wire devices usually employ the third wire to change the tone. When connected to Vdd you'll get one tone, and when connected to 0v you get another. That's the way they get the 'warbling' effect for the Alarm sound.

Other more sophisticated Piezo's allow the sychronisation of several sounders - and they use the third wire for that purpose. You'll know that is the type if the original smoke alarm had an additional conector for connecting to additional alarms.

Experiment and see what you get...


Maybe... I'm guessing it's a "self-drive" piezo buzzer. It needs a transistor and a few resistors to make it work...

Michael Wakileh
- 31st January 2010, 19:46
Every so often I find myself buying products just to find out how they work... Recently I bought a cheap battery powered Piezo alarm...very small and quite loud...
(I believe it's sweeping btw. two frequencies to be even more
audible...so it's probably a piezo transducer.)

I'm looking for help in figuring out how they made it so loud.

(The audio jack is being used as a switch...alarm goes on when
pin is pulled out...pin is stopped from coming out via housing...nice hack)

I will draw up a schematic soon... here some pics

Unfortunately I've never seen the critical part in question (black with 3 pins).
I'm guess I'm looking at a transformer? inductor?

Can anyone give me hints towards reading material or electrical tests I can do to find out more...

ScaleRobotics
- 31st January 2010, 20:10
Looks like the large 3 pin part might have heat shrink around it. Is that the case? If so, can you cut it off, and see a part #?

Michael Wakileh
- 31st January 2010, 21:36
Unfortunately no part number... just a bunch or really fine coils... I tried to be careful but I cut through them.... Perhaps I'll buy another unit so I can find out how many coils etc... but I guess we have an answer. I am not familiar with transformers. Logic tells me this one has a comon ground...input is boosted drive the piezo at higher voltage... I did a very brief search of farnell but didn't find anything similar... Anyone know part numbers or supliers of small 3 pin tranformers?

mtripoli
- 1st February 2010, 05:08
It's a coil (inductor) to generate flyback voltage. There's a switching circuit that creates a high voltage to apply across the piezo element. Piezo elements are generally designed to be run at high voltage; 30-200V is not uncommon. In a really good design the piezo will also be in a Helmholtz enclosure as well to really get everything from the system as a whole. Years ago I designed these things for car alarms. 120dB was on the low end of what you could achieve...

Do some searching on piezo elements; off the top of my head I'd say have a look at Murata. I seem to recall that they have some pretty good doc's on these things.

Mike Tripoli

P.S. I found the doc I was talking about pretty quickly: http://www.murata.com/catalog/p15e6.pdf. It's a good starting point...

Michael Wakileh
- 1st February 2010, 13:37
Thanks! I've glanced through it and it's the best info I've seen sofar. I'll need some time but I'm going to work on a simple solution for pics (need to read up on inductors etc). Seems like this is something that gets asked about often on the forum.

regards,
mike

Michael Wakileh
- 4th February 2010, 15:28
After some thought, I think I will go with max232/3232 or equivalent. May get back to this if sound output is not satisfactory...

mtripoli
- 5th February 2010, 15:09
Will that help? I'm going off the top of my head but you'd have to use both outputs and invert the signal going into one of the inputs to get the voltage swing across the piezo (assuming using one output pin on the PIC)? You'd only get about 14VAC? What is the capactive loading spec of the 232 device; can it drive a cap load (piezo's are normally a "relatively speaking" large capacitive load).

Have a look at this website: http://www.discovercircuits.com/P/piezo.htm. There are a couple of circuits shown. All you really need is a small inductor, a transistor and the piezo. The PIC is your oscillator. I'd have to think this is cheaper and easier than a MAX232?

Keep in mind the resonant frequency of the device as well. Thinking back, one of the problems that the car alarms I worked on had when I was brought in was the guy before me was trying to brute force the piezo to get the output needed (+120db @ 3 feet). It was at around +97db. Tweaking the frequency made it jump to over +120db. The other thing that is more important than you'd think is in the way the piezo is held. I've done edge fixture mostly; the tighter this is clamped the better for output.

I invented the "Singing Balloon"; this uses a piezo attached to a "foam speaker". It is edge mounted as well and driven with PWM from the sound chip. The output is around 10VAC to the piezo (in this case it reproduces music). The piezo *really* needed about 30VAC but the product (disposable in every sense of the word) couldn't stand the cost of the added circuitry to make it happen. I think to date there's been about 30-35 million :( of them produced.

Mike Tripoli

Michael Wakileh
- 5th February 2010, 22:15
Hi Mike!

Thanks for the post... I worked on a very lengthy reply and then lost it unfortunately =(...
The main pointers of that message were:

I'm looking for a small solution that can run on for example 3.3 volt, and haven't been satified with inverted pin output which is shown so often

Unfortunately I came to the conclusion that I don't understand enough to design a flyback solution in the limited time I can currently allocate.

I checked several resources, and then availability and size of split smd coils and their pricing. I had doubts as to whether there was much of an advantage of using a flyback converter here..

I had uncertainties on whether I could build the coils myself (aircoil? pcb inductor?)

Reading the schematics I had several difficulties as well...
(for example @ http://en.wikipedia.org/wiki/Flyback_converter) I was unsure how the split inductor should really be connected to the PCB.

PCB Die bonding made close analysis of the dissected circuit difficult.

Thats why I decided to follow a different route at the moment....

Anyway, in my search for a reasonable solution I did find some very nice chips from maxim (~1$) which I indend to try out. For example the MAX9738...
These also typically have 14-16VP-P so I hope my RS232 method will work... I do hope it will work because many hobbyists already have that chip at home.

I also figured the max3232 solution may also offer protection from Voltage spikes (from trauma or intended tapping) of the piezo (sensing by linking rs232 input and RS232 output).

Here some interesting links:
http://www.instructables.com/id/Extreme-Business-Cards!/step14/All-Done/
http://video.google.co.uk/videoplay?docid=-3723317327995034061#

I'm still missing some caps for my test but I will post soon...

regards,
Michael

Michael Wakileh
- 5th February 2010, 23:35
Hi! I got a chance to look at your singing ballons on youtube... nice...
I'd actually be quite content if I reach that volume... You wanted them even louder?

mtripoli
- 6th February 2010, 22:49
To answer the last question first: I'm not sure what video you saw of the "Singing Balloon". The sound level output of the balloon is satisfactory; I wanted the higher voltage to get more headroom. In order to get the volume you hear I had to severely clip the (original) waveform. With a higher voltage (more headroom) I could have clipped the sound less and it would have sounded much (much) better. As with any disposable product, sub-fractions of a penny add up fast.

I didn't listen to the videos you attached but I think I get it; the card is programmed with DTMF tones (http://en.wikipedia.org/wiki/Dual-tone_multi-frequency) that are recorded (or generated via code) and reproduced into the mouthpiece of the phone. Phone systems recognize this and dial the number. Lot's of products have been on the shelves over the years that do this. The business card is cute but I'm not so sure of the practicality (my opinion - but we're not talking about that). You didn't say if this is exactly what you want to do. If it is, I'd offer the following...

The links I posted show how to connect the inductor for operation. I don't know that this would help anyway. When using an inductor in an oscillator you are tuning the components for the target frequency. With DTMF you are generating a couple of different frequencies so (if) you get it to oscillate it will not be very efficient and the voltage generated will be all over the place. Frankly, I'd abandon that approach.

You *could* however design a small high voltage step-up circuit. I'm going straight from memory but I think both Maxim and Linear Technology make IC's to do this. I have no idea of the Vmin values... You could then use this with a transistor to power just the piezo. I think these devices are current hungry and you won't get far with a lithium coin cell (they probably have an enable of some sort to turn them on and off, but...). And then there is the noise on the supply rail to deal with...

However.

You don't need high volumes to make this work, the XOR'd output from two pins driving the piezo should be fine; with 3V you get 6Vp-p like this (5 gets you 10). You're not going for resonant frequency so you can pretty much ignore anything to do with that other than holding the piezo solidly.

Keep in mind that waveform is not going to be a perfect square-wave when driving the piezo, nor will you get all the way to the rails.

I'd look for the piezo devices that have a crystal element on both sides of the brass coin. These are more efficient than than the single sided and only cost a few pennies more.

The thing you need to keep in mind doing this is the stability and accuracy of the frequencies being generated and that the tones are sine wave, not square. As I recall from doing a DTMF decoder years ago was that you have a very small window of deviation from the center tones to make it work.

PBP has a DTMFout routine that needs a 20Mhz to get it right. It's PWM from one pin and needs a filter to get it "sine-wavy". You'll loose voltage through the filter so don't think it'll be anywhere near the rail (its meant for going to into an amp). I've seen assembly code years ago to generate DTMF and used a few but that was a long time ago.

Good luck.

P.S. When preparing a lengthy post, before posting it copy it to the clipboard. If the session has timed out you can just paste it back in.

Michael Wakileh
- 11th February 2010, 19:37
Hi Mike,

Sorry for the late reply, and thank you for all the great information and the great links...

I'm sure I've had several past projects with badly mounted piezos, and
thanks to this thread I've finally taken the time to look at boost converters. I actually do a lot of my prototyping in smd and I've scrapped the flyback idea for now. (Common mode chokes are quite expensive and have lead times of >2months with farnell.at)

However, I've skimmed the Microchip technical briefs (TB053, AN258, ccp tips and tricks) on the regular boost converters in discontinuous mode, and I will be adding some chip inductors to my next order. Once I get my parts, I will test a small high voltage stepup (Ip = 10mA) and transistor method.

I'm actually not working on an embedded project at the time...
Just trying to learn a bit for future endeavors. The business card link was just an example of a battery driven, tiny gadget (the type of device I like to work on). Also, I was interested in sensing of Voltage spikes, and ways to protect the io pins incase of shock/trauma.


best regards,
Michael

Telemachus
- 19th April 2010, 06:41
I have taken apart a kitchen timer, and it has a similar circuit to the piezo buzzer mentioned earlier in this thread. There is a large inductor coil attached where the buzzer is.

In this picture:

http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3949&d=1264966885

Can someone tell me what is the purpose of Q1? Looks to be a surface mount NPN transistor.

One of the leads to the piezo is always high, and the other one seems to be attached to the collector (not emitter!) of this transistor with the emitter going toward the IC through R1, although I could have my pinouts wrong.

How does the IC control the PWM going to the piezo by means of the transistor?

Thanks!

mark_s
- 19th April 2010, 17:41
This is a circuit I use. When the NPN is turned on the inductor is energized, turn off the transistor and a large counter inductive voltage spike is generated.
As stated in earlier posts its best to drive the piezos at the resonance frequency. Your picture maybe different

Your question about the IC control. The transistor acts as a switch, controlled by the IC. More important it protects the IC as a buffer with it's
higher current handling ability

mtripoli
- 20th April 2010, 03:40
I have taken apart a kitchen timer, and it has a similar circuit to the piezo buzzer mentioned earlier in this thread. There is a large inductor coil attached where the buzzer is.

In this picture:

http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3949&d=1264966885

Can someone tell me what is the purpose of Q1? Looks to be a surface mount NPN transistor.

One of the leads to the piezo is always high, and the other one seems to be attached to the collector (not emitter!) of this transistor with the emitter going toward the IC through R1, although I could have my pinouts wrong.

How does the IC control the PWM going to the piezo by means of the transistor?

Thanks!
You've got the pinout wrong... the 22K resistor is on the base, the emitter looks to be tied to ground (check it with a meter). It sounds like the piezo is in the collector making it an open collector. You can tie the coil in parallel with the piezo to get the same flyback effect that Mark_s was talking about. Again, it's resonant so you have to play with the frequency to get it to "go"...

Telemachus
- 20th April 2010, 06:20
You've got the pinout wrong... the 22K resistor is on the base, the emitter looks to be tied to ground (check it with a meter). It sounds like the piezo is in the collector making it an open collector. You can tie the coil in parallel with the piezo to get the same flyback effect that Mark_s was talking about. Again, it's resonant so you have to play with the frequency to get it to "go"...

Thanks, after some more research, I realized the true pinout.

Actually, what I am trying to do is to remove the coil and piezo entirely, and have the transistor act as a switch to turn on and off a higher voltage (3.3volts) that will be fed to the input pin of a PIC. Therefore, when the kitchen timer goes off, the PIC will read the PWM output as a digital signal to run a routine prior to resetting the kitchen timer to start counting again.

What I have come up with so far is to disconect the coil from the transistor's collector, mount instead a 3k3 resistor between the collector to PIC VDD (3.3V) and connect the PIC input pin on transistor's colector. With the emitter of the transistor connected to GND (I will ground the PIC to the CMOS circuit). That way, when the timer goes off, it should trigger a "buzzer" that in non audible, but compatible with the VDD voltage that my PIC can read digitally.

This is a timer circuit to snap the shutter on a Cannon SLR camera, and I have found that using the kitchen timer is cheaper than it would be to buy the LCD and buttons needed build the circuit completely based on a PIC.

mtripoli
- 21st April 2010, 01:56
A digital Canon SLR? If I recall, there is a group of pads inside the the battery door. Bridging these pads results in focus adjust and shutter release. I used a 1K resistor (or something) to play around with this. I was going to make an RF remote control for my camera but got side-tracked with something else (about 5 years ago). There's a bunch of info on the net about this stuff. I think you can use just a relay to do this...

I'm missing the point of using the kitchen timer. You can do everything you want with just the PIC...

Telemachus
- 21st April 2010, 04:17
A digital Canon SLR? If I recall, there is a group of pads inside the the battery door. Bridging these pads results in focus adjust and shutter release. I used a 1K resistor (or something) to play around with this. I was going to make an RF remote control for my camera but got side-tracked with something else (about 5 years ago). There's a bunch of info on the net about this stuff. I think you can use just a relay to do this...

I'm missing the point of using the kitchen timer. You can do everything you want with just the PIC...

The point of the timer is an LCD screen and push buttons for $2 at local discount store.

I have already created one that is solely pic based, sets the camera off on intervals based on a potentiometer, from 1 to 255 seconds. I was next going to install and LCD screen with push buttons to do it all digitally, and found that the kitchen timer is cheaper than buying those parts individually.

The timer has button that when pushed at the end of the cycle, restarts the timer. Essentially, the button is connecting a pin on the CMOS to the VDD of the circuit. I may be able to use another transistor and have the timer reset itself without even using a pic...