Chapters

8 Electronics: Power and Transistor Switching

electronics-controller-design

8.1 Start With the Decision

This section: Start With the Decision — GPIO means general-purpose input and output; its pins carry control signals.

GPIO means general-purpose input and output; its pins carry control signals. A transistor can switch a larger load using that signal. Load power is the supply that drives the valve itself. A GPIO pin can request that a valve open, but it cannot supply the valve. A transistor keeps control and load power apart.

8.2 Route Overview

This section: Route Overview — This is part 1 of 2.

This is part 1 of 2. Continue with Electronics: Controller Design and Review.

8.3 Part Objectives

This section: Part Objectives

  • Calculate base or gate drive for a switched load.
  • Choose protection for inductive current and supply faults.

8.4 Start Simple

This section: Start Simple

8.4.1 Follow the Safe Power Path

A microcontroller is a small computer built to read inputs and control outputs. GPIO means general-purpose input/output and names the pins used for many of those jobs. An actuator is a part that turns an electrical command into a physical change.

Picture a plant monitor that must open a water valve. The control pin can request the action, but it cannot safely supply the valve’s power. A driver must carry the load current. A protection path must handle the energy left when the valve turns off.

Draw two paths before choosing parts. Trace the small control signal from the pin to the driver. Then trace load power from the supply through the driver and valve. Check voltage, current, heat, startup demand, common reference, and the safe state after a reset or broken wire.

This path does not explain every semiconductor or switching detail. It prevents the first dangerous mistake: treating a logic pin as a power source. The deeper sections show how diodes, transistors, ratings, and measured evidence turn the sketch into a safe circuit.

Imagine a GPIO pin asked to light an LED, read a switch, and control a small load. Electronics is the set of parts that keeps those jobs within safe voltage, current, timing, and protection limits. Start with the pin limit, the load need, and the component that makes the two compatible.

8.5 Learning Objectives

This section: Learning Objectives

  • Explain how semiconductors, diodes, and transistors form the foundation of all IoT device hardware
  • Distinguish between conductors, insulators, and semiconductors and describe how doping creates N-type and P-type materials
  • Compare BJT and MOSFET transistors and determine which is appropriate for a given IoT switching or amplification task
  • Analyze transistor switching circuits for controlling high-power loads such as motors, relays, and LED strips from microcontroller GPIO pins
In 60 Seconds

Electronics is the study of controlling electron flow using semiconductors. This chapter covers conductors, insulators, semiconductors, diodes, and transistors (BJT and MOSFET) — the essential building blocks that enable every IoT microcontroller, sensor interface, and actuator control circuit.

Key Concepts
  • Semiconductor: A material whose conductivity can be engineered; silicon becomes useful for electronics because doping changes how charge moves through it.
  • Diode: A one-way device built from a PN junction; used for rectification, protection, LEDs, and the internal building blocks of more complex devices.
  • Transistor: A controllable semiconductor switch or amplifier; BJTs use base current, while MOSFETs use gate voltage.
  • Logic-level MOSFET: The default IoT power-switching device when a microcontroller must control relays, motors, solenoids, or LED strips without overstressing GPIO pins.
  • Driver circuit: The interface between a low-power controller and a higher-power load; typically includes a transistor, resistor network, and protection components such as a flyback diode.
  • Datasheet-first design: Good electronics decisions come from checking voltage, current, power, and switching requirements against the component datasheet instead of relying on generic part names.

8.6 Overview

This section: Overview — This book is the bridge between basic electricity and practical IoT hardware design.

This book is the bridge between basic electricity and practical IoT hardware design. It explains what semiconductors are, how diodes and transistors behave, and how to choose safe switching circuits when a microcontroller needs to control real loads.

Use this page as a guide, not as the main teaching chapter. The detailed explanations, examples, and checks live in the five linked sections below.

Chapter Roadmap
  • Start Simple
  • In 60 Seconds
  • Key Concepts
  • Overview
  • Chapter Navigation
  • Learning Path Recommendation
  • How To Use This Book
  • Checkpoint: Module Map
  • Smart Light from Silicon
  • Why This Chapter Matters for IoT
  • Prerequisites
  • Transistor Switching Examples
  • Deep dive: LED switch numbers

8.7 Chapter Navigation

This section: Chapter Navigation

8.7.1 Electronics Intro and Tools

~3,450 words | Beginner

Start with the learning objectives and prerequisite vocabulary, then distinguish electronics from basic electricity before using the Ohm’s-law, LED-resistor, voltage-divider, and battery-life calculators. Carry those results into the power-supply architecture and optimization discussion, where the beginner examples turn definitions into first design habits.

Start here if you need the vocabulary and first design habits before touching transistor or switching circuits.


8.7.2 Conductors and Semiconductors

~3,150 words | Beginner

Move from material classification—conductors, insulators, and semiconductors—to the component taxonomy of passive, active, and integrated devices. Then use the quick reference, circuit patterns, and real specifications to connect material behaviour to selection and rating decisions in an IoT circuit.

Key Topics: material behavior, passive components, voltage dividers, decoupling, current limiting, and rating checks


8.7.3 Semiconductors Doping Diodes

~5,100 words | Intermediate

Build the device model from semiconductor physics and atomic structure through N-type and P-type doping to the PN junction. With that boundary established, compare diode types, applications, and forward versus reverse bias, then use the checks to test whether the physical explanation predicts circuit behaviour.

Deep Dive: This is the theory chapter that explains why silicon devices behave the way they do.


8.7.4 Transistor Selection for IoT

~2,050 words | Intermediate

Begin with the BJT-versus-MOSFET comparison, then read voltage, current, and power-dissipation ratings against the intended load. Finish with switching speed, gate-drive requirements, logic-level behaviour, and the practical selection criteria that decide whether a GPIO can control the device safely.

Practical Focus: This is the selection chapter for real GPIO-to-load interfaces.


8.7.5 Electronics Summary Resources

~2,900 words | Beginner

Use the summary and key takeaways to identify what needs review, then revisit ESD damage and thermal drift as failure modes rather than isolated cautions. The visual galleries support recognition, while the related chapters and further resources point back to the evidence needed for a specific design decision.

Reference: Use this last, after the main sections, for review, troubleshooting, and quick lookup.


8.8 Learning Path Recommendation

This section: Learning Path Recommendation

Your BackgroundStart HereThen Read
Complete beginnerIntroduction → Conductors & InsulatorsPractice with calculators, then move to semiconductors
Some electronics knowledgeSemiconductors & DopingDeep dive into theory, then apply with transistor selection
Need practical guidanceTransistor Selection GuideJump to component selection, refer back to theory as needed
Quick referenceSummary & ResourcesUse visual galleries and component tables

8.9 How To Use This Book

This section: How To Use This Book

Voltage Vera, Electronics measurement and prototyping expertCheckpoint: Module Map

You now know:

  • This overview points to five linked sections, from beginner introductions through intermediate transistor selection.
  • The sequence starts with electricity, conductors, and semiconductors before it asks you to make switching decisions.
  • The practical target is safe GPIO-to-load design: respect the 3.3V signal level, current limits, and component ratings.

8.10 Smart Light from Silicon

This section: Smart Light from Silicon — The smart-light story turns the navigation list into a single chain: material choice creates components, components create circuits, and circuits let firmware affect the physical world.

From Raw Silicon to a Smart LED Light

Let’s trace how electronics principles build a complete IoT device - a Wi-Fi-controlled LED light.

Step 1: Starting Material - Pure Silicon We begin with ultra-pure silicon (99.9999999% pure - “nine nines”). Silicon has 4 valence electrons, making it a semiconductor - not a great conductor, but not an insulator either.

Step 2: Doping Creates N-type and P-type Engineers add tiny amounts of impurities:

  • Phosphorus (5 valence electrons) → N-type silicon (extra electrons available)
  • Boron (3 valence electrons) → P-type silicon (missing electrons, creating “holes”)

Step 3: PN Junction = Diode Place N-type and P-type together → PN junction → a diode forms. Conventional current flows one way (from P-side anode to N-side cathode) but not the reverse. This becomes our power rectifier to convert AC wall power to DC.

Step 4: Three Layers = Transistor Add a third layer:

  • NPN transistor: N-type, thin P-type, N-type
  • Controls current flow with a tiny gate/base signal
  • Millions of these make our ESP32 microcontroller

Step 5: Building the Smart Light Circuit

StageWhat It Does
Wall ACSupplies energy to the device
Diode rectifierConverts AC into pulsing DC
Voltage regulatorProduces safe DC rails for electronics
Battery backupKeeps the device alive during short outages
ESP32 and Wi-Fi moduleProcess the control logic and communicate wirelessly
GPIO outputSends a low-power control signal
MOSFETUses that small GPIO signal to switch the LED load
LED + resistorProduces light while the resistor limits current

Component Breakdown:

  1. Diode bridge: 4 PN junctions convert AC to pulsing DC
  2. Capacitor: Smooths pulsing DC to steady DC
  3. Voltage regulator (contains many transistors): Drops 12V to 3.3V for ESP32
  4. ESP32 microcontroller: Millions of transistors executing code
  5. MOSFET driver (N-channel, 3 layers): Switches LED on/off from GPIO signal
  6. LED (another diode!): Emits light when forward-biased
  7. Current-limiting resistor: Protects LED from overcurrent

The Electronics Magic:

  • Diodes ensure current only flows the correct direction
  • Transistors in the ESP32 store your Wi-Fi settings in SRAM cells (each made of 6 transistors)
  • MOSFET switches the high-current LED (1A) using only the 3.3V GPIO voltage signal — essentially zero current drawn from the GPIO pin!
  • Capacitors smooth voltage ripples from the power supply

All from Doping Silicon: Every component except resistors and capacitors is made from doped silicon forming PN or NPN/PNP junctions. The entire difference between a diode, BJT, MOSFET, and microcontroller is just the arrangement and doping profile of silicon layers!

Key Insight: Electronics is applied semiconductor physics. Understanding PN junctions, doping, and transistor operation explains how millions of components work together to create intelligent devices from inert silicon.

The smart-light story turns the navigation list into a single chain: material choice creates components, components create circuits, and circuits let firmware affect the physical world. The next question is why that chain matters so much in IoT work.

8.11 Why This Chapter Matters for IoT

This section: Why This Chapter Matters for IoT

Critical Skills for IoT Development

Every IoT device relies on electronics:

  • Microcontrollers contain millions of transistors
  • Sensors require proper signal conditioning circuits
  • Actuators need transistor-based switching circuits
  • Power management depends on voltage regulators and MOSFETs
  • Wireless modules use RF electronics

Without understanding electronics, you cannot:

  • Interface sensors safely (risk of damage)
  • Control high-power loads (motors, relays, LED strips)
  • Optimize battery life (inefficient power circuits)
  • Debug hardware issues effectively

8.12 Prerequisites

This section: Prerequisites

Before starting, you should understand:

  • Electricity Fundamentals: Voltage, current, resistance, Ohm’s Law
  • Atomic Structure: Atoms, electrons, protons, electron shells
  • Circuit Analysis: Reading circuit diagrams, Kirchhoff’s laws

8.13 Transistor Switching Examples

This section: Transistor Switching Examples

Controlling Loads with Transistors

The examples below move from a small LED to a relay and then to a PWM motor. Read them as escalating design checks: current first, then voltage, then heat and inductive protection.

8.13.1 LED Switching with NPN BJT

Scenario: Use an ESP32 GPIO pin (3.3V, max 12mA) to control a high-brightness LED that requires 100mA.

Components:

  • NPN transistor: 2N2222 (β = 100-300)
  • LED: Forward voltage = 2.0V, forward current = 100mA
  • Power supply: 5V

Wiring map:

NodeConnects ToPurpose
+5V supplyLED and current-limiting resistor pathProvides LED power
LED/resistor negative side2N2222 collectorLets the transistor switch the LED current
2N2222 emitterGNDCompletes the low-side current path
ESP32 GPIO (3.3V)1kΩ resistor, then 2N2222 baseProvides the small base current that turns the transistor ON
LED current pathAbout 100mA when ONGPIO controls a larger current safely through the transistor

Calculations:

Using the P2N2222A datasheet’s 0.3V maximum saturation drop at its stated 150mA/15mA test point, a 33Ω resistor gives LED current (5−2−0.3)/33=81.8 mA(5-2-0.3)/33 = 81.8\text{ mA} at that assumed drop. Verify the transistor’s actual drive and the LED’s current rating.

For a 100mA collector current, use forced gain near 10: about 10mA base drive, if the GPIO’s guaranteed source current and high-level voltage permit it; otherwise use a suitable MOSFET or driver. Choose the base resistor using the minimum GPIO high voltage and maximum VBE(sat). The P2N2222A datasheet guarantees VCE(sat) up to 0.3V at 150mA/15mA, so 0.2V is an assumption, not a limit.


8.13.2 MOSFET Relay Switching

Scenario: Control a 12V relay (coil resistance = 400Ω, current = 30mA) to switch 240V AC mains power to a lamp.

Components:

  • N-channel MOSFET: 2N7000 (logic-level, Vgs(th) = 0.8-3.0V, typical 2.1V)
  • Relay: 12V coil, SPDT contacts rated 10A @ 250VAC
  • Flyback diode: 1N4001 (protects MOSFET from inductive kick)

Wiring map:

NodeConnects ToPurpose
+12V supplyRelay coil positive sideProvides coil power
Relay coil negative side2N7000 drainMOSFET switches the coil current
2N7000 sourceGNDLow-side switch reference
ESP32 GPIO (3.3V)100Ω resistor, then MOSFET gateControls the relay
MOSFET gate10kΩ pull-down to GNDKeeps relay OFF during boot/reset
1N4001 flyback diodeAcross relay coil, cathode to +12VProtects MOSFET from inductive voltage spikes

Why MOSFET instead of BJT?:

  • MOSFET gate current: ~0µA (vs 2mA for BJT)
  • Lower power dissipation: Rds(on) = 5Ω → P = I²R = (0.03)² × 5 = 4.5mW
  • BJT would dissipate: Vce(sat) × Ic = 0.2V × 30mA = 6mW (comparable, but BJT wastes GPIO current)

Flyback Protection: When relay coil de-energizes, collapsing magnetic field induces voltage spike (can reach 100V+). Diode provides discharge path: spike energy dissipates through diode instead of destroying MOSFET.

Calculations:

  • Relay current: I = V / R = 12V / 400Ω = 30mA
  • MOSFET Vgs = 3.3V > Vgs(th) typical 2.1V → on (OK; verify Vgs(th) max for your specific device, because worst-case 2N7000 can have Vgs(th) up to 3.0V, leaving minimal margin at 3.3V)
  • Gate resistor: 100Ω limits inrush current when GPIO goes high (prevents ringing)
  • Pull-down: 10kΩ ensures gate stays at GND when GPIO is floating (prevents spurious relay activation)

Result: GPIO high → MOSFET conducts → relay energizes → mains lamp turns on (OK)


8.13.3 PWM Motor with Power MOSFET

Scenario: Variable-speed control of a 12V DC motor (stall current: 2A, running current: 500mA) using PWM from ESP32.

Components:

  • N-channel Power MOSFET: IRLZ44N (logic-level, Rds(on) = 0.022Ω @ Vgs=10V, ~0.028Ω @ Vgs=5V, Id(max) = 47A)
  • Motor: 12V, 500mA running, 2A stall
  • Flyback diode: choose a Schottky or suitable fast-recovery diode whose repetitive current, surge and thermal ratings cover the motor’s running and stall-current PWM conditions; 1N5819 suitability is not established for the stated 2A stall case.
  • Gate driver: Optional, but improves switching speed

Wiring map:

NodeConnects ToPurpose
+12V supplyDC motor positive sideProvides motor power
DC motor negative sideIRLZ44N drainMOSFET switches motor current
IRLZ44N sourceGNDLow-side switch reference
ESP32 PWM pin100Ω resistor, then MOSFET gateControls motor speed by PWM
MOSFET gate10kΩ pull-down to GNDKeeps motor OFF during boot/reset
Suitable rated flyback diodeAcross motor, cathode to +12VRepetitive current, surge and thermal ratings must cover running and stall-current PWM conditions; 1N5819 suitability is not established for the stated 2A stall case

Advanced Consideration: MOSFET Switching Losses

At PWM frequency of 1 kHz (ESP32 default):

  • Conduction loss (when ON): P = I² × Rds(on) = (0.5)² × 0.022 = 5.5mW using the 10V-gate datasheet value. The 0.05Ω, 3.3V estimate would give 12.5mW conditionally; the datasheet does not guarantee that resistance at 3.3V.
  • Drain switching loss (transitions): Depends on drain-voltage/current overlap and transition times

Gate Charge Calculation:

  • IRLZ44N gate charge: Qg = 63nC (from datasheet)
  • PWM frequency: f = 1 kHz
  • Average gate-charge current: I = Q × f = 63nC × 1000 = 63µA using the datasheet gate-charge figure illustratively; actual gate charge at 3.3V must be checked.
  • Approximate gate-drive power: P_gate ≈ Qg × Vdrive × f. Using the datasheet’s 63nC gate-charge figure illustratively gives 63nC × 3.3V × 1000 ≈ 0.2mW; actual gate charge at 3.3V must be checked. This is driver power, not MOSFET drain switching loss, which depends on drain voltage, current and transition times.

Total Power Dissipation: The 5.5mW figure uses 10V-gate on-resistance although the GPIO supplies 3.3V; the 0.2mW figure is gate-drive power, not drain switching loss. Verify on-resistance at 3.3V and transition losses before deciding whether a heatsink is needed.

If using higher PWM frequency (20 kHz for quieter operation):

  • Approximate gate-drive power: 63nC × 3.3V × 20,000 = 4.2mW; actual gate charge at 3.3V must be checked. This is not drain switching loss. Verify on-resistance at the applied gate voltage and drain transition losses before estimating total MOSFET dissipation.

Motor Characteristics:

  • PWM duty cycle 50% → average applied voltage about 6V; actual motor speed depends on motor characteristics and load and must be measured.
  • Flyback diode handles inductive kick when motor current changes
  • Schottky diode chosen for fast recovery (important at high PWM frequency)

Advanced Protection:

  • Add 0.1µF capacitor across motor terminals (suppresses EMI/RFI noise)
  • Add 100nF ceramic cap from Vgs to GND (stabilizes gate voltage during fast switching)

Expected result in this motor example: ESP32 PWM (0–100% duty) → MOSFET switches a modeled 500 mA load → motor speed may vary with duty cycle; verify under load. Power loss in MOSFET is minimal due to ultra-low Rds(on) (OK)

Key Differences from Beginner/Intermediate:

  • Power MOSFET handles 2A vs 30mA (relay) or 100mA (LED)
  • Switching losses become significant at high frequency
  • EMI suppression needed for motor commutation noise
  • Schottky diode for faster recovery than standard 1N4001
  • Heat dissipation requires duty-weighted conduction and drain-transition estimates at the approved gate voltage before thermal sign-off

Design Insight: For loads >500mA, always calculate power dissipation. If P > 500mW, add heatsink. If P > 2W, consider active cooling or multiple MOSFETs in parallel.

Hands-on lab · 35 min · Falstad CircuitJS

Transistor low-side switching and flyback path

I have explained transistor switching; now measure the base path, load current, and flyback peak.

Open the lab

This section:

8.14 Continue to the Next Part

This section: Continue to the Next Part — Carry this evidence into Electronics: Controller Design and Review, which begins with Checkpoint: Switching Loads.

Carry this evidence into Electronics: Controller Design and Review, which begins with Checkpoint: Switching Loads.

Find help

3 reviewed answers.

Where should I start in a module?

Open the module page from the sidebar to see its chapters in order. Use the module map to return to a topic you need.

Modules and paths

Reviewed

What can I try when a project does not work?

Check the symptom, then work through the diagnostic steps. Keep the error message and the smallest example that reproduces it.

When you are stuck

Reviewed

How do interactive examples work?

Use the interactive guide to check how examples and simulations work before changing your project.

Interactive examples guide

Reviewed