11 Electronics for IoT: Power and Switching
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.
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)
Checkpoint: 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 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 condition | Transistor region | Coil current | Collector/output voltage | Relay state |
|---|---|---|---|---|
| low, | Cutoff | Approximately zero | Pulled near through the coil | Released |
| high, base deliberately overdriven | Saturation | Set mainly by coil resistance | Low, approximately | 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 through the coil and transistor to ground.
Do not size the base resistor from the transistor’s headline DC gain . Gain varies between parts and falls in saturation. Instead, choose a conservative forced gain , often 10 for a small relay driver:
Walk the design. A 12 V relay coil draws and is controlled by a 3.3 V GPIO. With , require . Taking gives
A resistor supplies about , 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 , transistor dissipation while on is only , but collector-current, voltage, and safe-operating-area ratings must still cover startup and fault conditions.
The coil is inductive. When the transistor opens, produces whatever voltage is needed to keep current flowing. A flyback diode placed directly across the coil—cathode to , 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 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 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
| Parameter | IRLZ44N Spec | Requirement | Status |
|---|---|---|---|
| Vds (drain-source voltage) | 55V | 12V motor | OK: safe |
| Id (continuous drain current) | 47A | 2A motor | OK: massive headroom |
| Vgs(th) (gate threshold) | 1-2V | 3.3V GPIO | OK: logic-level candidate; threshold alone does not prove low loss |
| Rds(on) @ low gate voltage | ~0.035Ω near 4-5V gate drive | Low resistance | OK for this load if the datasheet curve supports the available gate voltage; do not use only the 10V headline value |
| Package | TO-220 | Through-hole | OK: 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.
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:
| Node | Connects To | Purpose |
|---|---|---|
| ESP32 GPIO (3.3V) | 100Ω resistor, then MOSFET gate | Controls the motor switch and limits gate current spikes |
| MOSFET gate | 10kΩ pull-down to GND | Keeps the motor OFF during ESP32 boot/reset |
| MOSFET source | GND | Low-side switch reference |
| MOSFET drain | Motor negative side | Switches motor current to ground |
| Motor positive side | +12V supply | Provides motor power |
| Flyback diode D1 | Across motor, cathode to +12V and anode to MOSFET drain | Protects 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
| Check | Expected | Measured | Status |
|---|---|---|---|
| GPIO voltage HIGH | 3.3V | 3.28V | OK |
| Gate voltage when ON | 3.3V | 3.27V | OK |
| Gate voltage when OFF | 0V | 0.01V | OK: pull-down working |
| Motor voltage when ON | 12V | 11.90V | OK: about 0.1V drop across MOSFET at Vgs=3.3V |
| Motor current | 2A max | 1.8A running | OK: below stall current |
| MOSFET temperature | <50°C | 32°C | OK: minimal heating |
Step 8: Common Mistakes to Avoid
| Mistake | Consequence | Fix |
|---|---|---|
| No gate resistor | GPIO inrush current spike damages ESP32 | Add 100Ω gate resistor |
| No pull-down resistor | Motor runs randomly during ESP32 boot | Add 10kΩ pull-down |
| No flyback diode | MOSFET fails after few switching cycles | Add 1N4007 across motor |
| Using standard MOSFET (not logic-level) | Requires 10V gate drive for its rated Rds(on), so it may overheat from GPIO drive | Use 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 switch | Requires negative gate voltage | Use N-channel for low-side |
The power dissipation formula from Step 3 above () determines whether your MOSFET needs a heatsink. Adjust the parameters below to explore different scenarios:
Bill of Materials (BOM):
| Component | Part Number | Quantity | Unit Cost | Total |
|---|---|---|---|---|
| MOSFET | IRLZ44N | 1 | $1.20 | $1.20 |
| Resistor (100Ω) | 1/4W | 1 | $0.02 | $0.02 |
| Resistor (10kΩ) | 1/4W | 1 | $0.02 | $0.02 |
| Diode | 1N4007 | 1 | $0.05 | $0.05 |
| Total | $1.29 |
Key Takeaways:
- Logic-level MOSFETs (Vgs=3.3V) are essential for microcontroller interfacing
- Gate resistor (100Ω) protects GPIO from gate capacitance inrush
- Pull-down resistor (10kΩ) prevents floating gate during boot/reset
- Flyback diode (1N4007) is MANDATORY for inductive loads (motors, relays, solenoids)
- Power dissipation calculation ensures no thermal issues (P = I² × Rds(on))
- Total cost <$2 enables safe, reliable motor control from any GPIO pin
Checkpoint: 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 Concept | Chapter Link | Relationship |
|---|---|---|
| Electricity Basics | Electricity Fundamentals | Voltage, current, resistance underpin all electronics |
| Semiconductor Physics | Doping and Diodes | How materials enable electronic control |
| Sensor Interfaces | Sensor Circuits | Electronics condition and amplify sensor signals |
| Power Management | Energy Systems | Switching 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 level | Electronics: Conductors and Insulators |
| Understand semiconductor doping, diodes, and LEDs | Electronics: Doping and Diodes |
| Apply electronics fundamentals to ADC and digital conversion | Analog and Digital Electronics |
| Build on this foundation with sensor interfacing circuits | Sensor 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.
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.
