Transistor
Transistors Explained: Types, Switching, Amplification, and Practical Circuits
A transistor is a semiconductor device used to control current or voltage. Transistors are fundamental to modern electronics: they switch LEDs and relays, amplify sensor signals, regulate power, and form the logic inside microcontrollers and processors. Although many transistor types exist, two especially useful families for beginners are bipolar junction transistors (BJTs) and field-effect transistors (FETs), including MOSFETs.
A BJT has three terminals called base, collector, and emitter. A relatively small base current controls a larger collector current in a common switching arrangement. A MOSFET has gate, drain, and source terminals; its gate voltage controls the channel's conduction. The gate draws very little steady DC current, but its capacitance must be charged and discharged during switching. These devices are not interchangeable without checking their electrical characteristics and pinouts.
A transistor used as a switch is usually driven between a low-conduction state and a strongly conducting state. A transistor used as an amplifier operates in a region where small input changes produce controlled output changes. The circuit topology, biasing, load, supply, and device ratings determine which behavior occurs.
This guide explains BJT and MOSFET basics, low-side switching, resistor selection, inductive-load protection, heat, datasheet reading, and common failures. Examples focus on low-voltage electronics such as Arduino and ESP32 projects. High-power and mains-connected circuits require appropriate design, isolation, and qualified handling.
1. BJT fundamentals
A bipolar junction transistor uses a small base-emitter drive to control current through the collector-emitter path. Common NPN and PNP types have different current directions and circuit arrangements. In a typical NPN low-side switch, the load is connected between the positive supply and collector, while the emitter is connected to ground. A base resistor limits current from the controlling GPIO or logic source.
In a simplified active-region model, collector current is related to base current by a current gain often represented as β or hFE. However, gain varies significantly between devices, current levels, temperature, and manufacturing batches. It is unsafe to design a saturated switch by assuming one exact gain value from a typical datasheet number.
For switching, a BJT is often driven into saturation so its collector-emitter voltage becomes relatively low. The datasheet specifies saturation voltage at particular collector and base currents. A suitable base current is needed to support the load current; too little base drive can leave the transistor partially on, increasing power dissipation.
For a simple small-signal NPN, the base-emitter junction behaves somewhat like a diode, but the exact voltage depends on current and temperature. A base resistor is still needed when driven from a voltage source. Connecting a GPIO directly to a transistor base can draw excessive current and damage the pin.
A PNP transistor can be used for high-side switching in suitable circuits, but the drive arrangement differs. For higher-current or low-voltage-drop switching, a MOSFET may be more appropriate. In all cases, check the actual pinout: transistor package lead order varies even among parts with similar shapes.
2. MOSFET fundamentals
A metal-oxide-semiconductor field-effect transistor uses gate voltage to control a conductive channel between drain and source. For an enhancement-mode N-channel MOSFET, a sufficiently positive gate-to-source voltage turns the channel on. A P-channel device is commonly used in high-side switching and has the opposite gate-drive polarity relative to its source.
MOSFET gates are insulated and have very high DC input resistance, but they are not indestructible. The gate has a maximum voltage rating and can be damaged by electrostatic discharge or transients. During switching, gate capacitance must be charged and discharged, so the driver must supply transient current. For slow, low-current switching, a microcontroller GPIO may be sufficient for a suitable logic-level MOSFET; for fast or high-power switching, a dedicated driver may be required.
A crucial datasheet parameter is RDS(on), the drain-to-source on-resistance at a specified gate-to-source voltage and current. A MOSFET described as “logic level” should have on-resistance specified at the actual drive voltage, such as 2.5 V, 3.3 V, or 4.5 V. The threshold voltage VGS(th) only indicates the beginning of conduction at a small test current; it does not mean the MOSFET is fully on at that voltage.
MOSFETs include a body diode as part of their structure. Its orientation affects reverse-current paths, especially in motor drivers and power converters. Do not assume a single MOSFET blocks current in both directions when off. Use the correct topology for the required protection or switching function.
3. Using a transistor as a low-side switch
A low-side switch places the transistor between the load and ground. The load connects to the positive supply, and the transistor connects the load's lower terminal to ground when enabled. This arrangement is common for indicator lamps, small DC motors, relay coils, and LED strips when the transistor and load are appropriately rated.
For an NPN BJT, the emitter typically connects to ground, the collector to the load's switched side, and the base receives a control signal through a resistor. For an N-channel MOSFET, the source typically connects to ground, the drain to the load's switched side, and the gate receives the control signal. In both cases, the load supply current flows through the transistor, not through the GPIO itself.
The controller and external load supply generally need a common ground reference for a non-isolated low-side arrangement. Connect the grounds deliberately and keep the high-current return path from disturbing sensitive logic ground. If isolation is required, use an appropriate isolated driver rather than tying grounds together casually.
The transistor's voltage rating must exceed the supply plus expected switching transients. Its current and thermal ratings must suit the load, and its package and PCB traces must dissipate the heat. A motor or relay can generate voltage spikes when switched, so add the suppression components specified for that load.
A transistor switch does not replace a fuse or supply protection. If the load or wiring shorts, the transistor can fail and the power source may deliver excessive current. Use protection appropriate to the source and application.
4. Driving a BJT: base resistor example
The base resistor limits current from the GPIO. A simplified estimate is R_B = (V_GPIO − V_BE)/I_B, where V_GPIO is the output voltage, V_BE is the base-emitter voltage at the chosen current, and I_B is the target base current. For a saturated switch, choose base current using the datasheet's saturation conditions rather than relying only on typical current gain.
Suppose a 5 V logic output drives an NPN transistor and a rough base-emitter drop of 0.7 V is assumed. If a design requires 2 mA base current, the estimated resistor is (5 − 0.7)/0.002 = 2.15 kΩ. A nearby standard value such as 2.2 kΩ is a starting point, but the collector load current and transistor saturation specification must be checked.
For a 3.3 V ESP32 GPIO, the available voltage across the resistor is smaller. The base current must be recalculated, and the GPIO's source-current limits must be respected. Do not use the pin's absolute maximum rating as the normal design target. If the required base current is too high, select a different transistor, a MOSFET, or a driver IC.
Check the resistor's power rating and the transistor's dissipation. In saturation, transistor power is approximately VCE(sat) × collector current, while in the active region both voltage and current can be significant. A transistor that is only partially on may heat substantially.
These equations are estimates, not universal component values. Read the transistor datasheet, check the load's startup current, and validate the circuit at low voltage with current limiting where practical.
5. Choosing a MOSFET for a microcontroller
For switching from a 3.3 V or 5 V GPIO, choose a MOSFET with RDS(on) specified at that gate voltage. The gate threshold voltage alone is not enough. If the datasheet only gives low on-resistance at 10 V gate drive, the device may not conduct well when driven directly from an ESP32 GPIO.
Conduction loss can be estimated as P ≈ I² × RDS(on). For example, a MOSFET with 50 mΩ on-resistance carrying 2 A has an idealized conduction loss of 0.2 W at that operating point. The actual resistance rises with junction temperature, and switching losses, package thermal resistance, PCB copper, and transient behavior also matter.
A MOSFET's gate charge affects how quickly it can switch. A large gate charge may be fine for a slow on/off control but unsuitable for high-frequency PWM from a weak GPIO. For power switching, a gate driver can provide the required charge and discharge current. Ensure the gate voltage stays within its maximum rating and that the gate does not float when the controller starts up or resets; a pull-down or pull-up resistor is often used to establish a safe default state.
Check drain-source voltage rating, continuous and pulsed current conditions, safe operating area, avalanche behavior, thermal resistance, package pinout, and body-diode characteristics. Current ratings in datasheets may assume an ideal case temperature and cannot be treated as guaranteed board-level current. The PCB layout and cooling strongly influence real capability.
6. Switching relays and motors safely
Relays, solenoids, and motors are inductive loads. When current is interrupted, the magnetic field collapses and can create a voltage spike that damages the transistor or causes electromagnetic interference. For a DC relay coil switched with a low-side transistor, a flyback diode is commonly placed across the coil with its cathode toward the positive supply and anode toward the transistor-switched side. Verify the exact topology before wiring.
A basic flyback diode reduces the voltage spike but can slow the release of a relay because coil current decays more gradually. A Zener or TVS clamp can allow faster decay, but the transistor's voltage rating and clamp energy must be designed accordingly. Do not apply the simple DC flyback-diode arrangement across an AC coil; suppression depends on the actual load and manufacturer recommendations.
A motor's startup and stall current can be many times its no-load current. Choose the transistor, supply, wiring, connector, and protection for the worst-case operating conditions. A transistor that handles the motor's free-running current may overheat or fail at stall. A suitable fuse can help protect wiring and the power source, but it must be selected for the system's fault current and time-current behavior.
Keep motor current out of sensitive breadboard rails and microcontroller regulator paths. Use a supply capable of the motor's transient demand, decoupling where appropriate, and a clear return-current layout. The control signal can come from the microcontroller, but the GPIO should not carry the motor current.
7. Transistors for amplification
A transistor can amplify a small signal when biased in an appropriate operating region. In a BJT amplifier, a small change in base-emitter voltage or base current can produce a larger change in collector current. A load resistor or another circuit converts that current variation into an output voltage. Biasing establishes a steady operating point so the signal can vary without excessive clipping.
A common-emitter BJT stage often provides voltage gain and inverts the signal. Emitter resistors can improve stability and linearity, while coupling capacitors can block DC between stages and allow AC signals to pass. The exact gain depends on transistor parameters, resistor values, load impedance, and frequency.
A MOSFET can also amplify signals in common-source and other configurations. Small-signal operation differs from switching: the transistor may intentionally operate with both significant voltage across it and current through it. This makes power dissipation and thermal stability especially important. A transistor suitable as a saturated switch may not be a good low-noise amplifier, and vice versa.
Amplifier design requires attention to bias current, voltage headroom, input/output impedance, frequency response, noise, distortion, and device ratings. The simple switching calculations in earlier sections should not be used to design an analog amplifier without analyzing the intended operating region.
For beginners, build low-voltage circuits from a known schematic and measure DC bias voltages before applying a signal. If the output is clipped or distorted, check the supply, bias network, transistor pinout, load, and signal amplitude. Never connect an unknown signal or a high-voltage source to a transistor stage without checking its input limits.
8. Read the datasheet before wiring
The transistor package shape does not guarantee the pin order. A TO-92 device may have emitter-base-collector, collector-base-emitter, or another arrangement depending on the part and viewing orientation. MOSFET packages likewise vary in gate, drain, and source pin assignment. Always check the exact manufacturer's datasheet and package drawing.
Important BJT specifications include maximum collector-emitter voltage, collector current, power dissipation, DC current gain, saturation voltage, base current, and thermal resistance. Important MOSFET specifications include drain-source voltage, gate-source voltage, RDS(on) at a relevant gate voltage, gate charge, threshold voltage, safe operating area, body-diode characteristics, and thermal resistance.
Maximum current and power values often assume ideal thermal conditions. A datasheet may show a high current rating that cannot be achieved on a small PCB without sufficient copper or cooling. The safe operating area indicates combinations of voltage and current the device can withstand for specified durations. For linear operation, this can be more restrictive than a simple current rating.
Check whether ratings are absolute maximum or recommended operating conditions. Absolute maximum values describe limits that should not be exceeded; they do not guarantee reliable operation at those values. Also inspect the device's switching behavior, leakage, and temperature dependence.
When replacing a transistor, match the function, polarity/type, pinout, voltage and current ratings, drive requirements, thermal behavior, and relevant switching characteristics. A “higher current” substitute can still fail if it needs more gate drive, has a different pinout, or dissipates more heat in the actual circuit.
9. Common transistor faults and troubleshooting
Load never turns on: Check the transistor pinout, supply, load wiring, base resistor or gate drive, and controller logic level. For a MOSFET, verify the actual gate-to-source voltage, not merely gate voltage relative to an unrelated point.
Transistor gets hot: It may be partially on, overloaded, undersized, poorly cooled, or exposed to a voltage spike. Calculate conduction and switching loss where possible, check the datasheet's operating conditions, and confirm the load's startup current. Disconnect power if the component overheats.
Microcontroller resets when switching a load: Investigate supply droop, ground bounce, inductive transients, wiring, and decoupling. Use a separate suitable load supply if necessary, with a deliberate reference arrangement. Add suppression appropriate to the load.
MOSFET works from 5 V logic but not 3.3 V: Its on-resistance may only be specified at a higher gate voltage. Choose a MOSFET characterized for the actual GPIO drive or use a gate driver.
BJT does not saturate: Base current may be insufficient, or the load current may be higher than expected. Check the datasheet saturation test conditions and recalculate the drive network. Do not draw excessive current from a GPIO to compensate.
Device fails repeatedly: Look for reversed supply, wrong pinout, overvoltage, shorted load, missing inductive suppression, excessive heat, or gate/base overdrive. Replace the transistor only after the cause is understood. Use current-limited testing for low-voltage prototypes.
10. Practical checklist and FAQs
Can a transistor drive a relay directly from a GPIO? The GPIO should control the transistor, not carry the relay-coil current. The transistor and its driver network must be suitable for the coil, and a DC coil usually needs a flyback or other appropriate suppression arrangement.
Is MOSFET threshold voltage the voltage needed for full turn-on? No. Threshold is measured at a very small drain current. Check RDS(on) at the actual gate voltage.
Why is a base or gate resistor used? A BJT base resistor limits base current. A MOSFET gate resistor may control switching transients and ringing; a pull-up or pull-down establishes a defined off state. The values depend on the circuit.
Can I switch an AC mains load with a small transistor? Not directly as a general-purpose beginner circuit. Mains switching requires suitable rated devices, isolation, enclosures, clearances, protection, and compliance with applicable standards.
Checklist
- Identify the exact transistor and verify its pinout.
- Confirm voltage, current, drive, and thermal ratings.
- Use a base resistor for a BJT and suitable gate drive for a MOSFET.
- Protect inductive loads with a circuit matched to the load type.
- Keep load current out of GPIO pins and unsuitable board traces.
- Test low-voltage circuits with current limiting and investigate repeated failures.
Transistors make it possible for small control signals to manage larger loads, but they are not magic current amplifiers without limits. Correct device selection, drive conditions, thermal design, wiring, and protection are what make a transistor circuit reliable.