Projects / Small speaker driver with a transistor

Small speaker driver with a transistor

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANOS8050

    Check the pinout

    Look up the S8050 emitter, base and collector.

  2. NANO

    Wire the driver

    D9 through 1 kohm to the base, emitter to GND.

  3. NANO

    Wire the speaker

    Collector to speaker minus, speaker plus through 47 ohm to 5V.

  4. NANO

    Wire the knob

    Outer legs to 5V and GND, middle to A0.

  5. NANO

    Upload the sketch

    A scale plays on a loop.

  6. NANO

    Turn the knob

    The volume changes.

  7. NANO

    Compare with a buzzer

    The speaker is louder.

  8. NANOS8050

    Feel the transistor

    It should stay cool.

In short

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
See the electronics first. This build uses transistor switch. Try a transistor switch in the circuit builder and watch the voltages and currents before you wire it.

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Nano D91 kohm resistorThen to the S8050 base
S8050 emitterNano GNDFlat side facing you: emitter, base, collector from left to right, check your datasheet
S8050 collectorSpeaker minusLow side switch
Speaker plus47 ohm resistor then Nano 5VLimits the current
Pot outer legsNano 5V and GNDVolume knob
Pot middle legNano A0Reads 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.

CheckExpected
Knob at minimumQuiet scale
Knob at maximumLoud scale
Speaker disconnectedSilence
Transistor flippedNo sound
Resistor removedDo 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 →

Ask Lark AI

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.