Small speaker driver with a transistor
Build it step by step
0 of 8 doneCheck the pinout
Look up the S8050 emitter, base and collector.
Wire the driver
D9 through 1 kohm to the base, emitter to GND.
Wire the speaker
Collector to speaker minus, speaker plus through 47 ohm to 5V.
Wire the knob
Outer legs to 5V and GND, middle to A0.
Upload the sketch
A scale plays on a loop.
Turn the knob
The volume changes.
Compare with a buzzer
The speaker is louder.
Feel the transistor
It should stay cool.
How do you build a small speaker driver with a transistor?
A transistor boosts a board's tone output so a small speaker plays louder, with a volume knob. You need Arduino Nano, S8050 NPN transistor, Resistor 1 kΩ, Speaker 8 Ω 0.5 W, Resistor 47 Ω, Potentiometer 10 kΩ and Breadboard 830 Tie Points. It takes 8 steps and about 75 minutes.
- Level
- Beginner
- Time
- About 75 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SemiconductorsBuy
- PassivesBuyResistor 1 kΩ × 1
- Motors & ActuatorsBuy
- PassivesBuyResistor 47 Ω × 1
- PassivesBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Nano D9 | 1 kohm resistor | Then to the S8050 base |
| S8050 emitter | Nano GND | Flat side facing you: emitter, base, collector from left to right, check your datasheet |
| S8050 collector | Speaker minus | Low side switch |
| Speaker plus | 47 ohm resistor then Nano 5V | Limits the current |
| Pot outer legs | Nano 5V and GND | Volume knob |
| Pot middle leg | Nano A0 | Reads the volume |
Code
A microcontroller pin can only supply about 20 milliamps, which is far too little for an 8 ohm speaker. This build uses an S8050 transistor as a switch: a small current from the pin through a 1 kilohm resistor into the base lets a much larger current flow from the collector to the emitter through the speaker. A 47 ohm resistor in series with the speaker limits the current to under 100 milliamps so the speaker and the transistor stay within their ratings. Never connect an 8 ohm speaker straight to a board pin, or to 5 volts without a resistor. The sketch makes the tone itself as a square wave and changes how long the signal stays high in each cycle. A short high time gives the speaker less power and a quieter sound, so the pot works as a volume knob without any extra parts in the audio path. The sound is a plain buzzy square wave and is not high-fidelity, but it is much louder than a buzzer on a pin. Keep your ear away from the speaker at the highest setting.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int OUT = 9, POT = A0;
const int NOTES[] = {262, 294, 330, 349, 392, 440, 494, 523}; // C major scale
const int N = 8;
// Play one note as a square wave. The duty cycle sets the volume: a shorter high
// time gives less power to the speaker.
void playNote(int freq, int ms, int dutyPercent) {
long period = 1000000L / freq; // microseconds
long high = period * dutyPercent / 100;
long cycles = (long)freq * ms / 1000;
for (long i = 0; i < cycles; i++) {
digitalWrite(OUT, HIGH);
delayMicroseconds(high);
digitalWrite(OUT, LOW);
delayMicroseconds(period - high);
}
}
void setup() {
pinMode(OUT, OUTPUT);
digitalWrite(OUT, LOW);
}
void loop() {
for (int i = 0; i < N; i++) {
int duty = map(analogRead(POT), 0, 1023, 5, 50); // 5 to 50 percent
playNote(NOTES[i], 300, duty);
delay(60);
}
delay(800);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Knob at minimum | Quiet scale |
| Knob at maximum | Loud scale |
| Speaker disconnected | Silence |
| Transistor flipped | No sound |
| Resistor removed | Do not do this, speaker and transistor can overheat |
If it does not work
No sound
Check the transistor orientation and the base resistor.
Very quiet
Check the speaker connections and turn the knob up.
Distorted
Normal for a square wave, lower the volume.
Transistor hot
The 47 ohm resistor is missing or the pins are wrong, unplug at once.
Nano resets
Power from a better USB port.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the small speaker driver with a transistor?
Arduino Nano, S8050 NPN transistor, Resistor 1 kΩ, Speaker 8 Ω 0.5 W, Resistor 47 Ω, Potentiometer 10 kΩ and Breadboard 830 Tie Points.
How long does the small speaker driver with a transistor take to build?
About 75 minutes for a beginner maker, in 8 steps.
How do I know the small speaker driver with a transistor works?
Knob at minimum: Quiet scale. Knob at maximum: Loud scale. Speaker disconnected: Silence.
No sound: what should I check?
Check the transistor orientation and the base resistor.
Very quiet: what should I check?
Check the speaker connections and turn the knob up.
Distorted: what should I check?
Normal for a square wave, lower the volume.
Transistor hot: what should I check?
The 47 ohm resistor is missing or the pins are wrong, unplug at once.
