Chapters

11 Electronics for IoT: Power and Switching

electronics-controller-design

11.1 Start With the Situation

The signal calculations are correct, but an IoT device must also survive its power and load paths. The team must budget battery life and choose switching components without exceeding logic, thermal, or current limits.

11.2 Overview

This route turns power budgets into safe transistor, MOSFET, and load-switching decisions.

This is part 2 of 2. Review Electronics for IoT: Signals and Calculators when you need the first route.

11.3 Learning Objectives

By the end of this chapter, you will be able to:

  • calculate an IoT power budget
  • select BJT or MOSFET switching
  • check logic-level, current, and thermal limits

11.4 Chapter Roadmap

Follow the original sections below in order. They begin at the reviewed split boundary and keep every worked example, figure, check, and supporting banner with the section that owns it.

Battery Life Optimization Strategies

1. Sleep Mode Selection:

  • Light sleep: 2mA, wake in <1 ms, RAM preserved
    • Use for: Frequent wake-ups (<1 second intervals)
  • Deep sleep: 0.01mA, wake in 100 ms, most RAM lost
    • Use for: Periodic monitoring (minutes to hours)
  • Hibernation: ~0.005mA, wake in seconds, complete power down
    • Use for: Emergency backup, yearly wake-ups

2. Transmission Optimization:

  • Wi-Fi transmission: 200-300mA burst for 1-2 seconds
  • BLE advertising: 10-20mA for 10 ms every 100 ms-1s
  • LoRaWAN: 100-150mA for 50 ms-2s (spreading factor dependent)
  • Strategy: Collect 10-100 readings, transmit once vs transmit each reading

3. Real-World Targets:

  • Coin cell (CR2032): 0.005-0.02mA average → 1-5 years
  • AA batteries (2×): 0.05-0.5mA average → 6 months-5 years
  • Rechargeable (daily charging): <100mA average → 20+ hours
  • Solar powered: Match average consumption to solar generation (typically 5-50mA)
Power Budgeting Check

Voltage VeraCheckpoint: Calculation Checks

You now know:

  • For an LED on a 3.3V rail with a 2V forward drop, the resistor drops 1.3V, so about 68 ohms is the practical choice.
  • A 500 mA supply cannot carry 200 mA and 350 mA at the same time without exceeding its rating.
  • Battery and power-path choices depend on average current, sleep behavior, and whether an LDO or buck converter wastes less energy.


11.5 Knowledge Check

11.6 BJT Transistor as a Relay Switch

An NPN bipolar junction transistor is a current-controlled low-side switch. The relay coil connects from its load supply VCCV_{CC} to the collector, the emitter returns to ground, and a GPIO drives the base through a resistor. The control supply and coil supply may be different voltages, but this simple base-drive circuit needs the GPIO ground and transistor-emitter ground to share a reference. The relay contacts remain a separate circuit and can switch an isolated load within their ratings.

Read the two switching states from current flow:

Input conditionTransistor regionCoil currentCollector/output voltageRelay state
VinV_{in} low, IB0I_B\approx0CutoffApproximately zeroPulled near VCCV_{CC} through the coilReleased
VinV_{in} high, base deliberately overdrivenSaturationSet mainly by coil resistanceLow, approximately VCE(sat)V_{CE(sat)}Energised

The collector voltage is therefore an inverted version of the control: a high input produces a low collector voltage. That does not mean the relay action is inverted; the coil energises because current now has a path from VCCV_{CC} through the coil and transistor to ground.

Do not size the base resistor from the transistor’s headline DC gain hFEh_{FE}. Gain varies between parts and falls in saturation. Instead, choose a conservative forced gain βf\beta_f, often 10 for a small relay driver:

IBICβf,RBVGPIO,HVBE(sat)IB.I_B\geq\frac{I_C}{\beta_f}, \qquad R_B\leq\frac{V_{GPIO,H}-V_{BE(sat)}}{I_B}.

Walk the design. A 12 V relay coil draws 60 mA60\ \mathrm{mA} and is controlled by a 3.3 V GPIO. With βf=10\beta_f=10, require IB6 mAI_B\geq6\ \mathrm{mA}. Taking VBE(sat)0.8 VV_{BE(sat)}\approx0.8\ \mathrm{V} gives

RB3.30.80.006417 Ω.R_B\leq\frac{3.3-0.8}{0.006}\approx417\ \Omega.

A 390 Ω390\ \Omega resistor supplies about 6.4 mA6.4\ \mathrm{mA}, provided the GPIO is rated to source it. If it is not, use a MOSFET or a driver IC rather than hoping for more transistor gain. With VCE(sat)=0.2 VV_{CE(sat)}=0.2\ \mathrm{V}, transistor dissipation while on is only 0.2×0.060=12 mW0.2\times0.060=12\ \mathrm{mW}, but collector-current, voltage, and safe-operating-area ratings must still cover startup and fault conditions.

The coil is inductive. When the transistor opens, v=Ldi/dtv=L\,di/dt produces whatever voltage is needed to keep current flowing. A flyback diode placed directly across the coil—cathode to VCCV_{CC}, anode to the collector—is reverse-biased during normal operation and conducts the decaying coil current at turn-off. The diode protects the transistor, though it also lengthens relay release time; a faster release may require a deliberately higher-voltage clamp designed within the transistor rating.

Before release, verify each path separately: base current and GPIO loading in the control path; coil current and VCE(sat)V_{CE(sat)} in the load path; diode polarity and turn-off waveform in the inductive path; and contact voltage, current, isolation, and load type in the switched circuit. That four-path check is what turns the symbolic cutoff/saturation story into a safe interface between different voltage domains.

Scenario: You need to control a 12V DC motor (stall current: 2A) from an ESP32 GPIO pin (3.3V output, 12mA max). Design the transistor switching circuit.

Treat the problem as three coupled paths. The control path runs from the ESP32 GPIO through the gate resistor to the MOSFET gate; it must establish a defined OFF state during reset and charge the gate quickly enough for the chosen switching rate. The load path runs from the 12 V rail through the motor and MOSFET to ground; it must be rated for stall current, not merely the lower running current. The turn-off path is provided by the flyback diode so the motor winding’s current can decay without forcing the drain voltage beyond the switch rating. A common ground ties the 3.3 V control voltage to the MOSFET source reference.

Choose the device only after those paths are explicit. A headline drain-current rating measured under favourable thermal conditions is not proof of a safe design, and gate-threshold voltage is only where conduction begins. The useful check is the datasheet’s on-resistance at the available gate drive, followed by I2RI^2R loss and a thermal estimate. The checklist below records those decisions in the same order: switch type, electrical ratings, physical package, dissipation, gate network, protection, and finally code behaviour.

Step 1: Choose Transistor Type

BJT vs MOSFET comparison:

  • BJT (2N2222): Current-controlled, max Ic ≈ 0.8A (can’t handle 2A); even for a higher-rated BJT, base current = Ic/β ≈ 2A/100 = 20mA (exceeds GPIO limit!)
  • MOSFET (IRLZ44N): Voltage-controlled, gate current ≈ 0µA (perfect for GPIO)

Select: N-channel logic-level MOSFET (IRLZ44N)

Step 2: Verify MOSFET Specifications

ParameterIRLZ44N SpecRequirementStatus
Vds (drain-source voltage)55V12V motorOK: safe
Id (continuous drain current)47A2A motorOK: massive headroom
Vgs(th) (gate threshold)1-2V3.3V GPIOOK: logic-level candidate; threshold alone does not prove low loss
Rds(on) @ low gate voltage~0.035Ω near 4-5V gate driveLow resistanceOK for this load if the datasheet curve supports the available gate voltage; do not use only the 10V headline value
PackageTO-220Through-holeOK: easy to prototype

Before laying out the switch, inspect Figure 11.1 to identify the package features that the electrical and thermal calculation must eventually map onto. The photograph supplies orientation, while the datasheet remains the authority for pin order and ratings.

A TO-220 package power transistor with three metal leads and a metal mounting tab
Figure 11.1: TO-220 power MOSFET with three leads and a metal mounting tab. Photo: Suyash Dwivedi, CC BY-SA 4.0.

Read Figure 11.1 by locating the three leads first, then the insulated body, and finally the metal tab used for mechanical mounting and heat transfer. Do not infer gate, drain, and source order from appearance; verify the exact device pinout. That physical reading connects the on-resistance and junction-temperature checks to assembly, clearance, and any heatsink decision.

Step 3: Calculate Power Dissipation

With motor running at 2A (using Rds(on) ≈ 0.050Ω at Vgs=3.3V, worst case):

  • Voltage drop: V = I × Rds(on) = 2A × 0.050Ω = 0.10V (negligible)
  • Power dissipation: P = I² × Rds(on) = (2A)² × 0.050Ω = 0.20W

At room temperature (25°C):

  • Thermal resistance: 62.5°C/W (TO-220 without heatsink)
  • Temperature rise: 0.20W × 62.5°C/W = 12.5°C
  • Junction temperature: 25 + 12.5 = 37.5°C (well below 175°C max)

No heatsink needed!

Step 4: Design Gate Drive Circuit

Components needed:

  • R1: Gate resistor (100Ω) - limits gate charge current
  • R2: Pull-down resistor (10kΩ) - ensures MOSFET off when GPIO is floating
  • D1: Flyback diode (1N4007) - protects MOSFET from motor inductive kickback

Wiring map:

NodeConnects ToPurpose
ESP32 GPIO (3.3V)100Ω resistor, then MOSFET gateControls the motor switch and limits gate current spikes
MOSFET gate10kΩ pull-down to GNDKeeps the motor OFF during ESP32 boot/reset
MOSFET sourceGNDLow-side switch reference
MOSFET drainMotor negative sideSwitches motor current to ground
Motor positive side+12V supplyProvides motor power
Flyback diode D1Across motor, cathode to +12V and anode to MOSFET drainProtects the MOSFET when motor current is interrupted

Step 5: Calculate Component Values

Gate Resistor (R1 = 100Ω):

  • Purpose: Limit inrush current when charging gate capacitance
  • Gate capacitance (Ciss): 1200pF (from datasheet)
  • Peak gate current: I = 3.3V / 100Ω = 33mA (brief ~120ns transient; average current negligible)
  • Gate charging time: τ = R × C = 100Ω × 1200pF = 120ns (fast switching)

Pull-down Resistor (R2 = 10kΩ):

  • Purpose: Ensure MOSFET is OFF when GPIO is tri-state (during boot/reset)
  • Leakage current budget: 10µA maximum
  • Voltage across R2 when OFF: V = 10µA × 10kΩ = 0.1V (below Vgs(th), safe)
  • Power dissipation: P = V² / R = (3.3V)² / 10kΩ = 1.1mW (negligible)

Flyback Diode (D1 = 1N4007):

  • Purpose: Clamp inductive voltage spike when motor turns off
  • Motor inductance creates voltage spike: V = -L × (dI/dt)
  • Without diode: spike can reach 100-300V, destroying MOSFET
  • Diode spec: 1N4007 (1A, 1000V) handles motor’s inductive kickback
  • Orientation: Cathode (stripe) to 12V, anode to motor/drain

Step 6: Arduino Code Example

const int MOTOR_PIN = 25;  // GPIO25 on ESP32

void setup() {
  pinMode(MOTOR_PIN, OUTPUT);
  digitalWrite(MOTOR_PIN, LOW);  // Motor off initially
}

void loop() {
  // Turn motor on
  digitalWrite(MOTOR_PIN, HIGH);  // 3.3V to MOSFET gate
  delay(2000);  // Run for 2 seconds

  // Turn motor off
  digitalWrite(MOTOR_PIN, LOW);   // 0V to gate, MOSFET off
  delay(1000);  // Off for 1 second
}

Step 7: Verification Checklist

CheckExpectedMeasuredStatus
GPIO voltage HIGH3.3V3.28VOK
Gate voltage when ON3.3V3.27VOK
Gate voltage when OFF0V0.01VOK: pull-down working
Motor voltage when ON12V11.90VOK: about 0.1V drop across MOSFET at Vgs=3.3V
Motor current2A max1.8A runningOK: below stall current
MOSFET temperature<50°C32°COK: minimal heating

Step 8: Common Mistakes to Avoid

MistakeConsequenceFix
No gate resistorGPIO inrush current spike damages ESP32Add 100Ω gate resistor
No pull-down resistorMotor runs randomly during ESP32 bootAdd 10kΩ pull-down
No flyback diodeMOSFET fails after few switching cyclesAdd 1N4007 across motor
Using standard MOSFET (not logic-level)Requires 10V gate drive for its rated Rds(on), so it may overheat from GPIO driveUse a MOSFET with Rds(on) specified at your actual gate voltage; for ESP32, prefer 2.5-3.3V data
P-channel MOSFET for low-side switchRequires negative gate voltageUse N-channel for low-side

The power dissipation formula from Step 3 above (P=I2×Rds(on)P = I^2 \times R_{ds(on)}) determines whether your MOSFET needs a heatsink. Adjust the parameters below to explore different scenarios:

Bill of Materials (BOM):

ComponentPart NumberQuantityUnit CostTotal
MOSFETIRLZ44N1$1.20$1.20
Resistor (100Ω)1/4W1$0.02$0.02
Resistor (10kΩ)1/4W1$0.02$0.02
Diode1N40071$0.05$0.05
Total$1.29

Key Takeaways:

  1. Logic-level MOSFETs (Vgs=3.3V) are essential for microcontroller interfacing
  2. Gate resistor (100Ω) protects GPIO from gate capacitance inrush
  3. Pull-down resistor (10kΩ) prevents floating gate during boot/reset
  4. Flyback diode (1N4007) is MANDATORY for inductive loads (motors, relays, solenoids)
  5. Power dissipation calculation ensures no thermal issues (P = I² × Rds(on))
  6. Total cost <$2 enables safe, reliable motor control from any GPIO pin

Voltage VeraCheckpoint: Switching Loads

You now know:

  • A 3.3V ESP32 GPIO pin should command the switch, not power a 12V motor directly.
  • The MOSFET example checks voltage rating, current rating, gate drive, Rds(on), and heat before calling the design safe.
  • The 100 ohm gate resistor, 10k pull-down, and flyback diode each prevent a different failure mode.

11.7 Concept Relationships

Electronics fundamentals connect across multiple IoT domains:

Related ConceptChapter LinkRelationship
Electricity BasicsElectricity FundamentalsVoltage, current, resistance underpin all electronics
Semiconductor PhysicsDoping and DiodesHow materials enable electronic control
Sensor InterfacesSensor CircuitsElectronics condition and amplify sensor signals
Power ManagementEnergy SystemsSwitching regulators use transistors for efficiency

11.8 See Also

Electronics Foundations:

Follow these connections in order: Conductors and Insulators - Material properties and component types; Semiconductors and Diodes - PN junctions and one-way current flow; Transistor Selection - Choose BJT vs MOSFET for your project.

Practical Applications:

Follow these connections in order: Sensor Signal Conditioning - Amplify and filter analog signals; Motor Control Basics - Transistor H-bridge circuits; LED Drivers - Current limiting and PWM dimming.

Common Pitfalls

Resistors, capacitors, inductors, diodes, and transistors have fundamentally different electrical behaviors. Substituting a capacitor where a resistor is needed, or using an NPN transistor circuit topology for a PNP device, produces circuits that don’t work. Always identify the specific component type, package, and electrical parameters required before substitution.

Electrolytic capacitors, LEDs, diodes, and transistors are polarized — they only work correctly in one orientation. Reversing an electrolytic capacitor causes it to fail (and sometimes explosively). Reversing an LED causes it to block current (no light). Always verify polarity markings (stripe on diode, stripe on capacitor, flat side of LED) before inserting components.

Schematics use standardized symbols that bear no resemblance to the actual physical component. An NPN transistor symbol (triangle with arrow) looks nothing like a TO-92 plastic package. An op-amp symbol (triangle) doesn’t look like a DIP-8 IC. Always translate schematic symbols to component identifiers and then to physical pinouts via the datasheet — never guess from the symbol alone.

A capacitor rated 16 V in a 12 V circuit seems fine, but voltage ratings should be derated by 50% for reliability: use 25 V or 35 V capacitors in a 12 V circuit. Similarly, transistors rated 200 mA used at 190 mA run hot and fail early. Apply 50% derating to voltage, current, and power ratings as standard engineering practice.

11.9 What’s Next

If you want to…Read this
Learn how electronic components work at the circuit levelElectronics: Conductors and Insulators
Understand semiconductor doping, diodes, and LEDsElectronics: Doping and Diodes
Apply electronics fundamentals to ADC and digital conversionAnalog and Digital Electronics
Build on this foundation with sensor interfacing circuitsSensor Circuits and Signals

11.10 Logic Levels and Shifting

The sections above orient beginners to GPIO limits, component roles, load switching, and protection components. When two real boards are connected, the next review question is whether each digital link is both logically valid and electrically survivable across its voltage domains.

For the layered engineering checks, continue to Logic Level and Level Shifting Contracts. It works through VOH/VOL and VIH/VIL thresholds, noise margin, 3.3 V and 5 V directionality, resistor-divider limits, bidirectional bus shifting, pull-up sizing, and absolute-maximum protection.

11.11 Figure Review: Logic-Controlled Load Current

A low-side transistor switch lets a GPIO command a higher-current load without asking the logic pin to source the coil current directly.

Low-side NPN relay-driver schematic with GPIO base resistor, relay coil, shared ground, collector current, and flyback diode, beside cutoff-low and saturated-high output states.
Figure 11.2: Low-side NPN relay driver and state table.

In Figure 11.2, GPIO 3V3 supplies base current through RB while the collector carries relay current; CUTOFF · LOW leaves the coil off, SATURATED · HIGH energizes it, and the flyback path safely circulates turn-off energy.

11.12 Summary

This chapter introduces the electronics foundation behind IoT devices: voltage, current, resistance, GPIO limits, loads, sensors, and protection components. It frames circuit design as a balance of signal behavior, power, safety, and component limits.