Transistor is "deamplifying" speaker.

Hi.
I am building a simple circuit where I have a speaker (that I took from an old speaker I had) and I amplified it by following this tutorial.
My code is also very simple.

void setup()
{

pinMode(11,OUTPUT);
}

void loop()
{
for (int i=1; i<2000; i=i+5)
{
digitalWrite(11,HIGH);
delayMicroseconds(i);
digitalWrite(11,LOW);
delayMicroseconds(i);

}
}
but when I try the circuit, it is quieter than if I attach the sound output pin (pin 11) directly to the speaker.
Thank you.

Simple and wrong circuit. Its putting an unknown DC current through the speaker, which is bad news.

Don't connect an Arduino pin direct to the speaker, or you'll likely fry the Arduino pin (you may or may
not be lucky about this).

This might be a better bet: arduino uno - 8Ω speaker, what resistor values to use? - Arduino Stack Exchange

but when I try the circuit, it is quieter than if I attach the sound output pin (pin 11) directly to the speaker.

Don't do that without adding a series resistor (which will knock-down the volume by a lot). A piezo speaker/transducer is OK because it's higher impedance.

The "absolute maximum" rated current from an Arduino I/O pin is 40mA. Form [u]Ohm's Law[/u] that works out to a minimum of 120 Ohms at 5V.

[u]Here[/u] are some transistor driver circuits. "Low side" drivers are usually better. You can put a capacitor in series with the speaker to block the DC and if the speaker is too loud you can add a series resistor.

But how do I know how much Ohms my speaker is? And how do I amplify it correctly?
Thank you.

But how do I know how much Ohms my speaker is?

Most speakers are 4 or 8-Ohms. Usually it’s marked on the speaker or check the specs if you can find them. In the video you linked to the speaker was clearly marked. If you measure with a multimeter it will usually measure slightly lower than the rated impedance because your measuring the DC resistance of the voice coil.

Like I said, piezo transducers are high impedance. You can’t measure the resistance with a meter because piezos are “capacitive”. There are some 150 or 300 Ohm headphone drivers but most headphones are between 32 & 64 Ohms.

And how do I amplify it correctly?

With a proper transistor or MOSFET driver circuit or with an audio power amplifier. Or, you can use “powered” computer speakers. With a driver (or amplifier) you can use a higher voltage for even more power/loudness.

One advantage of an amplifier or amplified speakers is that you usually get a volume control.

(The only reason you can get-away with a simple driver circuit in place of a linear amplifier is that the Arduino doesn’t put-out analog.)

I don’t really get it. I’m a complete beginner and I have a couple of speakers that I got out of old speakers or Arduino kits, I don’t know if they are piezoelectric or what. I also don’t get why my transistor was "deamplifying my speakers or why I can’t connect it directly to the Arduino. Is there any way I can use 2n2222A or TIP41C transistors to amplify my speaker? If I need to add a resistor how can I amplify it?
Thank you so much for your time and patience.

Maybe you bought the wrong kit if the parts are not identified…

If you have a multimeter a piezo transducer will measure open (infinite resistance). It has AC impedance (which is not as easy to measure) but infinite DC resistance.

[u]This is a little 8-Ohm speaker[/u]. There is a magnet and a paper cone.

[u]This is a piezo transducer[/u] or “piezo speaker”. There is no magnet.

[u]This is a piezo beeper[/u] or “piezo buzzer”. They can look identical to a transducer but they have a built-in circuit to generate sound when powered with DC.

If you buy a piezo device from a cheap supplier sometimes they are described wrong and you don’t know if you’re getting a buzzer or a transducer. if you connect DC and you don’t get any sound (or if you just hear a “click”) its a transducer/speaker.

A transistor won’t make a piezo transducer louder unless you use a higher voltage. In fact, it might be a little quieter because of the voltage drop across the transistor.

With a 4 or 8 Ohm speaker, you are “pushing” the current limits of a 2N2222. If you have a higher voltage available (more than 5V) the 2N2222 should work.

So I checked and I'm pretty sure I have all three of those, I connected a piezo beeper and amplifyed it with a TIP41C transistor and it worked pretty well. I want something really loud tjough and I have what I think is something like a 8 Ohm speaker, which I took from a loudspeaker, and its much louder so, if I would attach it to the Arduino through a TIP41C transistor, would that damage anything?
Thanks again.

if I would attach it to the Arduino through a TIP41C transistor, would that damage anything?

Yes read reply #1 again

Basically you have a crappy circuit you are trying to copy.

OK.
So how would I attach it. In series with a resistor?
I am assuming that attaching it through a transistor will still damage the Arduino
Thank you.

It is not the Arduino that is damaged it is the speaker itself that will be damaged, that is what makes it a crappy circuit. The speaker should be connected to the collector of the transistor through a large capacitor to keep the DC out of it.

D.C. in a speaker pushes out the cone in a fixed direction, this pushes the coil against the end stop and damages the coil. Also it limits the movement of the coil to the zero position with zero current to the end stop, the coil ( and so the cone ) never goes to the end of the travel. Passing the signal through a capacitor removes that DC component and allows the cone to move either side of the end point.

However any current for the coil has to pass through a resistor from the collector of the transistor to the supply voltage. This cause it to waste a lot of power, in fact 75% of the power is wasted, and more is wasted due to the fact that a capacitor acts like an AC resistor who’s resistance changes with with the inverse frequency. That is at DC the resistance is very very high and drops off as the frequency increases, but in effect it is still absorbing power making it even less efficient.

If you put an analogue signal through this amplifier it would be even worse, it only works at all because you are feeding it with a square wave, so the transistor is either on or off.so that amplifier is even more rubbish with signals other than a square wave.

If I take a TIP41C transistor and connect the Base to Arduino, Collector to 9 Volts and Emitter to Speaker Positive
and Speaker Negative to ground would that be OK? I tried it and it seemed to work fine but it required a lot of voltage.

If I take a TIP41C transistor and connect the Base to Arduino, Collector to 9 Volts and Emitter to Speaker Positive
and Speaker Negative to ground would that be OK?

Depends what you mean by OK. You have what is called an emitter follower, it has no voltage gain, but does have some current gain. The voltage on the emitter ( so the voltage on your speaker ) can only ever be between 0.7 and 1.5 volts LESS than the signal you put into it. Also it has current going only one way through the speaker so the cone will only move through half the range of its travel. This in the long term will damage the speaker.

I also don't get why my transistor was "deamplifying my speakers

I think the above answers that then.
It is better if you replace deamplifying with a proper word like attenuating. Only the Simpsons say things like "enbiggen".

but it required a lot of voltage.

Where is a lot of voltage required? It would work exactly the same if you used 5V than the 9V on the collector.

OK. I have it working perfectly now, Thank you so much for your help.

virtuos1:
I also don't get why my transistor was "deamplifying my speakers or why I can't connect it directly to the Arduino.

Firstly that circuit you used was completely wrong.

Secondly you can't connect an 8 or 4 ohm speaker to an Arduino pin is because its utterly under powered
for the load - would you expect a kitten to arm-wrestle a gorilla and win?!

You need to amplify the signal current and power, passing only AC to the speaker - did you try the
circuit I linked to in my reply #1?

Hahaha I want to drive a 25 watt 8 Ohm speaker with my Arduino. Why isn’t it shaking my room I put in an emitter follower amplifier.