part · Level 3 · Sense · active

How a 2N2222 transistor switches

NPN transistor (2N2222) — An electric switch flipped by electricity — a tiny current controls a big one.

What it is

A transistor is an electrically controlled switch: a small current into one leg lets a much larger current flow between the other two. No moving parts, and it can switch millions of times a second. Every chip you own is made of them; the 2N2222 is one on its own, in a little black half-cylinder.

Three legs. Hold the flat face toward you, legs down: left to right they are Emitter, Base, Collector. The emitter goes to battery −. The collector goes to whatever you want to switch (through it to +). The base is the control input.

Yours is an NPN type. Push a little current into the base and current flows from collector to emitter. Stop, and it stops. It is the part that lets a sensor divider — which can only supply a fraction of a milliamp — run an LED or a buzzer.

How it works

The 0.7 V rule. The base-to-emitter junction is a diode. Below about 0.7 V nothing happens; above it the base conducts and the transistor turns on. So any voltage divider that swings past 0.7 V can drive it.

Gain. Collector current is roughly the base current times the transistor's gain (hFE, or β) — 100 to 300 for a 2N2222; the site's simulations use 200. To pass 11 mA to an LED you need only 11 ÷ 200 ≈ 0.055 mA into the base.

Base resistor. Divider middle at 1.0 V, 1 kΩ to the base: base current = (1.0 − 0.7) ÷ 1000 = 0.3 mA. Times 200 is 60 mA of possible collector current — far more than the 11 mA the LED lane allows. So the transistor is saturated: fully on, acting like a closed switch with only about 0.1–0.3 V left across it. Saturated is what you want for a switch; it runs cool and the load gets nearly the whole 4.5 V.

Load current. With the LED lane on the collector: 4.5 − 2.0 (LED) − 0.2 (saturated transistor) ≈ 2.3 V across 220 Ω → ≈ 10.5 mA. With an active buzzer (≈ 150 Ω): (4.5 − 0.2) ÷ 150 ≈ 29 mA. Both trivial against the 600 mA maximum.

Limits. Keep the collector under 600 mA and never let the collector–emitter voltage exceed 40 V (you are at 4.5 V, far below it). Never connect the base straight to + without a resistor: (4.5 − 0.7) ÷ 0 Ω is a dead transistor.

The numbers

Pinout (flat face toward you)E – B – C — emitter to −, collector to the load
Base turn-on voltage≈ 0.7 V
Gain (hFE)100 – 300 — sims use 200
Max collector current600 mA — P2N2222A datasheet
Saturation voltage (C–E)≈ 0.1–0.3 V — at your currents
Base current from 1.0 V via 1 kΩ0.3 mA

manufacturer datasheet ↗

See it working

The Automatic Night Light circuit, simulated live. Open it on the Workbench to change anything.

simulating…

🔧 Open this circuit in the Workbench →

Mistakes everyone makes

  • Pins swapped. The transistor either does nothing or is weakly on backwards. Fix: flat face toward you, E-B-C left to right; the emitter is the leg nearest the flat face's left edge.
  • No base resistor. A divider dragged down to 0.7 V, or a base fried from a direct + connection. Fix: 1 kΩ between whatever drives the base and the base pin.
  • LED on the collector with no 220 Ω. The transistor happily passes 600 mA — the LED will not. Fix: the LED lane keeps its own resistor.
  • Load on the emitter instead of the collector. The transistor never saturates and the load gets 0.7 V less than expected. Fix: emitter to −, load between + and the collector.
  • Expecting it to switch a motor without a diode. Motor kickback can exceed the 40 V rating. Fix: 1N4001 across the motor, banded end to +.

Questions people ask

What is the pinout of a 2N2222?
For the common TO-92 plastic package (P2N2222A): flat face toward you, legs pointing down, left to right is emitter, base, collector. Metal-can versions differ — check the datasheet.
How much base current does a 2N2222 need?
Collector current divided by the gain, about 200. To switch an 11 mA LED you need about 0.06 mA; to be safely saturated give it several times that — 0.3 mA through a 1 kΩ from a 1 V source is plenty.
Can a 2N2222 drive a buzzer or a small motor?
An active buzzer at 30 mA, easily. A small DC motor at 100–300 mA is within the 600 mA rating but the transistor will warm up, and you must add a flyback diode across the motor.

Projects that use this part

  • 🌙 Automatic Night Light — A light that switches itself on when the room gets dark — no hands, no code. L3 · 35 min
  • 🌅 Sunrise Alarm — The night light — flipped. Swap two parts and the LED wakes up with the sun instead. L3 · 25 min
  • 🍪 Cookie Jar Alarm — The Sunrise Alarm's brain wired to a buzzer instead of a lamp — quiet in the dark jar, screaming when the lid comes off. L3 · 25 min
  • 🪤 Trip Wire Alarm — A thin wire across a doorway holds the alarm silent. Break the wire and the buzzer screams — until you connect it back. L3 · 25 min
  • 🌡️ Warm Hand Alarm — Cup your hand over the sensor and the LED lights up — a thermometer that turns into a switch. L3 · 30 min
  • 📖 Reading Light — The Automatic Night Light with a knob on top — turn it to dial in how dark the room has to get before the lamp fires. Your first tunable threshold. L3 · 30 min
  • 🏝️ Vacation Nightlight — The Automatic Night Light with a manual override — flip the slide switch off and the lamp stays dark even in a pitch-black room. L3 · 25 min
  • 📚 Study Lamp — The Automatic Night Light with a force-on override — flip the slide switch and the lamp stays lit even in daylight, ignoring the sensor. L3 · 25 min
  • 🌆 Curfew Beeper — The Automatic Night Light's brain with a buzzer where the LED used to sit — beeps the moment the room goes dark, so you never miss sunset. L3 · 30 min
  • 🤒 Fever Beeper — The Warm Hand Alarm's brain wired to a buzzer instead of a lamp — silent in a normal room, beeping the second a warm palm covers the sensor. L3 · 25 min
  • 🌇 Dusk Chorus — The Curfew Beeper with a red LED wired in parallel with the buzzer — one dusk sensor drives a chime and a lamp at the same time. L3 · 30 min
  • 🎺 Warm Hand Chorus — Fever Beeper with a red LED added in parallel with the buzzer — one warm-hand sensor drives a chime and a lamp at the same time. L3 · 30 min
  • 💨 Handheld Fan — Press the button, the fan spins. A tiny finger current commands a hundred-milliamp motor through a transistor. L4 · 20 min
  • 🌞 Sunrise Fan — Sunrise Alarm with the LED swapped for a motor. The sun rises, the fan starts — an automatic wake-you-up desk breeze. L4 · 25 min
  • 🆘 Panic Fan — Two buttons, either one fires the fan. Panic Doorbell wearing a motor — an OR gate that spins. L4 · 20 min
  • 🎉 Party Spinner — One button, three mouths: a spinning motor, a red LED, and a buzzer all fire together. One transistor drives them all. L4 · 25 min
  • 🚗 Twin Wheels — Two motors from one button — a Level 9 robot drivetrain, five levels early. L4 · 25 min
  • 🎚️ Dial-a-Spin — Dial-a-Brightness with a motor instead of an LED. Twist the knob and watch the fan speed slide from full spin to a slow crawl. L4 · 20 min
  • 🕸️ Trip Wire Fan — Trip Wire Alarm's brain wearing a motor. The wire is intact — the fan is silent. Snap it — the fan spins as the alarm. L4 · 25 min

verified against: onsemi — P2N2222A datasheet · SparkFun — Transistors · Kuphaldt — Lessons in Electric Circuits, Bipolar Junction Transistors