Every integrated circuit on the planet, from the chip in your Arduino Uno to the processor in your smartphone, is built from billions of transistors. Understanding how a single transistor works gives you the foundation to build switching circuits, amplifiers, sensor interfaces, and motor drivers. In this guide, we will break down BJT transistors from first principles, walk through real calculations, and build practical circuits you can wire up on your breadboard today.
What Is a Transistor?
A transistor is a three-terminal semiconductor device that acts as an electrically controlled switch or amplifier. Apply a small current to one pin, and the transistor allows a much larger current to flow between the other two pins. That core idea -- a tiny signal controlling a big one -- is the reason transistors replaced vacuum tubes and became the fundamental building block of all modern electronics.
There are two broad families of transistors: BJTs (Bipolar Junction Transistors) and MOSFETs (Metal-Oxide-Semiconductor Field-Effect Transistors). This article focuses on BJTs, the easiest to understand and the most common in hobbyist circuits. We will cover MOSFETs in a comparison section later.
BJT Basics: Three Pins
A BJT has three terminals:
- Base (B) -- The control pin. A small current here turns the transistor on.
- Collector (C) -- The pin connected to the load (relay, motor, LED strip).
- Emitter (E) -- The pin connected to ground (for NPN) or supply (for PNP).
Think of a transistor as a water valve. The base current is your hand turning the tap. A tiny twist (small base current) opens the valve and lets a large flow of water (collector current) rush through the pipe. Remove your hand, and the valve snaps shut. That is exactly how a transistor switches a relay or motor on and off from a microcontroller GPIO pin.
NPN vs PNP: Current Flow Direction
BJTs come in two polarities:
| Property | NPN | PNP |
|---|---|---|
| Current flow | Into Collector, out of Emitter | Into Emitter, out of Collector |
| Base trigger | Current flows into Base | Current flows out of Base |
| Emitter connects to | Ground (GND) | Supply (VCC) |
| Switching position | Low-side (between load and GND) | High-side (between VCC and load) |
| Vbe to turn on | +0.7V (Base more positive than Emitter) | -0.7V (Base more negative than Emitter) |
| Common examples | 2N2222, BC547, 2N3904 | 2N3906, BC557 |
When to use NPN: Most switching applications. The load sits between VCC and the collector, and the transistor connects the load to ground. This is called low-side switching and is simpler to drive from a microcontroller.
When to use PNP: When you need high-side switching -- the transistor sits between VCC and the load, and the load connects to ground. Useful when the load must have one terminal permanently grounded.
Key Parameters You Must Know
Before you pick a transistor or calculate a resistor value, you need to understand these datasheet parameters:
- hFE (Current Gain): The ratio of collector current to base current. If hFE = 200 and you push 1mA into the base, the transistor can pass up to 200mA through the collector. Typical values range from 100 to 300 for small-signal transistors.
- Vbe (Base-Emitter Voltage): The voltage drop across the base-emitter junction when the transistor is on. For silicon BJTs, this is approximately 0.7V.
- Vce(sat) (Collector-Emitter Saturation Voltage): The voltage drop across the transistor when it is fully on (saturated). Typically 0.1V to 0.3V for small-signal BJTs, up to 1V for power transistors.
- Ic(max) (Maximum Collector Current): The absolute maximum current the transistor can handle. Exceed this and the transistor overheats and fails.
- Pd (Power Dissipation): Maximum power the transistor can safely dissipate as heat. Calculated as Vce x Ic. For a TO-92 package, this is typically 500mW to 625mW.
Popular Transistors: Comparison Table
| Transistor | Type | Ic(max) | hFE (typical) | Vce(sat) | Package | Best For |
|---|---|---|---|---|---|---|
| 2N2222 | NPN | 800mA | 100-300 | 0.3V | TO-92 | General-purpose switching |
| 2N3904 | NPN | 200mA | 100-300 | 0.2V | TO-92 | Low-current switching, amplifiers |
| BC547 | NPN | 100mA | 110-800 | 0.25V | TO-92 | Signal amplification, low-power switching |
| 2N3906 | PNP | 200mA | 100-300 | 0.25V | TO-92 | PNP complement to 2N3904 |
| BC557 | PNP | 100mA | 110-800 | 0.25V | TO-92 | PNP complement to BC547 |
| TIP120 | NPN Darlington | 5A | 1000+ | 2V | TO-220 | Motors, solenoids, high-current loads |
| TIP127 | PNP Darlington | 5A | 1000+ | 2V | TO-220 | High-side high-current switching |
For most Arduino and ESP32 projects, 2N2222 or BC547 will be your go-to NPN transistor. When you need to switch loads above 500mA, step up to the TIP120.
Using a Transistor as a Switch
This is the most common use case in maker projects. You want a microcontroller GPIO pin (which can only source 20-40mA) to control a device that draws much more current -- a relay, a motor, an LED strip.
Circuit 1: NPN Switching a 5V Relay from Arduino
+5V
|
[Relay Coil]
|
C
Arduino ---[Rb]--- B 2N2222
D7 E
|
GND
+ Flyback diode (1N4007) across relay coil
(cathode to +5V, anode to collector)
Components needed: 2N2222 NPN transistor, 1K ohm resistor (Rb), 1N4007 flyback diode, 5V relay module.
Calculating the Base Resistor
The relay coil draws 70mA at 5V (check your relay datasheet). We need to calculate the base resistor to ensure the transistor is fully saturated (fully on).
Step 1: Determine the required base current (Ib)
Ib = Ic / hFE x safety_factor
Ib = 70mA / 100 x 10
Ib = 7mA
We use a safety factor of 10 to ensure the transistor is driven hard into saturation. The minimum hFE for 2N2222 at 70mA is around 100, so we design for 10x the minimum base current.
Step 2: Calculate Rb
Rb = (Vgpio - Vbe) / Ib
Rb = (5V - 0.7V) / 7mA
Rb = 4.3V / 0.007A
Rb = 614 ohms
Use the nearest standard resistor value: 560 ohms or 680 ohms. A 1K ohm resistor also works for most relays since the 2N2222 typically has hFE well above 100.
Arduino Code:
const int RELAY_PIN = 7;
void setup() {
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
digitalWrite(RELAY_PIN, HIGH); // Relay ON
delay(5000);
digitalWrite(RELAY_PIN, LOW); // Relay OFF
delay(5000);
}
Circuit 2: NPN Switching a DC Motor with Flyback Diode
When switching inductive loads like motors, relays, and solenoids, you must include a flyback diode. When the transistor turns off, the collapsing magnetic field in the coil generates a voltage spike that can destroy your transistor. The flyback diode clamps this spike safely.
+12V
|
[DC Motor]
|
1N4007 diode (cathode to +12V, anode here)
|
C
Arduino ---[1K]--- B 2N2222 (or TIP120 for >500mA)
D9 E
|
GND (shared with Arduino GND)
For PWM speed control, simply use analogWrite():
const int MOTOR_PIN = 9; // PWM-capable pin
void setup() {
pinMode(MOTOR_PIN, OUTPUT);
}
void loop() {
// Ramp up speed
for (int speed = 0; speed <= 255; speed += 5) {
analogWrite(MOTOR_PIN, speed);
delay(50);
}
// Ramp down speed
for (int speed = 255; speed >= 0; speed -= 5) {
analogWrite(MOTOR_PIN, speed);
delay(50);
}
}
Important: If the motor draws more than 500mA, use a TIP120 Darlington transistor instead of the 2N2222.
Darlington Pair: TIP120
A Darlington pair is two transistors connected together so that the current amplified by the first is amplified further by the second. The result is extremely high current gain -- the TIP120 has an hFE of 1000 or more.
This means you can drive a 5A load with just 5mA of base current. The tradeoff is a higher saturation voltage: Vce(sat) is around 2V for a TIP120 versus 0.2-0.3V for a standard transistor. At high currents, this means more power dissipated as heat, so you may need a heatsink.
When to use TIP120:
- Driving DC motors (up to 5A)
- Controlling solenoids and large relays
- Driving LED strips (12V, high current)
- Any load above 500mA where you want simplicity over efficiency
Base resistor for TIP120:
Ic = 2A (motor load)
hFE = 1000 (minimum)
Ib = 2A / 1000 x 5 = 10mA (with safety factor of 5)
Rb = (5V - 1.4V) / 10mA = 360 ohms
Note: Vbe for a Darlington is approximately 1.4V (two junctions in series), not 0.7V.
Using a Transistor as an Amplifier
While switching is the most common hobbyist application, transistors were originally designed as amplifiers. In a common emitter amplifier configuration, the transistor amplifies a small AC signal (like audio from a microphone) into a larger one.
The basic idea: bias the transistor into its active region (not fully on, not fully off) using a voltage divider at the base. The small AC signal at the base modulates the larger collector current, producing an amplified version of the input signal at the collector.
+VCC
|
[Rc] (Collector resistor)
|
C
Input ---[C1]---+---[R1]--- +VCC
|
B
|
[R2]--- GND
|
E
|
[Re] (Emitter resistor for stability)
|
GND
Amplifier design is a deep topic. For hobbyist audio projects, a pre-built amplifier module (like the LM386) is usually more practical. But understanding the principle helps you read schematics and debug circuits.
NPN Low-Side vs PNP High-Side Switching
| Configuration | NPN Low-Side | PNP High-Side |
|---|---|---|
| Transistor position | Between load and GND | Between VCC and load |
| Load position | Between VCC and collector | Between emitter and GND |
| GPIO drives base | HIGH to turn on | LOW to turn on |
| Complexity | Simple -- base resistor only | Needs voltage divider if VCC > GPIO voltage |
| Use when | Load does not need grounded terminal | Load must have one terminal grounded |
| Common transistor | 2N2222, BC547 | 2N3906, BC557 |
NPN low-side switching is preferred in most cases because the base can be driven directly from a microcontroller GPIO pin. PNP high-side switching requires more care: if VCC is 12V and your GPIO is 5V, you cannot drive the PNP base directly -- you need an NPN transistor to drive the PNP, creating a two-transistor circuit.
Transistor as a Level Shifter
ESP32 operates at 3.3V logic, but many modules and sensors expect 5V signals. A single NPN transistor can convert 3.3V signals to 5V:
+5V
|
[10K] (Pull-up resistor)
|-----> 5V Output Signal
C
ESP32 ---[1K]--- B 2N3904
GPIO E
|
GND
When ESP32 GPIO is LOW, the transistor is off, and the pull-up resistor pulls the output to 5V. When GPIO is HIGH, the transistor turns on and pulls the output to GND. Note that this inverts the signal -- a HIGH input produces a LOW output. If you need non-inverted output, use two transistors in series or handle the inversion in software.
Transistor vs MOSFET: When to Choose Which
| Feature | BJT (e.g., 2N2222) | MOSFET (e.g., IRLZ44N) |
|---|---|---|
| Controlled by | Base current | Gate voltage |
| Input impedance | Low (draws current) | Very high (almost no current) |
| Switching speed | Moderate | Fast |
| Saturation voltage | 0.2-0.3V | Very low (Rds(on) x I) |
| Power dissipation | Higher at high currents | Lower at high currents |
| 3.3V GPIO drive | Works fine (current-driven) | Needs logic-level MOSFET |
| Cost | Very cheap | Slightly more expensive |
| Best for | Low-current switching, amplifiers | High-current switching, PWM motor control |
Rule of thumb: For loads under 500mA, a BJT is simple and cheap. For loads above 500mA, especially with PWM, a logic-level MOSFET (like IRLZ44N or IRLB8721) is more efficient because it wastes less power as heat.
Transistor Packages
| Package | Typical Ic(max) | Power Dissipation | Size | Examples |
|---|---|---|---|---|
| TO-92 | Up to 800mA | 500-625mW | Small, 3 leads | 2N2222, BC547, 2N3904 |
| TO-220 | Up to 10A+ | 2W+ (with heatsink: 65W+) | Large, tab for heatsink | TIP120, TIP31, BD139 |
| SOT-23 | Up to 500mA | 250-350mW | Tiny SMD | MMBT2222, MMBT3904 |
TO-92 is what you will use on breadboards. TO-220 is for power applications where you bolt a heatsink to the tab. SOT-23 is the surface-mount equivalent of TO-92 for PCB designs.
Critical note: Pin order varies between packages and even between manufacturers. The 2N2222 in a TO-92 package has pins ordered E-B-C (flat side facing you, left to right), but the BC547 is C-B-E. Always check the datasheet.
Reading Transistor Datasheets
When you get a new transistor, here is what to look for in the datasheet:
- Pinout diagram: Which pin is B, C, E. Do not guess -- check every time.
- Absolute Maximum Ratings: Ic(max), Vce(max), Pd(max). Never exceed these.
- hFE vs Ic graph: hFE changes with collector current. At very low and very high currents, gain drops. Design for the minimum hFE at your operating current.
- Vce(sat) vs Ic: Tells you the voltage drop (and therefore power loss) when switching.
- Safe Operating Area (SOA): A graph showing the safe combinations of Vce and Ic. Stay inside this area or the transistor will overheat.
- Thermal resistance: Tells you how hot the junction gets per watt of dissipation. Combined with Pd, this determines if you need a heatsink.
Common Mistakes to Avoid
1. No base resistor Connecting a GPIO pin directly to the base with no resistor creates a short circuit through the base-emitter junction. The junction drops only 0.7V, so the GPIO tries to source excessive current. This can destroy the transistor and damage your microcontroller. Always use a base resistor (typically 1K to 10K ohm).
2. Wrong pinout The 2N2222 has E-B-C pinout. The BC547 has C-B-E. The TIP120 has B-C-E. Swapping pins means the circuit either does not work or the transistor overheats. Check the datasheet for every transistor you use.
3. Exceeding power dissipation A TO-92 transistor can dissipate about 500mW. If your transistor passes 200mA with a 3V Vce drop, that is 600mW -- it will overheat. Either reduce Vce by ensuring full saturation or use a TO-220 package.
4. No flyback diode on inductive loads Relays, motors, and solenoids generate voltage spikes when switched off. Without a flyback diode (1N4007 or 1N4148), these spikes will kill your transistor. This is the number one cause of "my transistor randomly died."
5. Using a BJT where a MOSFET is better If you are switching 2A+ loads with PWM, a BJT wastes significant power as heat. Switch to a logic-level MOSFET for better efficiency.
Practical Projects
Project 1: Dark-Activated Night Light
Use an LDR (Light Dependent Resistor) and a BC547 transistor to automatically turn on an LED when it gets dark.
+5V
|
[LDR]
|
+-------> B (BC547) ---[1K]--- to +5V through LED
|
[10K] C ---[330R]--- LED --- +5V
| E --- GND
GND
When light hits the LDR, its resistance drops (around 1K ohm), pulling the base low -- transistor stays off. In darkness, the LDR resistance rises (100K+ ohms), the voltage divider pushes the base above 0.7V, and the transistor turns on the LED.
Project 2: Touch Sensor
Your body acts as a weak antenna, picking up 50Hz mains hum. A Darlington pair (or TIP120) has enough gain to amplify this tiny signal and switch an LED.
Touch Wire ----> B (TIP120)
C ---[330R]--- LED --- +5V
E --- GND
Touch the wire and the LED lights up. This works because the TIP120 has a gain of 1000+, amplifying the microamp-level signal your finger provides into enough current to light an LED.
Project 3: Simple Audio Amplifier
Use a 2N3904 in common emitter configuration to amplify an electret microphone signal:
+5V
|
[4.7K] (Rc)
|----> Output to speaker/amplifier
C
Mic+ ---[10uF]---+---[100K]--- +5V
|
B 2N3904
|
[100K]--- GND
|
E
|
[1K] (Re)
|
GND
This provides a voltage gain of approximately Rc/Re = 4.7K/1K = 4.7x. For higher gain, add a bypass capacitor across Re. For practical audio amplification, you will want to follow this with an LM386 amplifier module for speaker-level output.
Summary
Transistors are the most versatile components in electronics. With just a few rupees worth of parts, you can switch motors, drive relays, amplify signals, shift voltage levels, and build sensor circuits. Start with a pack of 2N2222 (NPN) and 2N3906 (PNP) transistors, a handful of resistors, and some 1N4007 diodes. These will cover 90% of your project needs.
Key takeaways:
- NPN for low-side switching (most common) -- connect load between VCC and collector, emitter to ground
- Always calculate your base resistor -- Rb = (Vgpio - 0.7V) / Ib, where Ib = Ic / hFE x safety factor
- Always use a flyback diode on inductive loads (motors, relays, solenoids)
- Check the pinout in the datasheet -- never assume pin order
- Use TIP120 for loads above 500mA, or switch to a MOSFET for better efficiency
- Stay within power limits -- Pd = Vce x Ic must be below the package rating
Browse our full range of transistors, resistors, diodes, and development boards at wavtron.in to get started on your next project.



