Electronics & Circuits · Study deck

Electronics for IoT: Power and Switching

The signal calculations are correct, but an IoT device must also survive its power and load paths.

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

$$ I_B\geq\frac{I_C}{\beta_f}, \qquad R_B\leq\frac{V_{GPIO,H}-V_{BE(sat)}}{I_B}. $$.

  • The relay coil connects from its load supply $V_{CC}$ to the collector, the emitter returns to ground, and a GPIO drives the base through a resistor.
  • With $\beta_f=10$, require $I_B\geq6\ \mathrm{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 $V_{BE(sat)}\approx0.8\ \mathrm{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/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.

Numbers to remember

12 VThe load path runs from the 12 V rail through the motor
≈ 0.8Amax Ic ≈ 0.8A (can't handle 2A); even for a higher-rated BJT

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 $I^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.
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.
  • <!-- Note: This code can be run on a physical ESP32 with Arduino IDE, or simulated at wokwi.com with an ESP32 + MOSFET + motor circuit -->.
  • Purpose: Ensure MOSFET is OFF when GPIO is tri-state (during boot/reset).
iotclass.org

Major section

Explore: MOSFET Thermal Calculator

The power dissipation formula from Step 3 above ($P = I^2 \times R_{ds(on)}$) determines whether your MOSFET needs a heatsink.

  • Logic-level MOSFETs (Vgs=3.3V) are essential for microcontroller interfacing.
  • Gate resistor (100Ω) protects GPIO from gate capacitance inrush.
  • Flyback diode (1N4007) is MANDATORY for inductive loads (motors, relays, solenoids).

Why it matters

Total cost <$2 enables safe, reliable motor control from any GPIO pin.

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.

  • $$ I_B\geq\frac{I_C}{\beta_f}, \qquad R_B\leq\frac{V_{GPIO,H}-V_{BE(sat)}}{I_B}. $$.
  • 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 are powered from the same 5V, 500 mA USB power supply. Sensor A draws 200 mA and Sensor B draws 350 mA. What will happen when both sensors are operating simultaneously?

ABoth sensors will operate normally because current is shared equally between them
BOnly Sensor A will operate because it was connected first
CDemand is 550 mA, above the supply.
DThe USB supply will automatically increase its current output to 550 mA
Show answer

Answer: C In a parallel circuit, total current is the sum of individual currents: 200 + 350 = 550 mA, exceeding the 500 mA supply limit.

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?

A165 ohms -- calculated as 3.3V / 20mA using Ohm's law
B100 ohms -- a standard value close to the calculated resistance
C33 ohms -- the resistor only needs to limit current, not drop the full supply voltage
D65 ohms, then choose about 68 ohms.
Show answer

Answer: D

iotclass.org

Retrieval practice

Recall check 3 of 3

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

Q3Place each electronics concept where it lives so you can separate the low-energy information path from the higher-current load path.

ASensor signal
BMotor supply
CGate resistor
DBattery charger
Show answer

Answer: A These boundaries keep sense input, make decision, drive power distinct so you can separate the low-energy information path from the higher-current load path.

Q4Complete 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 · In a parallel circuit, total current is the sum of individual currents: 200 + 350 = 550 mA, exceeding the 500 mA supply limit.
  2. D
  3. A · These boundaries keep sense input, make decision, drive power distinct so you can separate the low-energy information path from the higher-current load path.
  4. A · GPIO pins are for small signals, not motors, relays, LED strips, or other high-current loads.
iotclass.org