Chapters

8 Electronics: Power and Transistor Switching

electronics-controller-design

8.1 Start With the Decision

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 is part 1 of 2. Continue with Electronics: Controller Design and Review.

8.3 Part Objectives

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

8.4 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

  • 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 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

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

Your BackgroundStart HereThen Read
Complete beginnerIntroductionConductors & 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

Voltage VeraCheckpoint: 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

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

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

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

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 Ohm’s Law R=VIR = \frac{V}{I}, with voltage across resistor = 5V - 2V (LED) - 0.2V (Vce(sat)) = 2.8V and desired current 100 mA: R=2.8V0.1A=28ΩR = \frac{2.8V}{0.1A} = 28\Omega. Worked example: With a 33Ω standard resistor, actual current is I=2.8V33Ω=85 mAI = \frac{2.8V}{33\Omega} = 85\text{ mA}, which is safe (below 100 mA max) and provides sufficient brightness. Note: The simplified calculation ignoring Vce(sat) gives 30Ω, which is also acceptable since a slightly higher resistance just means slightly less LED current.

  1. LED resistor (if needed above LED):

    • Voltage across resistor: 5V - 2V (LED drop) - 0.2V (Vce(sat)) = 2.8V
    • Current: 100mA
    • Resistor: R = 2.8V / 0.1A = 28Ω (use 33Ω standard for safety margin)
  2. Base resistor:

    • Required collector current: Ic = 100mA
    • Transistor gain (minimum): β = 100
    • Required base current: Ib = Ic / β = 100mA / 100 = 1mA
    • Add safety factor (2x): Ib = 2mA
    • Base voltage drop: Vbe = 0.7V
    • Resistor: R = (3.3V - 0.7V) / 2mA = 2.6V / 0.002A = 1.3kΩ (use 1kΩ)

Result: GPIO high → 2mA into base → 100mA through collector → LED lights at full brightness (OK)


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: 1N5819 Schottky (low forward voltage, fast recovery)
  • 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
1N5819 Schottky diodeAcross motor, cathode to +12VHandles motor flyback current during switching

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 Rds(on) at Vgs=10V; at Vgs=3.3V expect ~0.05Ω, giving ~12.5mW — still negligible)
  • Switching loss (transitions): Depends on gate charge (Qg) and switching time

Gate Charge Calculation:

  • IRLZ44N gate charge: Qg = 63nC (from datasheet)
  • PWM frequency: f = 1 kHz
  • Gate drive current (average): I = Q × f = 63nC × 1000 = 63µA (negligible!)
  • Switching loss (simplified): P ≈ Qg × Vgs × f = 63nC × 3.3V × 1000 = 0.2mW

Total Power Dissipation: 5.5mW + 0.2mW = 5.7mW → no heatsink needed

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

  • Switching loss: 63nC × 3.3V × 20,000 = 4.2mW
  • Total: 5.5mW + 4.2mW = 9.7mW → still OK without heatsink

Motor Characteristics:

  • PWM duty cycle 50% → average voltage 6V → motor runs at ~50% speed
  • 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)

Result: ESP32 PWM (0-100% duty) → MOSFET switches 500mA → motor speed varies smoothly. 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 calculated to verify no heatsink needed

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.

8.14 Continue to the Next Part

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