Learning Goals 5 min
Yesterday you learned that an Arduino pin cannot drive a motor. Today you build the cheapest fix in the world: a single transistor that lets a small Arduino current control a much bigger motor current. By the end of this lesson you will:
- Wire an NPN BJT (2N2222 or BC547) as a one-direction motor switch, with the correct base resistor and a shared ground between the Arduino and a 4 × AA pack.
- Identify the three legs of a TO-92 transistor — base, collector, emitter — and tell "flat side towards you" left-to-right as B-C-E or E-B-C depending on the part (it's different for 2N2222 vs BC547, and the difference matters).
- Predict and observe the symptoms of two common mis-wirings: the resistor on the collector instead of the base, and the transistor used "upside-down" (collector and emitter swapped).
Warm-Up 10 min
Bring out the small black plastic part: a 2N2222 or BC547. Hold it with the flat face towards you. It has three pins, slightly bent outward — these are the transistor's legs.
Find the datasheet for your part
The two most common classroom transistors have different pinouts even though they look identical:
| Transistor | Flat side facing you, left → right |
|---|---|
| 2N2222 (TO-92) | Emitter — Base — Collector (E-B-C) |
| BC547 | Collector — Base — Emitter (C-B-E) |
| S8050 / S9013 | Emitter — Base — Collector (E-B-C) |
Always double-check the datasheet for your exact part. Wiring a transistor backwards (collector and emitter swapped) won't destroy it immediately, but the motor will refuse to drive properly. (We'll demonstrate this on purpose in §5.)
What does "NPN" mean?
Bipolar transistors come in two flavours: NPN and PNP. We're using NPN today because:
- NPN turns ON when the base is pulled up to ~0.7 V above the emitter. That matches an Arduino "HIGH" (5 V) → base on.
- PNP would turn on when the base is pulled down below the emitter — also possible but less convenient with an Arduino's 0 V / 5 V outputs and a positive supply rail.
For the rest of Cluster B, "transistor" means "NPN BJT" unless we say otherwise. MOSFETs (the other kind) come up briefly in L03-09 as a higher-power alternative.
New Concept · The low-side switch 25 min
What "low-side" means
The motor is connected between the battery + and the transistor's collector. The transistor sits between the motor and ground — i.e. on the "low side" of the load. When the Arduino sets the base HIGH, the transistor conducts (collector-to-emitter ON) and current flows: battery+ → motor → transistor → battery−. When the Arduino sets the base LOW, the transistor is off and no current flows.
| Connection | Why |
|---|---|
| Motor + lead → Battery + | Power for the motor comes from the pack, never from the Arduino. |
| Motor − lead → Transistor collector | The transistor is the "valve" that enables / disables the current path. |
| Transistor emitter → Battery − | Current returns to the negative battery terminal. |
| Battery − → Arduino GND | Common ground — without this, the base voltage has no reference. |
| Arduino digital pin → 1 kΩ resistor → Transistor base | Resistor limits base current to a safe ~4 mA. |
Why a resistor on the base, not the collector?
The base is the input. Without a resistor, the Arduino pin would source as much current as the base wants to swallow — potentially tens of mA — and you'd damage either the pin, the transistor, or both. A 1 kΩ resistor caps the base current at (5 V − 0.7 V) / 1000 Ω ≈ 4 mA, well within the pin's 20 mA comfort zone and plenty to fully turn on a small NPN.
Putting the resistor on the collector instead would limit the motor current — defeating the whole point.
The full wiring diagram (in words)
- Battery pack's red wire → breadboard's + rail.
- Battery pack's black wire → breadboard's − rail.
- Breadboard's − rail → Arduino GND (the common ground).
- Motor red lead → breadboard's + rail.
- Motor black lead → transistor's collector (rightmost pin on a 2N2222, leftmost on a BC547 — check yours!).
- Transistor emitter → breadboard's − rail.
- Transistor base → 1 kΩ resistor → Arduino digital pin (let's use D9).
The sketch — simplest possible
// L03-06 · Transistor as a switch — minimum viable
const int MOTOR_GATE = 9;
void setup() {
pinMode(MOTOR_GATE, OUTPUT);
}
void loop() {
digitalWrite(MOTOR_GATE, HIGH); // base HIGH → transistor on → motor spins
delay(2000);
digitalWrite(MOTOR_GATE, LOW); // base LOW → off → motor stops
delay(2000);
}Two seconds on, two seconds off, forever. The Arduino sources only a few mA through the base resistor; the motor pulls ~500 mA from the AA pack. The Arduino never sees the motor current.
Worked Example · Build the one-direction switch 25 min
Step 1 — assemble on the breadboard
Follow the wiring list from §3 carefully. Use the breadboard's power rails for the battery pack so you don't accidentally short the AAs across the breadboard.
Step 2 — sanity test before you plug in the Arduino
With the Arduino unplugged, briefly touch the base resistor's free end (the one that will go to D9) directly to the breadboard's + rail. The motor should spin. Then touch it to the − rail (or leave it floating). The motor should stop.
If both states work, the transistor + motor + battery side is correct. If neither state spins the motor, check:
- Battery has juice (multimeter reads ~6 V across the pack).
- Motor wires are firmly in the breadboard.
- Transistor orientation matches your part's datasheet.
Step 3 — plug in the Arduino, upload the sketch
Connect the base resistor's free end to D9. Connect Arduino GND to the breadboard − rail (common ground!). Upload the sketch from §3. The motor should spin for 2 seconds, stop for 2 seconds, repeat.
Step 4 — try PWM (gentle preview)
Replace the body of loop() with:
for (int duty = 0; duty <= 255; duty += 5) {
analogWrite(MOTOR_GATE, duty);
delay(50);
}
for (int duty = 255; duty >= 0; duty -= 5) {
analogWrite(MOTOR_GATE, duty);
delay(50);
}The motor should ramp from stopped to full speed and back. PWM on the base (works because D9 is a PWM pin) flicks the transistor on and off thousands of times per second; the motor responds to the average voltage. You'll explore this properly in L03-09.
Step 5 — observe the brush noise
Bring an FM radio close to the motor while it spins (or watch your Arduino's on-board LED). You'll likely hear / see noise — small EM bursts from the motor brushes. That's the brush noise from L03-05; it'll be one of the reasons we put decoupling caps on the supply in L03-08.
Step 6 — deliberately break the wiring (educational)
Try these one at a time, take note of what changes, then fix it back:
| Change | What you should see | Why |
|---|---|---|
| Remove the common ground (Arduino GND wire to − rail) | Motor barely spins, or doesn't respond to the pin at all | The transistor's base voltage has no shared reference — base "HIGH" isn't HIGH compared to the emitter |
| Swap collector and emitter | Motor may spin weakly even when HIGH, or behave erratically | The transistor works in "inverse" mode — much lower gain, much worse switch |
| Move the resistor to the collector side | Motor barely turns even when HIGH | You're now limiting the motor current to ~5 mA — far below what it needs to spin |
Always restore the correct wiring before moving on. These mis-wirings won't blow anything up immediately, but they give you a feel for "what does wrong look like" — useful for next time something doesn't work.
Try It Yourself 15 min
Goal: Add a button on D2 (with INPUT_PULLUP) so the motor spins only while the button is pressed. Press = spin, release = stop.
Hint
const int BTN = 2;
void setup() {
pinMode(MOTOR_GATE, OUTPUT);
pinMode(BTN, INPUT_PULLUP);
}
void loop() {
bool pressed = (digitalRead(BTN) == LOW);
digitalWrite(MOTOR_GATE, pressed ? HIGH : LOW);
}This is the "dead-man's switch" pattern — useful for student-built tools (drill, fan, anything spinny) where the motor should stop the moment the user lets go.
Goal: Read a potentiometer on A0 and use it to set the motor's PWM duty cycle live — a one-direction electronic throttle.
Hint
int pot = analogRead(A0); // 0..1023
int duty = map(pot, 0, 1023, 0, 255);
analogWrite(MOTOR_GATE, duty);You'll notice the motor only starts spinning above some minimum duty (~30–60), because friction + back-EMF mean small voltages aren't enough to overcome stiction. This is the "dead-band" we tackle in L03-09.
Goal: Combine the previous two: button to enable, pot to control speed. If the button is released, motor is OFF regardless of the pot. If pressed, motor runs at the pot-controlled duty.
Hint
bool enabled = (digitalRead(BTN) == LOW);
int pot = analogRead(A0);
int duty = enabled ? map(pot, 0, 1023, 0, 255) : 0;
analogWrite(MOTOR_GATE, duty);Now you have a finished "variable-speed dead-man switch". Real consumer drills work exactly like this — speed dial + trigger.
Mini-Challenge · Photograph and label your build 10 min
- Take a clear photo of your breadboard from above, with the Arduino + battery pack visible.
- On paper (or with annotation software), label every component: motor, transistor, base resistor, battery+ rail, battery− rail, common ground wire, Arduino GND, Arduino D9.
- Add an arrow showing the motor current path (battery+ → motor → transistor → battery−). Add a second arrow showing the control current path (Arduino D9 → resistor → base).
- Annotate where you'll add the flyback diode tomorrow (L03-07). Just a labelled spot, not the part itself.
This labelled photo is documentation. Stick it in your engineering notebook. If your build breaks next week, you'll have a reference to compare against.
Recap 5 min
An NPN BJT in a low-side configuration is the simplest legal motor switch: Arduino pin → resistor → base; collector goes to one end of the motor, emitter to the battery negative, common ground between the two supplies. digitalWrite(HIGH) closes the "valve", current flows, motor spins; LOW opens it, motor coasts. analogWrite() on a PWM pin gives you speed control. We can drive the motor in one direction only — reversing requires the H-bridge of L03-08. And we haven't protected the transistor yet from the motor's inductive kick — that's tomorrow's flyback-diode lesson.
- BJT (bipolar junction transistor)
- A three-terminal current-controlled switch. NPN turns on when its base is pulled ~0.7 V above its emitter; PNP turns on when its base is pulled below its emitter.
- Base, collector, emitter
- The three terminals of a BJT. The base is the control input; the collector-emitter path is the switched output.
- Low-side switch
- A transistor placed between the load and ground (vs "high-side" between supply and load). Easiest for NPN BJTs with a positive supply.
- Base resistor
- A resistor (typically 1–10 kΩ) between the controlling logic pin and the transistor's base. Limits the base current to a safe level.
- Saturation
- When a transistor is fully on — minimum voltage drop, maximum current passes. You want a switch to be either saturated (fully on) or fully off; the in-between region wastes power.
- Common ground
- Connecting the negative terminals of multiple power supplies (Arduino USB, motor pack) so that signals from one have a shared reference at the other.
- Dead-man's switch
- A control scheme where the actuator (motor, magnet) is on only while a button is held — releasing the button kills the motion. Used in tools, kart pedals, industrial saws.
Homework 5 min
- Save the "button + pot + transistor" sketch from §5 as
motor-throttle.ino. We'll extend it tomorrow with proper flyback protection. - Look up the datasheet for the transistor you used. Find the maximum collector current rating (often called IC(max)). Most small-signal NPNs handle ~600 mA – 1 A. Is your motor's stall current within that limit? If not, you need a bigger transistor or a MOSFET (more in L03-08).
- Bring tomorrow: one rectifier diode (1N4148, 1N4001, or any 1 A general-purpose diode). The 1N4001 is the most common "flyback" diode in classroom kits — fine for small motors.
Bring back next class:
- Your working motor-throttle build, still wired on the breadboard (don't tear it down).
- The diode for L03-07.
- Your annotated photo from §6.