Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Exhibition / Re: 1khz Sine Wave Generator on: December 17, 2010, 03:13:10 am
There is a great example, that I found more clear, at
2  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Real Speaker (not Piezo) on: October 09, 2010, 05:10:12 pm
Thanks, Osgeld!  

I decided to try using multiple Arduino pins to direct more current through the speaker.  Since it didn't need any more parts, I was able to implement this idea quickly (and without spending another $10 on an unpowered 1.5W speaker).  

With four pins on each side high/low (eight total), it seems to work.  Of course, it uses up a lot of pins, and the volume still isn't great (0.2 W max out of 1.5 W possible for the speaker), but it was really easy.  

I see how to use a capacitor and either four SCRs or four transistors to get the same power with just three Arduino pins.  But I don't have the parts right now.  

For the benefit of anybody else looking for easy ways to get decent (not great) volume out of an Arduino with a small speaker and minimal extra parts, I'll sketch out my calculations and some code below.  

* A single pin is limited to 40 mA current on the Arduino.  Groups of pins are also limited, but importantly the ground pin itself is limited to 200 mA current.  So that's basically the upper bound.  

* With a single pin and 40 mA current through an 8 Ohm speaker, the power into the speaker is P = I^2 R ~= 0.013 W.  To get this current, a resistor with value (5 V / 0.04 A) - 8 Ohms = 117 Ohms is needed in series with the speaker.

* With four pins and 160 mA current through the same speaker, the power is 0.20 W --- still well below the max of 1.5 W, but 16 times more than before.  A 23.25 Ohm resistor is needed.  

* The circuit connects pins 3,4,5,6 to each other, and pins 8,9,10,11 to each other.  To avoid any short circuits, it is important to switch every pin in the group simultaneously---so you can't use digitalWrite() one pin at a time.  Here is some sample code:

PORTB |= B1111;      // PORTB references pins 8 through 13, B1111 represents 1111 in binary, thus this command turns on pins 8,9,10,11

Basic loop:
PORTB ^= B1111;        // toggle the state of pins 8-13
PORTD ^= B111100; // PORTD references pins 0 through 7 (0 and 1 are for TX and RX, so I start with 2)

By alternating between having 8-11 HIGH, 3-6 LOW; and 8-11 LOW, 3-6 HIGH, this code generates square waves.  (It is important to alternate back and forth for volume, so the speaker is pushed in both directions.)  

Using 5 pins would in theory increase the power another 50%, while pushing the Arduino's current to its absolute maximum.  The appropriate resistance to add is 17 Ohms.  But I ran out of low-value resistors, and couldn't get the effective resistance any lower than 23 Ohms.
3  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Real Speaker (not Piezo) on: October 08, 2010, 04:05:11 pm
The speaker has that 1.5W, 8 ohms rating.
P = I*V,  V = I*R, and so P = V2/R   or...
1.5 = V2/8
12 = V2
3.5 = V  (approximately.)
So you don't need more than 3.5V to drive the speaker.  110V would make sparks and let the magic smoke out.
On the other hand, back to P=I*V, or 1.5 = I * 3.5 gives us
I = 1.5/3.5 = 0.43A, more than 10 times the current output of the Arduino.  That's why you need the resistor as well.
With an appropriate limit of 40mA, you'd get P = I^2R or about 0.01W... (additional power dissipated in the resistors.)

You could get some louder by connecting multiple pins to multiple resistors before connecting the speaker, adding their total current capability.

Cheap powered speakers are so common and cheap these days that they're probably a better route.

Thanks very much for spelling it out for me!  That's very helpful.  It makes a lot of sense.  Up here in Canada, things tend to be ridiculously overpriced---you don't want to know what I paid for this speaker---but I will see if I can find a powered one.  
4  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Real Speaker (not Piezo) on: October 08, 2010, 04:03:38 pm
The simplest way is to use a transistor, with a lowish collector resistor say 100R. Then couple it into the speaker with a capacitor. That will stop excessive DC current through the coils but still allow AC to get through. The bigger the capacitor the louder it will be. Start off with 1uF.

Excuse the stupid question, but why not only use DC current?  Does that harm the speaker?  So far I have only used DC and it is working fine, just too quiet.  (Thus the circuit is resistor from ground to a transistor controlled by the Arduino pin, to the speaker, to the + end of a 9V battery.)  
5  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Real Speaker (not Piezo) on: October 07, 2010, 05:22:54 pm
Oops, we keep posting over each other.  Active speakers is a good idea, too, I will see if I can find some around.  
6  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Real Speaker (not Piezo) on: October 07, 2010, 05:21:32 pm
Thanks Grumpy_Mike.  I saw that you posted similar advice here but didn't appreciate it.  

I still find this very confusing, and Google/Wikipedia aren't a great teachers. smiley  

It sounds like I should be hooking up 120 VAC to the speaker, using an NPN transistor and a strong capacitor to control with the Arduino.  I will have to look a lot more into "push-pull circuits" because I don't want to screw up 120 VAC.  
7  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Real Speaker (not Piezo) on: October 07, 2010, 05:12:33 pm
Thanks for your advice.  I was hoping to avoid that because I don't have good access to electronics stores here, but if that's what it takes I'll do it.  

Shouldn't the volume only be a function of the current going through the speaker, though?  It seems like it should be really easy to max out this current with a 9V battery separate from the Arduino.  I guess I don't understand how an amplifier would work better.  
8  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Real Speaker (not Piezo) on: October 07, 2010, 10:43:45 am
Here is a related question:

I picked up an 8 Ohm, 1.5W speaker.  Connecting it to the Arduino, powered over USB, it is just too quiet even with very low resistance.  Are there any simple, cheap options for making it louder?  

* I don't care about sound quality, I am only driving square waves.  
* Also, it doesn't need to be that much louder.  The volume of my alarm clock radio would be fine.  (I opened it up and it uses a 16 Ohm, 1.5W speaker, but on 120 VAC of course.)  

Would a 0.5W speaker be louder?  If I used 9V power to the Arduino, would that get louder?  Any simple amplifier solutions when quality is totally irrelevant?  

Hmm, maybe I should hook up a 9V battery to the speaker, with some resistance, and somehow use an SCR to switch it on and off quickly.  Does that sound reasonable?  To avoid blowing out the speaker, I guess I should choose R so that I=9V/R makes P = I^2 * 8Ohm < 1.5W?  Thus R around 20 Ohms total (counting the speaker's impedance).  Can this hurt the Arduino at all?  
Pages: [1]