How to - Amplifying a Piezo Speaker and Volume Control

Piezospeaker Volume Control
Here is a·activity you can use to control the volume of your Piezospeaker with a potentiometer.· The volume ranges from barely audible to annoyingly loud.·

Parts List
You can find most of these parts in the What's a Microcontroller kit.· The LM358 is part of the Basic Analog and Digital kit, but you can also purchase it online through the Parallax Component Shop.· The 9 V battery clip is an item you can probably get at your local Radio Shack or other electronics outlet.

Parallax
Part Number···· Quantity··· Description
· 152-01031········· (1)········· 10 k potentiometer
· 150-01030···· ···· (2)········· 10 k resistors
············································· or (1) 5 k
· 900-00001········· (1)········· Piezospeaker
· 800-00016········· (misc.)···· Jumper wires

························· (2)········· 9 V batteries
· 602-00015······ ·· (1)········· LM358 opamp
························· (1)········· 9 V battery clip with tinned leads

Amplifier Circuit Between P9 and Piezospeaker
The circuit you are about to build is called an inverting amplifier circuit.· It has an input that receives the audio signal from the BASIC Stamp(R) 2 microcontroller's P9 I/O pin.··It's output is connected to the piezospeaker, and you can control the volume with a potentiometer.··The LM358 in the amplifier circuit·will need a dual power supply, which·you will use two 9 V batteries and·one 9 V battery clip with tinned leads to build.

Dual Supply Schematic
To get good amplification with one opamp circuit, the opamp chip can needs two supplies, a negative voltage and a positive voltage.· By plugging a 9 V battery into the Board of Education's battery clip, this will give you + 9 V at the Vin sockets above the breadboard.· If you measure this with a voltmeter, connect the positive lead to Vin and the negative lead to Vss.· To make the -9 V supply, simply connect the positive lead of your second 9 V battery to Vss.· The negative lead will then supply -9 V.· Most 9 V battery clips with tinned leads have a red lead connected to the battery's positive terminal, and a black lead connected to the battery's negative terminal.· Verify this with a voltmeter.· If the red lead is indeed the connected to the 9 V battery's positive terminal, then connect the it to Vss, and set the black lead aside.· You will connect the black lead to the opamp's negative power supply input when you build that circuit.

attachment.php?attachmentid=36496

LM358 Pin Map
This is a pin map of the LM358 opamp chip.· It has two opamp circuits in it along with a positive and negative power inputs.· Remember to use the semicircle reference notch to get the chip right-side-up on the breadboard.· If you plug it in upside-down but wire it as though it's right-side-up, it could damage the chip and maybe your BASIC Stamp too.

attachment.php?attachmentid=36494

Project Schematic
This is the circuit you will need to build.· It's really easy to make a wiring mistake on this kind of circuit; I corrected several before I could get my own circuit to work.· Fortunately for me, I didn't damage anything.· Before you actually plug in the batteries, triple check the circuit.

Note that the opamp triangle in the schematic has pin number references that match the ones on the pin map.· Build this circuit.· You will be using the dual power supply you built earlier, make sure to connect Vin to pin 8 on the LM358, and connect the -9 V (battery clip's black lead) to pin 4 on the LM358.· Vss should be connected to pin 3 on the opamp.·

attachment.php?attachmentid=36495

Wiring Diagram
Here is a photo of the completed circuit that you can use as a wiring diagram for trouble-shooting.·

attachment.php?attachmentid=36492

Testing the Circuit
When I plug in my batteries, I usually monitor the opamp's temperature for fifteen or so seconds by resting my fingertip on the top of the chip.· If it gets hot in this amount of time, I disconnect power immediately and start looking for wiring errors.

If your LM358 stays cool, run a program to make your BASIC Stamp generate a ten second tone:

Test Program
I like playing a tone for about ten seconds.· This gives me enough time to turn the pot and verify that it controls volume, but it doesn't go on long enough to disturb·anybody else.· If I want to run the program a second time, I just press and release the Reset button on my board.·

Run this program and verify·that you can control the tone volume with·the potentiometer.· The full range of potentiometer motion should change the volume from quiet to loud, and visa-versa.
' ToneForOpampVolumeTest.bs2
 
'{$STAMP BS2}
'{$PBASIC 2.5}
 
DEBUG "Mi...", CR:  FREQOUT 9, 10000, 1319     ' E6
 
END


How the Circuit Works
Here is a simplified version of the opamp circuit.· This·circuit is called an inverting opamp circuit.· Vi is the input voltage, Vo is the output voltage, and Ri and Rf are called the input and feedback resistors.· In your circuit, Ri is two 10 k resistors in parallel, for an equivalent resistance of 5 k.· Rf is a 10 k pot, and it can be adjusted anywhere from about 100 ohms·to 10 k.

attachment.php?attachmentid=36493

Opamp is short for operational amplifier.· Here is the math operation that this operational amplifier circuit performs:

Vo = (-Vi * Rf / Ri)

Vo is the inverting amplifier's output voltage, and it is the negative of the input voltage (Vi), scaled by the ratio of the feedback resistor (Rf) divided by the input resistor (Ri).· Keep in mind that you turn the potentiometer to control the value of Rf.· When·the potentiometer is·in the middle of its range of motion, Rf and Ri are both 5000, so Vo is simply the negative of the input voltage.· When Rf is near 10 k, Rf/Ri = 10000/5000 = 2.· So, the output voltage is -2 times the input voltage.· If you turn the potentiometer the other direction, below 5000, to say, 500, then the output voltage is -1/10 of the input voltage.

Your Turn - Digital Potentiometer Control
Try replacing the potentiometer with the digital potentiometer from What's a Microcontroller, Chapter 9.· You can then modify the program to control the volume automatically, or even with the Debug Terminal.

The piezospeaker plays notes loudest at 5 kHz, and the device's response is optimal between 4.5 and 5.5 kHz.· As the notes get lower, they are attenuated by the speaker and they sound quieter.· With a digital potentiometer, the BASIC Stamp can be programmed to automatically adjust the volume of each note so that it compensates for the piezospeaker's tendency to play some notes louder than others.· This is a project that will require some time, experimentation and tuning.· Good luck!

___________________________________________________________________

This draft material is part of a forthcoming Stamps in Class text by Andy Lindsay.

(c) 2004·by Parallax Inc - all rights reserved.··

Post Edited By Moderator (Jessica Uelmen (Parallax)) : 8/25/2010 6:34:21 PM GMT
549 x 502 - 225K
420 x 210 - 20K
204 x 224 - 23K
562 x 302 - 47K
219 x 286 - 16K

Comments

  • 27 Comments sorted by Date Added Votes
  • bahadurbahadur Posts: 1
    edited July 2010 Vote Up0Vote Down
    the project was great. if you can helpe me how to amplify the bazer thank you.
  • AttorneyJonAttorneyJon Posts: 10
    edited December 2010 Vote Up0Vote Down
    Hi Mr. Lindsay,

    This is a very nice project. I am new to electronics and have a few questions, if I may ask???? First, I am having trouble locating the LM358. I am going to order one from Parallax; however, I was wondering if I could substitute another IC in its place for the time being? Any idea? LM272 or 386? (I have some of those lying around.) Second, I would like to somehow combine this project with the Christmas Caroling device, to amplify the sound. BUT, I'm not quite sure how to do it. I don't think that there is enough room on the Christmas Caroling STAMP to also build this amp. Is there some way I could combine the two? Or connect two STAMPS? Any ideas for a newbie would be greatly appreciated. Thank you for your help.
  • HumanoidoHumanoido Posts: 5,770
    edited December 2010 Vote Up0Vote Down
    You can use a small speaker and the LM386 amp chip. The small amplifier sold by Radio Shack uses this chip. If you need more room, use a larger breadboard. Connecting stamps is easy. Just look at any of the BASIC Stamp Supercomputer threads.
  • AttorneyJonAttorneyJon Posts: 10
    edited December 2010 Vote Up0Vote Down
    @Humanoido:

    Thanks for your response. Radio Shack is just down the street, so I'll pay them a visit today. I'll tell them that you sent me and see if I can get YOU a discount. :)

    Thanks for your help; I appreciate it.
  • NB_NesquikNB_Nesquik Posts: 35
    edited March 2012 Vote Up0Vote Down
    @Humanoido,
    What kind of small speaker should I use, and how would I connect it to the amp chip? Would the connections be like the ones in the activity?
  • davejamesdavejames Posts: 3,887
    edited March 2012 Vote Up0Vote Down
    Hello NB,

    A small, 8 Ohm, dynamic speaker in the 1W range would suffice.

    Since the amplifier circuit is powered by a single supply, then a capacitor would need to be inserted between the output of the amp and the speaker to protect the speaker from the DC offset; value of 10uF or more would be sufficient.

    I checked Radio Shack's DIY web page and they don't seem to carry simple speakers anymore, so you may have to buy from Mouser, DigiKey, Jameco, etc.

    Regards.
    Well-written documentation requires no explanation.
  • NB_NesquikNB_Nesquik Posts: 35
    edited March 2012 Vote Up0Vote Down
    Hello davejames,
    I have a set of sony speakers with with an 8ohm impedance and power handling capacity of 0.2W rated and 0.4W max. I do not have a 10uF capacitor, but i do have a 3300uF, a 1000uF, four 0.1uF, and four 0.01uF capacitors. Could these work for this circuit? and if they do, how should they be connected?
  • davejamesdavejames Posts: 3,887
    edited April 2012 Vote Up0Vote Down
    NB - mucho sorry for the slow response!

    The 1000uF will work, put the plus (+) side toward the amplifier output, the other end to the speaker you mentioned.

    Lemme know how it works?


    ***Whoa!!! Wait - are you powering the amp from a single supply, or are you using 2 supplies (+, -)? If you're using 2 supplies, then the coupling cap will not be needed.
    Well-written documentation requires no explanation.
  • NB_NesquikNB_Nesquik Posts: 35
    edited April 2012 Vote Up0Vote Down
    I tried connecting the circuit like you said, and the speaker volume is lower than the piezo speaker. I have other power supplies that are not regulated in 6V, 9V, and 12V. I attached a picture of the actual circuit and a schematic. I dont know if there just needs to be more power or what. Any sugestions on what to do? Thanks

    photo 1.JPG
    speaker schematic.doc
    960 x 720 - 276K
  • davejamesdavejames Posts: 3,887
    edited April 2012 Vote Up0Vote Down
    NB - look at the schematic in post #1. That circuit will work. The circuit you posted won't, if it's really what you've connected. From your picture I see no resistors required for feedback. Again, replicate what was done in the first post. It should be the ticket!
    Well-written documentation requires no explanation.
  • NB_NesquikNB_Nesquik Posts: 35
    edited April 2012 Vote Up0Vote Down
    The circuit in post #1 made the volume a little higher, but is there any way to make it any louder. Right now the speaker volume is only a little louder than it was before and not really any louder than the piezo speaker. I would like the volume to be a LOT louder, so you could hear it across a noisy room, or is that even possible?
  • davejamesdavejames Posts: 3,887
    edited April 2012 Vote Up0Vote Down
    NB - my apologies. I misread the IC used in post #1 as an LM386 (power amp) instead of an LM358 (dual op-amp). That's why I couldn't understand why the circuit was not loud enough.

    There're some tricks that could be done with the LM358, but the better thing to do would be purchase an IC designed to drive a speaker, such as the LM386 (Radio Shack sells these for under $2).

    I'm sure other Forum Wizards will have suggestions for low voltage power amps.
    Well-written documentation requires no explanation.
  • NB_NesquikNB_Nesquik Posts: 35
    edited April 2012 Vote Up0Vote Down
    I have an LM386 chip, and thats what I have been using to power it all along. Sorry if I did not make that clear at first. When I was connecting it, I used the schematic and connected the proper connections to the correct pins on the LM386 chip.
  • davejamesdavejames Posts: 3,887
    edited April 2012 Vote Up0Vote Down
    ...ok then - if the 1/4 watt output of the LM386 is not enough, then you'll have to go with another power amp, and larger power supply.

    There was a previous thread on the Forum where someone was asking about preferences for single-chip power amps; late last year, earlier this year?

    One last thing about the LM386...did you set it up for its minimum gain of 20, or for more gain? If the previous .doc schematic referenced the 386, then it would appear that it was set to 20.
    Well-written documentation requires no explanation.
  • ercoerco Posts: 18,488
    edited April 2012 Vote Up0Vote Down
    A 386 can definitely put out annoyingly loud sound with the right gain, and a big enough speaker of the right impedance. Check all of those; are you sure you need more power? Do a quick test with one of these 386-based Radio Shack amps. Very handy to keep one on your bench.

    http://www.radioshack.com/product/index.jsp?productId=2062620
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • davejamesdavejames Posts: 3,887
    edited April 2012 Vote Up0Vote Down
    ...well I'll be!

    I looked through the RS site and could not find that little beauty. It was my initial thought for NB, but since I wasn't able to find it, couldn't pass on the info.

    Thanks erco!
    Well-written documentation requires no explanation.
  • ercoerco Posts: 18,488
    edited April 2012 Vote Up0Vote Down
    I'll admit, I looked on Ebay afterward to see if anyone was selling clones of these for $5. Nothing yet! I know degreed EE's that buy dozens of these and build them into projects.
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,345
    edited April 2012 Vote Up0Vote Down
    The Veho360 that Parallax sells for the same price ain't exactly chopped liver. It has nice fidelity, is adequately loud, and you don't have to feed it vast quantities of new batteries (nom nom nom burp!) if you forget to turn it off -- as I have done numerous times with my RS unit.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • ercoerco Posts: 18,488
    edited April 2012 Vote Up0Vote Down
    The Veho360 that Parallax sells for the same price ain't exactly chopped liver.-Phil

    Chopped liver & BestBuy netbooks: http://www.seriouseats.com/recipes/2010/03/the-nasty-bits-chopped-liver-recipe.html
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • davejamesdavejames Posts: 3,887
    edited April 2012 Vote Up0Vote Down
    erco wrote: »

    THAT was funny!!

    I still hate liver, though.
    Well-written documentation requires no explanation.
  • NB_NesquikNB_Nesquik Posts: 35
    edited September 2012 Vote Up0Vote Down
    I have a lm358 IC and have tested the circuit and it works. I was wondering can I make this IC control an audio signal with seperate left and right signals. I assume that I can by replicating the circuit again and wire up pins 5,6, and 7 instead of 1,2, and 3. However, that would need two potentiometers. Is there a way that this can be done while only using on potentiometer to control the volume of both signals?

    Also can this be supplied with a 12v power supply?

    Thanks
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,345
    edited September 2012 Vote Up0Vote Down
    With a single pot? No, not easily at least. The simplest way would be to use a dual ganged pot, like this one at RadioShack:

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • mdenada000mdenada000 Posts: 1
    edited December 2013 Vote Up0Vote Down
    Hi there,I am outputing sound from Arduino to a speaker and I need it to be loud. I am then attempting to build this amplifier but I can't succeed in the wiring...




    I have all the parts, however my op amp and potentiometer are different from your example.


    My OpAmp is this (it doesn't have the semicircle..): http://thumbs3.ebaystatic.com/d/l225/m/mecIGU9IUhQGLXSWqCauqmg.jpg


    My 10K Potentiometer is this: http://www.source-electronics.co.uk/RadioShack-10K-Ohm-Mini-Volume-Control

    Also instead of a Piezzo Speaker I am using a regular Speaker on pin9 and Gnd on the Arduino board.



    Any thoughts on how to hook it up?

    Thanks a lot in advance!!
  • davejamesdavejames Posts: 3,887
    edited December 2013 Vote Up0Vote Down
    Hello mdenada00 - welcome to the Forum.

    Do you have the datasheet for the AD290 you're using?
    Well-written documentation requires no explanation.
  • ergliftererglifter Posts: 1
    edited November 2014 Vote Up0Vote Down
    Hi All, i'm in an intro electrical engineering class in college and I'm trying to amplify a signal outputted from an ATMEGA 2560 to make a piezobuzzer annoyingly loud. Unfortunately, I could not obtain the LM358 op-amp the OP used. I do however have the LM386 op-amp another guy suggested and tested. Is there anyway I can use the LM386 op-amp to make it work? Do I need to make any modifications?

    Also, quick question about the potentiometer. Why are the bottom and middle terminals connected? Doesn't that not do anything since you only need it as a variable resistor (2 terminals connected). Don't understand why that extra wire is there.
  • kwinnkwinn Posts: 7,601
    edited November 2014 Vote Up0Vote Down
    Yes, the LM386 will work, in fact it was designed for audio amplification. Connecting the middle and one of the other terminals makes the potentiometer behave as a variable resistor.Post the entire circuit if you want a more detailed explanation of what is going on.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
Sign In or Register to comment.