Electronics & Circuits · Study deck

Electronics for IoT: Power and Switching

The signal calculations are correct, but an IoT device must survive its load path, the route that supplies current to the part being driven.

Voltage Vera is your guide for this deck.

Voltage Vera, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain: 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.
  • Explain: 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.
  • Explain: 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!).
  • Explain: Taking VBE(sat)≈0.8 VV_{BE(sat)}\approx0.8\ \mathrm{V}VBE(sat)​≈0.8 V gives.
iotclass.org

Major section

BJT Transistor as a Relay Switch

The collector voltage is therefore an inverted version of the control: a high input produces a low collector voltage.

  • An NPN bipolar junction transistor is a current-controlled low-side switch.
  • The relay contacts remain a separate circuit and can switch an isolated load within their ratings.
  • Gain varies between parts and falls in saturation.

Key terms

If it
If it is not, use a MOSFET or a driver IC rather than hoping for more transistor gain.
iotclass.org

Major section

BJT Transistor as a Relay Switch (continued)

IB≥ICβf,RB≤VGPIO,H−VBE(sat)IB. I_B\geq\frac{I_C}{\beta_f}, \qquad R_B\leq\frac{V_{GPIO,H}-V_{BE(sat)}}{I_B}. IB​≥βf​IC​​,RB​≤IB​VGPIO,H​−VBE(sat)​​..

  • The relay coil connects from its load supply VCCV_{CC}VCC​ to the collector, the emitter returns to ground, and a GPIO drives the base through a resistor.
  • With βf=10\beta_f=10βf​=10, require IB≥6 mAI_B\geq6\ \mathrm{mA}IB​≥6 mA.
  • The coil is inductive.
iotclass.org

Major section

BJT Transistor as a Relay Switch (continued)

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.

  • Taking VBE(sat)≈0.8 VV_{BE(sat)}\approx0.8\ \mathrm{V}VBE(sat)​≈0.8 V gives.
  • If it is not, use a MOSFET or a driver IC rather than hoping for more transistor gain.
  • When the transistor opens, v=L di/dtv=L\,di/dtv=Ldi/dt produces whatever voltage is needed to keep current flowing.
iotclass.org

Major section

MOSFET Switch for 12V Motor

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 photograph supplies orientation, while the datasheet remains the authority for pin order and ratings.

Why it matters

Purpose: Ensure MOSFET is OFF when GPIO is tri-state (during boot/reset).

TO-220 power MOSFET with three leads and a metal mounting tab. Photo: Suyash Dwivedi, CC BY-SA 4.0.
TO-220 power MOSFET with three leads and a metal mounting tab. Photo: Suyash Dwivedi, CC BY-SA 4.0.
iotclass.org

Major section

MOSFET Switch for 12V Motor (continued)

D1: Flyback diode (1N4007) - protects MOSFET from motor inductive kickback.

  • 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.
  • R1: Gate resistor (100Ω) - limits gate charge current.
  • Without diode: spike can reach 100-300V, destroying MOSFET.
iotclass.org

Major section

MOSFET Switch for 12V Motor (continued)

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 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^2RI2R 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.
iotclass.org

Major section

MOSFET Switch for 12V Motor (continued)

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!).

  • That physical reading connects the on-resistance and junction-temperature checks to assembly, clearance, and any heatsink decision.
  • Thermal result: This estimate does not establish junction temperature or heatsink need without a guaranteed on-resistance at the applied gate voltage and a verified duty cycle.
  • <!-- Note: This code can be run on a physical ESP32 with Arduino IDE, or simulated at wokwi.com with an ESP32 + MOSFET + motor circuit -->.
iotclass.org

Major section

Explore: MOSFET Thermal Calculator

The power dissipation formula from Step 3 (P=I2×Rds(on)P = I^2 \times R_{ds(on)}P=I2×Rds(on)​) estimates conduction loss when the on-resistance is known at the applied gate voltage.

  • Adjust the parameters below to explore conditional scenarios; the calculator does not include PWM duty cycle or drain-transition losses.
  • Logic-level MOSFETs need guaranteed on-resistance at the actual GPIO gate voltage; threshold voltage alone is insufficient.
  • Gate resistor (100Ω) protects GPIO from gate capacitance inrush.
iotclass.org

Deck summary

Key takeaways

The collector voltage is therefore an inverted version of the control: a high input produces a low collector voltage.

  • IB≥ICβf,RB≤VGPIO,H−VBE(sat)IB. I_B\geq\frac{I_C}{\beta_f}, \qquad R_B\leq\frac{V_{GPIO,H}-V_{BE(sat)}}{I_B}. IB​≥βf​IC​​,RB​≤IB​VGPIO,H​−VBE(sat)​​..
  • 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 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.
iotclass.org

Retrieval practice

Recall check 1 of 3

Voltage Vera says: answer from memory, then check your reasoning.

Q1Two IoT sensors share a 5V supply rated for 500 mA. At the intended operating voltage, Sensor A requires 200 mA and Sensor B requires 350 mA. What is their combined demand relative to the supply rating?

ADemand stays 500 mA because parallel sensors share current equally.
BDemand is only 200 mA because Sensor A was connected before Sensor B.
CDemand totals 550 mA, which exceeds the 500 mA supply rating.
DDemand totals 550 mA and the supply automatically provides it at 5 V.
Show answer

Answer: C At the intended 5V operating point, the parallel loads demand 200 + 350 = 550 mA, 50 mA above the supply's 500 mA rating.

iotclass.org

Retrieval practice

Recall check 2 of 3

Voltage Vera says: answer from memory, then check your reasoning.

Q2An IoT sensor board draws 50 mA from a 3.3V supply. The designer adds an LED indicator that requires 20 mA at 2V. Using a current-limiting resistor from the 3.3V rail, what resistor value is needed for the LED?

AUse a 165 Ω resistor from full supply voltage because the LED drop does not affect resistor current.
BA 100 Ω resistor yielding too little current from the 1.3 V drop
CA 33 Ω resistor nearly doubling the target 20 mA LED current
DA 65 Ω calculation, using a 68 Ω standard resistor in practice
Show answer

Answer: D see answers page

iotclass.org

Retrieval practice

Recall check 3 of 3

Voltage Vera says: answer from memory, then check your reasoning.

Q3Q3: signal versus load powerWhat motor, lamp or relay receives the switched power in a controller circuit?

APowered load
BSensor signal
CMicrocontroller decision
DTransistor switch
Show answer

Answer: A It is the motor, lamp, relay, or other device receiving switched power.

Q4Q4: GPIO driver decision helperComplete the GPIO load decision helper for a beginner IoT circuit:

Aneeds_driver = load_current_ma > gpio_limit_ma
Bneeds_driver = load_current_ma < gpio_limit_ma
Cneeds_driver = gpio_limit_ma == 0
Dneeds_driver = load_current_ma + gpio_limit_ma
Show answer

Answer: A GPIO pins are for small signals, not motors, relays, LED strips, or other high-current loads.

iotclass.org

Print reference

Answers

Answer key.

  1. C · At the intended 5V operating point, the parallel loads demand 200 + 350 = 550 mA, 50 mA above the supply's 500 mA rating.
  2. D · The resistor must drop the voltage difference between the supply (3.3V) and the LED forward voltage (2.0V), which is 1.3V. Using Ohm's law: R = V/I = 1.3V / 0.02A = 65 ohms. A common mistake is using the full supply voltage (3.3V/0.02A = 165 ohms), which would under-drive the LED. In practice, the nearest standard resistor (68 ohms) would be selected, resulting in approximately 19 mA -- close enough for an indicator LED.
  3. A · It is the motor, lamp, relay, or other device receiving switched power.
  4. A · GPIO pins are for small signals, not motors, relays, LED strips, or other high-current loads.
iotclass.org