Transistors
Using NPN transistors and Darlington pairs as GPIO-driven switches for higher-power loads in cockpit builds.
An ESP32 GPIO pin can safely source or sink around 12 mA (absolute maximum 40 mA). That is enough for a single indicator LED with a series resistor, but not for:
An NPN transistor acts as an electrically controlled switch: a tiny base current from the GPIO (limited by a resistor) allows a much larger collector-to-emitter current to flow. The load runs from a separate power rail — the GPIO only provides the control signal.
The transistor sits on the low side of the load (between load and GND). The load connects from the positive supply rail to the collector; the emitter goes to GND. When the GPIO is HIGH the base current turns the transistor on and current flows through the load.
Base Resistor Calculation
The base resistor limits the current into the base so the GPIO is not overloaded:
RB = (VGPIO − VBE) ÷ IB where IB = IC ÷ hFE
| Parameter | Typical value | Notes |
|---|---|---|
| VGPIO | 3.3 V | ESP32 logic high |
| VBE | 0.6–0.7 V | Base-emitter drop, silicon NPN |
| hFE | 100–300 | Current gain; see datasheet |
| IC | your load current | E.g. 200 mA for relay coil |
Practical shortcut: a 1 kΩ base resistor works for almost every small NPN transistor (2N2222, BC547, BC337) driven from 3.3 V GPIO. It gives ~2.6 mA base current, which saturates transistors with hFE ≥ 100 for collector currents up to ~260 mA. Use a 10 kΩ resistor if the load is light (< 50 mA) to save power.
| Part | IC max | hFE | Package | Best used for |
|---|---|---|---|---|
| 2N2222 / PN2222 | 600 mA | 100–300 | TO-92 | Single LEDs, small buzzers, signal switching |
| BC547 | 100 mA | 110–800 | TO-92 | Annunciator LEDs, low-current relay drives |
| BC337 | 800 mA | 100–630 | TO-92 | LED banks, relay coils, small buzzers |
| TIP120 (Darlington) | 5 A | 1 000+ | TO-220 | Large LED arrays, motor control, solenoids |
| IRLZ44N (N-MOSFET) | 47 A | — (FET) | TO-220 | High-power LED strips, motors — gate driven directly from 3.3 V |
A Darlington pair cascades two NPN transistors so the emitter of Q1 drives the base of Q2. The combined current gain is the product of both transistors — allowing a tiny base current to switch several amperes. The TIP120 integrates this pair in a single TO-220 package.
| Load | Typical current | Recommended transistor |
|---|---|---|
| Single annunciator LED | 5–20 mA | BC547 or 2N2222 (or just a resistor, no transistor needed) |
| 4–8 LED annunciator bank | 40–160 mA | BC337 or 2N2222 |
| 5 V relay coil | 50–100 mA | BC337 + 1N4007 flyback diode |
| 12 V relay coil | 50–150 mA | BC337 or TIP120 + 1N4007 |
| LED strip (30 LEDs) | 500 mA – 1 A | TIP120 or IRLZ44N |
| Small DC motor / solenoid | 1–3 A | TIP120 or IRLZ44N + flyback diode |
Overhead Panel Annunciator Bank
An overhead panel typically has dozens of amber/red annunciator lights grouped by system. Rather than running a GPIO wire to each LED, group them by system and switch the whole group with one BC337 per group. Wire each LED in the group in series with its own 68–100 Ω resistor so a single failed LED does not short the others.
Relay-Driven External Power
When a cockpit subsystem (instrument lighting dimmer, panel fan) needs to be toggled from the simulator, a 5 V relay driven by a BC337 is the safest approach. The relay isolates the ESP32 GPIO from the mains-side or high-voltage circuit entirely. Always add a 1N4007 across the relay coil with the cathode towards the positive rail.
LED Backlighting Strip
Panel backlighting (white or amber LED strips behind MDF panels) typically draws 500 mA or more. Use an IRLZ44N MOSFET: gate through a 100 Ω resistor to the ESP32 GPIO, drain to the LED strip negative terminal, source to GND. Add a 10 kΩ pull-down between gate and source so the strip stays off at power-on before the firmware runs.
TO-92 transistors (2N2222, BC547, BC337) have three legs. With the flat face towards you and legs pointing down, the pin order differs by manufacturer — always check the datasheet or package markings. The most common orderings for NPN are:
| Transistor | Left | Centre | Right (flat face towards you) |
|---|---|---|---|
| 2N2222 (Fairchild/ON) | Emitter | Base | Collector |
| BC547 / BC337 | Collector | Base | Emitter |