9  Electronics & Calculators

In 60 Seconds

Electronics adds intelligence to electricity. While electrical devices simply use power, electronic devices use semiconductors (transistors, diodes) to actively control current flow, enabling microcontrollers to read sensors, make decisions, and drive actuators in every IoT system.

9.1 Learning Objectives

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

  • Classify Semiconductor Materials: Distinguish conductors, insulators, and semiconductors by their electrical properties
  • Differentiate N-type and P-type: Describe doping processes and predict semiconductor behavior based on impurity type
  • Analyze Diode Operation: Trace one-way current flow through PN junctions and select diodes for protection circuits
  • Compare Transistor Types: Evaluate BJT versus FET transistors and justify selection for specific IoT applications
  • Design Switch Circuits: Calculate component values for transistor-based digital switches in IoT devices

Simple Analogy: Electronics as the Brain and Nerves

Think of an IoT device like a human body: - Electricity = blood flowing through veins (provides energy) - Electronics = brain and nervous system (controls what happens) - Transistors = neurons (make decisions: “fire” or “don’t fire”) - Circuits = neural pathways (connect sensors to actions)

Just as your brain decides “too hot → sweat” or “danger → run,” electronics decide “temperature > 75°F → turn on fan” or “motion detected → send alert.”

Why Electronics ≠ Electricity

Electrical Device Electronic Device Key Difference
Light bulb - flip switch → light on Smart bulb - phone command → chip decides → light on Electronics add intelligence
Fan - plug in → spins at fixed speed Smart fan - sensor reads temp → microcontroller adjusts speed Electronics react to sensors
Heater - always on when plugged in Smart thermostat - monitors temp → turns heater on/off automatically Electronics make decisions

The magic ingredient? Transistors - tiny electronic switches that can turn on/off millions of times per second, making all digital logic possible.

Key Building Blocks Explained

Component Simple Explanation Real-World IoT Example Why It Matters
Voltage (V) Electrical “pressure” pushing electrons 3.3V from ESP32 GPIO pin Too high voltage = fried components
Current (I) Flow of electrons (like water flow rate) LED draws 20mA Too much current = overheating
Resistance (R) Opposition to current flow 220Ω resistor limits LED current Prevents component damage
Ohm’s Law V = I × R (the fundamental relationship) V=3.3V, LED Vf=2V, needs 20mA → R=(3.3−2)/0.02=65Ω → use 68Ω resistor Design every circuit with this
Diode One-way valve for electricity Prevents battery reverse polarity damage Protects expensive circuits
Transistor Electronic switch controlled by voltage/current ESP32 pin (3.3V) controls 12V motor via transistor Microcontrollers can’t directly drive high-power loads

Real Numbers: Why You Need Electronics Knowledge

Without Electronics Knowledge With Electronics Knowledge Impact
Connect LED directly to GPIO → LED or GPIO burns out Add 220Ω resistor → LED lights safely Prevent $20 ESP32 damage
Control relay with GPIO pin → GPIO pin damaged Use transistor switch → relay works perfectly Avoid 40mA relay coil damaging 12mA GPIO
Battery lasts 6 months → acceptable? Optimize with MOSFET load switching → 5 year battery life 10× improvement
Trial-and-error debugging (4 hours) Read datasheet, calculate voltages → fix in 15 minutes 16× faster debugging

The Most Important Electronics Concepts for IoT

  1. Transistors as Switches (90% of IoT usage):
    • Microcontroller GPIO can only provide 10-40mA
    • Motors, relays, high-power LEDs need 100mA to 10A
    • Transistor acts as electronically-controlled switch: small signal controls big load
    • Example: ESP32 (12mA) → Transistor → 1A LED strip
  2. Power vs Signal (Critical distinction):
    • Signal: 3.3V GPIO, I2C/SPI data lines (low current, logic levels)
    • Power: Motor supply, LED strips, actuators (high current, voltage can vary)
    • Never mix these! Use transistor to separate signal from power
  3. Current Limiting (Protect everything):
    • LEDs without resistors → burn out in seconds
    • Transistors without base resistors → damaged GPIO
    • Always calculate resistor values, don’t guess

Quick Self-Assessment

Before proceeding, can you answer these?

Question Beginner Answer You Should Know
“Can I connect a 5V sensor directly to ESP32 (3.3V)?” “Let me try…” ❌ “No! Need level shifter or voltage divider” ✓
“LED not lighting, what’s wrong?” “LED is broken” ❌ “Check: polarity? resistor value? voltage? current?” ✓
“How to control 12V motor with ESP32?” “Connect GPIO to motor wire” ❌ “Use transistor (MOSFET) as switch + flyback diode” ✓

If you got those right, you’re ready for this chapter. If not, read carefully and take notes!

Recommended Learning Path:

  1. Start: Read this chapter (Electronics Fundamentals) - understand transistors
  2. Foundation: Study Electricity - master Ohm’s Law and power calculations
  3. Application: Sensor Circuits - connect real sensors
  4. Practice: Sensor Labs - hands-on ESP32 projects

Electronics is like having a super-smart brain that can make decisions about electricity!

9.1.1 The Sensor Squad Adventure: The Traffic Controller

Max the Microcontroller was very proud of his special friend - a tiny switch called Terry the Transistor. “Terry can turn electricity on and off super fast!” Max explained. “Even faster than you can blink!”

One day, Sammy the Sensor detected that a room was getting too hot. “It’s 30 degrees! Too warm!” Sammy reported. Max thought quickly. “Terry, we need to turn on the cooling fan!” But the fan needed lots of electricity - way more than Max could provide by himself. Terry the Transistor said, “Don’t worry, Max! You just give me a tiny signal, and I’ll let the big electricity through to power the fan!”

Lila the LED watched in amazement as Terry worked. With just a whisper from Max (a tiny signal), Terry opened a big gate that let powerful electricity flow to the fan. “It’s like being a traffic controller!” Lila said. “A small hand signal can stop or start huge trucks!” Bella the Battery smiled. “That’s exactly right! Electronics are smart controllers. They use tiny signals to control big power - that’s why your tablet can play videos, your toys can talk, and smart homes can do amazing things!”

9.1.2 Key Words for Kids

Word What It Means
Electronics Smart parts that can control and direct electricity
Transistor A tiny switch that can turn electricity on/off really fast
Microcontroller A mini computer brain that makes decisions
Signal A message sent using electricity (like a secret code)
Chip A tiny piece with millions of transistors inside
Circuit Board A flat board where electronic parts connect together

9.1.3 Try This at Home!

Play the Transistor Game!

  1. One person is the “Microcontroller” (the boss who gives quiet commands)
  2. One person is the “Transistor” (the gatekeeper)
  3. Other people are “Electricity” waiting to get through

Rules:

  • The Microcontroller whispers “ON” or “OFF” to the Transistor
  • When the Transistor hears “ON,” they open their arms and let Electricity people walk through
  • When they hear “OFF,” they block the path with closed arms
  • The Electricity people can ONLY pass when the Transistor opens the gate!

What you learned: Just like in real electronics, a tiny command (whisper) controls whether big electricity (people) can flow through. That’s how transistors work in all your electronic devices!

9.2 Prerequisites

Before diving into this chapter, you should be familiar with:

  • Electricity Fundamentals: Understanding voltage, current, resistance, Ohm’s Law, and power calculations is critical for analyzing transistor circuits and calculating bias resistor values
  • Atomic Structure: Basic knowledge of atoms, electrons, protons, and electron shells helps you understand semiconductor physics, doping, and PN junctions
  • Circuit Analysis: Ability to read circuit diagrams and apply Kirchhoff’s laws for analyzing transistor switching and amplifier circuits
Why Electronics Matters for IoT

Transistors are the foundation of all modern computing. Every microcontroller, sensor, and communication module in IoT contains billions of transistors. Understanding how they work is essential for IoT hardware design.

Key Concepts
  • Semiconductor: Material with controllable conductivity between conductors and insulators; foundation of all electronics
  • Doping: Adding impurities to silicon to create N-type (excess electrons) or P-type (excess holes) semiconductors
  • Diode: Two-layer semiconductor (PN junction) allowing current flow in only one direction; forward bias conducts, reverse blocks
  • Transistor: Three-layer semiconductor acting as voltage/current-controlled switch or amplifier; building block of all digital logic
  • BJT (Bipolar Junction Transistor): Current-controlled device where small base current controls large collector-emitter current
  • FET (Field Effect Transistor): Voltage-controlled device where gate voltage controls drain-source current; nearly zero input current
Key Takeaway

In one sentence: Transistors are tiny electronically-controlled switches that bridge the gap between low-power microcontroller signals and high-power real-world loads–mastering this concept unlocks all IoT hardware design.

Remember this rule: Always check three things before connecting a load to a GPIO pin–required current (does it exceed GPIO limits?), required voltage (does it match logic level?), and load type (inductive loads need flyback diodes).


9.3 From Electricity to Electronics

Electronics is the study and application of devices that control electron flow using semiconductors.

While electrical devices (motors, heaters, lamps) just use current flow, electronic devices (computers, sensors, microcontrollers) actively control and manipulate current using semiconductors.

9.3.1 Analog to Digital Signal Flow in IoT Systems

One of the most critical electronics concepts for IoT is how analog sensor signals are converted to digital data:

Flowchart showing signal flow from physical phenomenon through sensor transducer, analog signal conditioning, ADC conversion, digital processing by microcontroller, to wireless transmission

Analog to digital signal flow in IoT systems
Figure 9.1: Signal flow from physical phenomenon to wireless transmission in IoT systems. Physical events (temperature, light, pressure) are converted by sensor transducers into continuous analog voltages (0-3.3V), conditioned through amplification and filtering circuits, digitized by ADC converters into discrete binary values (10-16 bit resolution), processed by microcontrollers, and transmitted wirelessly. Orange nodes represent analog domain, teal nodes represent digital domain, with ADC as the critical bridge between continuous and discrete signal representations.

This layered variant emphasizes the domain boundaries between physical, analog, and digital realms, helping students understand where signal transformations occur and what challenges exist at each transition.

Signal domains diagram showing physical, analog, and digital domain boundaries with signal transformations and error sources at each processing stage
Figure 9.2: Domain boundary view showing signal transformations and error sources at each processing stage.

Key Stages Explained:

  1. Physical → Sensor: Environmental changes (temperature rises from 20°C to 25°C) are converted to electrical signals
  2. Analog Signal: Continuous voltage proportional to physical quantity (e.g., 10mV per °C)
  3. Signal Conditioning: Amplify weak signals (µV → mV), filter noise, level shift to ADC input range
  4. ADC Conversion: Sample analog voltage at regular intervals, quantize to nearest digital value
  5. Digital Processing: Microcontroller applies calibration, averages readings, detects thresholds
  6. Wireless Transmission: Packaged data sent via communication protocol to cloud or gateway

Example - Temperature Sensor Chain:

  • NTC Thermistor: 10kΩ at 25°C → Voltage divider: 1.65V → Op-amp gain ×2: 3.3V → 12-bit ADC: 4095 → ESP32 converts to 25.0°C → MQTT publishes value

9.4 Interactive Electronics Calculators

Before diving into semiconductors, let’s master the practical calculations you’ll use daily in IoT development.

9.4.1 Ohm’s Law Calculator

Ohm’s Law (V = I x R) is the foundation of all circuit analysis. Use this calculator and reference when designing your IoT circuits.

Using the Ohm’s Law Calculator

Common IoT Applications:

1. LED Current Limiting:

  • Supply voltage - LED forward voltage = voltage across resistor
  • R = V_resistor / I_desired
  • Always use next higher standard resistor value

2. Pull-up/Pull-down Resistors:

  • Typical values: 10kΩ (low power), 4.7kΩ (faster switching), 1kΩ (strong pull)
  • Higher resistance = less current = longer battery life
  • Lower resistance = faster response time

3. Power Budget:

  • Calculate power for each component: P = V × I
  • Sum total power consumption
  • Verify power supply can handle total current
  • Check individual component power ratings (¼W, ½W, 1W resistors)

Standard Resistor Values (E12 series): 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82 (and multiples: ×10, ×100, ×1k, ×10k, ×100k)

9.4.2 LED Resistor Calculator

LEDs are everywhere in IoT - status indicators, displays, and debugging. This tool calculates the perfect current-limiting resistor.

9.4.3 Voltage Divider Calculator

Voltage dividers are essential for reading analog sensors and interfacing different voltage levels. This tool helps you design voltage dividers for IoT applications.

9.4.4 Battery Life Calculator

Understanding battery life is critical for IoT devices. This tool calculates runtime based on current consumption and sleep modes.

9.4.5 IoT Device Power Supply Architecture

Now that you can estimate battery life, let’s examine how power flows through your IoT device and where optimization opportunities exist:

Block diagram showing IoT power distribution from sources like battery, USB, and solar through regulation stages including LDO, buck converters, and PMIC load switches to device loads with protection circuits

IoT device power supply architecture
Figure 9.3: IoT device power supply architecture showing complete power distribution from sources (battery, USB, solar) through power management (charger ICs, LDO regulators, buck converters, PMIC load switching) to device loads (microcontroller, wireless radio, sensors, actuators) with protection circuits (flyback diodes, TVS/Zener overvoltage protection, fuses). Orange nodes are power sources, navy nodes are power regulation, teal nodes are digital loads, gray nodes are high-power loads requiring transistor switches and protection circuits.

9.4.6 Alternative View: Power Source Selection Decision Tree

This decision tree helps IoT designers select the optimal power source based on deployment constraints. Rather than showing power flow, it guides through the critical questions that determine which power architecture is feasible for your application.

Decision tree for selecting IoT power sources based on mains availability, size constraints, deployment location, battery chemistry, and expected duration
Figure 9.4: Decision tree for selecting IoT power sources: Start with mains availability, consider size constraints and deployment location, then match battery chemistry to expected deployment duration. Solar is viable when average current is low enough for panel sizing. Energy harvesting suits long-term, maintenance-free installations.

Power Path Strategies:

  1. Linear Regulation (LDO): Simple, low noise, but inefficient
    • Use for: Microcontroller and sensitive analog sensors
    • Efficiency: 60-70% (Vout/Vin)
    • Example: 5V → 3.3V LDO wastes (5-3.3) × current as heat
  2. Switching Regulation (Buck Converter): Complex but efficient
    • Use for: Battery-powered devices, high current loads
    • Efficiency: 80-95% regardless of voltage difference
    • Example: 12V → 3.3V at 90% efficiency vs 27.5% for LDO
  3. Load Switching via PMIC: Gate power to unused peripherals
    • Use for: Sensors, radios not continuously needed
    • Savings: Eliminate standby current (often 100µA - 10mA per device)
    • Implementation: P-channel MOSFET controlled by MCU GPIO
  4. Direct Battery Connection: Bypass regulators when possible
    • Use for: High-power actuators (motors, solenoids)
    • Control: MOSFET switch from MCU GPIO
    • Protection: Flyback diode for inductive loads
Battery Life Optimization Strategies

1. Sleep Mode Selection:

  • Light sleep: 2mA, wake in <1ms, RAM preserved
    • Use for: Frequent wake-ups (<1 second intervals)
  • Deep sleep: 0.01mA, wake in 100ms, 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 10ms every 100ms-1s
  • LoRaWAN: 100-150mA for 50ms-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)
Check Your Understanding: Power Budgeting


9.5 Knowledge Check

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.

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 ✓ Safe
Id (continuous drain current) 47A 2A motor ✓ Massive headroom
Vgs(th) (gate threshold) 1-2V 3.3V GPIO ✓ Fully on at 3.3V
Rds(on) @ Vgs=4.0V ~0.035Ω Low resistance ✓ Minimal voltage drop (note: 0.022Ω spec is at Vgs=10V; at 3.3V Rds(on) is higher)
Package TO-220 Through-hole ✓ Easy to prototype

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

Circuit:

ESP32 GPIO (3.3V) ──[100Ω]──┬─── MOSFET Gate
                            │
                           [10kΩ] Pull-down
                            │
                           GND

12V ────┬─── Motor ────┬─── MOSFET Drain
        │              │
        └──── [D1] ────┘
           (1N4007)
          cathode→12V

                         MOSFET Source ─── GND

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
Gate voltage when ON 3.3V 3.27V
Gate voltage when OFF 0V 0.01V ✓ (pull-down working)
Motor voltage when ON 12V 11.90V ✓ (~0.1V drop across MOSFET at Vgs=3.3V)
Motor current 2A max 1.8A running ✓ (below stall current)
MOSFET temperature <50°C 32°C ✓ (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, won’t fully turn on ✓ Use logic-level MOSFET (Vgs=3.3V)
❌ 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 (\(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): | 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:

  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

9.6 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

9.7 See Also

Electronics Foundations:

Practical Applications:

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.

9.8 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