2 Electricity Fundamentals
2.1 Introduction
A soil moisture sensor deployed in a vineyard stops reporting after 3 weeks — the battery was sized for 6 months. A student’s first ESP32 project burns out an LED within seconds. An industrial temperature logger produces wildly noisy readings because the power supply wasn’t filtered. What do these failures have in common?
Every one of them comes down to two equations: Ohm’s Law (\(V = I \times R\)) and the Power Law (\(P = V \times I\)). Master these, and you can analyze any resistive circuit, calculate component values, estimate power consumption, and determine battery life for any IoT project. Get them wrong, and you’ll burn components, drain batteries, and waste weeks debugging.
2.2 Learning Objectives
After completing this chapter, you will be able to:
- Explain how voltage, current, and resistance relate through Ohm’s Law
- Calculate component values for LED current limiting, pull-up resistors, and voltage dividers
- Estimate battery life for duty-cycled IoT devices
- Design power budgets for multi-component IoT systems
- Identify common electrical mistakes that damage hardware
- Interpret circuit diagrams and translate schematic symbols into physical connections
Key Concepts
- Voltage (V): The electrical potential difference between two points; measured in volts (V); drives current to flow from high potential to low potential through a conductor; a battery maintains a voltage difference between its positive and negative terminals
- Current (I): The rate of charge flow through a conductor; measured in amperes (A); 1 A = 1 coulomb per second; flows from positive to negative terminal through the external circuit (conventional current direction)
- Resistance (R): Opposition to current flow; measured in ohms (Ohm); a high resistance limits current for a given voltage; materials with near-zero resistance are conductors, near-infinite resistance are insulators
- Ohm’s Law: V = I x R: the voltage across a resistive element equals the current through it times its resistance; rearranges to I = V/R and R = V/I; applies to resistors, not to LEDs, capacitors, or inductors
- Power Law: P = V x I = I^2 x R = V^2/R: electrical power in watts dissipated by a component; determines component power ratings and battery consumption; a 3.3 V device drawing 100 mA consumes 0.33 W
- Direct Current (DC): Current flowing in one constant direction; produced by batteries, regulated power supplies, and solar cells; used in all digital microcontroller circuits and most IoT sensor systems
- Alternating Current (AC): Current reversing direction at regular frequency (50 or 60 Hz for mains power); transmitted efficiently at high voltage over long distances; converted to DC by power supplies before use in IoT systems
- Ground (GND): The common reference point (zero volts) in a circuit; all voltages are measured relative to ground; all current must return to the power source through a ground path — an open ground breaks all circuits sharing that ground
2.3 Prerequisites
- Basic algebra (solving for variables in equations)
- IoT Reference Models — understand where electrical principles fit in the hardware layer
For Beginners
Think of electricity as water flowing through pipes. A battery is like a water pump pushing water through a pipe system. Voltage is the water pressure (how hard it pushes). Current is the flow rate (how much water passes per second). Resistance is a narrow section of pipe (it slows the flow down).
The key insight: if you increase pressure (voltage) through the same pipe (resistance), more water flows (current). That’s Ohm’s Law — \(V = I \times R\) — and it governs every electrical circuit in every IoT device ever built.
2.4 Chapter Overview
This chapter is organized into five focused sections. Each builds on the previous one.
2.4.1 1. Introduction — What is Electricity?
Beginner | ~30 min
Voltage, current, resistance, atoms and electrons, water analogies, circuit diagrams.
Key takeaway: Distinguish V, I, and R — the three quantities that define every circuit.
2.4.2 2. Ohm’s Law — The One Equation You Need
Intermediate | ~45 min
V = I × R in practice: LED current limiting, battery life calculations, voltage dividers, I2C pull-up sizing.
Key takeaway: Apply V = I × R and P = V × I to calculate component values for any IoT circuit.
2.4.3 3. Common Pitfalls — Mistakes That Burn Hardware
Intermediate | ~20 min
Unit confusion (mA vs A), forgetting voltage drops, exceeding GPIO current limits, ignoring power dissipation.
Key takeaway: Always check units, power ratings, and current limits before building circuits.
2.4.4 4. Applications and Labs — Build Real Circuits
Intermediate | ~40 min
Passive components (resistors, capacitors, inductors), real-world IoT circuits, interactive simulations.
Key takeaway: Apply electrical principles to build working IoT prototypes.
2.4.5 5. Reference and Resources — Quick Lookup
All levels | ~30 min
Formula reference, component values, review quiz (20+ questions), troubleshooting guide.
2.4.6 Which Path Should I Take?
| Your Background | Recommended Path | Time |
|---|---|---|
| Absolute beginner | Start with Introduction → watch videos → try Ohm’s Law tools → bookmark Reference | ~2 hrs |
| Student / hobbyist | Introduction + Ohm’s Law → study worked examples → review Pitfalls → complete Labs | ~2.5 hrs |
| Professional developer | Skim Introduction → focus on IoT sections in Ohm’s Law (battery life, voltage dividers, I2C pull-ups) → study Pitfalls | ~1.5 hrs |
2.5 Core Concepts Map
Before diving into formulas, here’s the big picture — four concepts and how they connect:
2.6 Quick Reference
Keep these formulas and values handy as you work through the sub-chapters — you’ll reference them constantly.
Definition: Ohm’s Law
Ohm’s Law states that voltage across a conductor equals the current through it multiplied by its resistance: \(V = I \times R\). Rearranged: \(I = V/R\) (to find current) or \(R = V/I\) (to find resistance). This single equation is the foundation of all resistive circuit analysis.
2.6.1 Key Equations
| Equation | What It Calculates | Example |
|---|---|---|
| \(V = I \times R\) | Voltage, current, or resistance | 3.3V / 330Ω = 10mA through an LED |
| \(P = V \times I\) | Power consumption | 3.3V × 100mA = 330mW for an ESP32 |
| \(R_{series} = R_1 + R_2\) | Series resistance | 100Ω + 220Ω = 320Ω total |
| \(R_{parallel}^{-1} = R_1^{-1} + R_2^{-1}\) | Parallel resistance | Two 10kΩ in parallel = 5kΩ |
| Battery life = Capacity / Current | Runtime estimate | 2000mAh / 1.34mA ≈ 62 days |
2.6.2 Try It: Ohm’s Law Calculator
Drag the sliders to see how voltage, current, resistance, and power relate:
2.6.3 Typical IoT Values
These are the numbers you’ll use most often when designing IoT circuits:
| Component | Typical Current | Typical Voltage | So What? |
|---|---|---|---|
| LED | 10-20 mA | 2-3V forward | Needs a current-limiting resistor from GPIO |
| ESP32 (active) | 80-200 mA | 3.3V | Draws 330-660mW — the power hog in most designs |
| ESP32 (deep sleep) | 10-150 µA | 3.3V | 1000× less than active — why duty cycling matters |
| Sensor (passive) | 0.1-10 mA | 3.3-5V | Usually negligible in power budgets |
| LoRa TX | 20-120 mA | 3.3V | Brief bursts (50ms) but high current — size your battery for peaks |
2.6.4 Safety Thresholds
| Current Through Human Body | Effect |
|---|---|
| 1 mA | Tingling sensation |
| 10 mA | Cannot let go of conductor |
| 100 mA | Ventricular fibrillation (potentially fatal) |
Hardware limit to remember: GPIO pins can source/sink 20-40 mA max per pin. Exceeding this damages the microcontroller permanently.
Putting Numbers to It: Why Duty Cycling Changes Everything
The math: An ESP32 drawing 100mA continuously from a 2000mAh battery lasts just \(2000 / 100 = 20\) hours. But wake it for only 1 minute per hour? Watch what happens:
- Active average: \(100\text{mA} \times (1/60) = 1.67\text{mA}\)
- Sleep average: \(0.01\text{mA} \times (59/60) = 0.01\text{mA}\)
- Total: \(1.68\text{mA}\)
- Battery life: \(2000 / 1.68 = 1{,}190\) hours ≈ 50 days — a 60× improvement from one design decision.
Try it yourself — adjust the sliders below to design your own duty cycle:
2.7 How Much Do You Already Know?
Try these five questions before reading the sub-chapters. Your score tells you where to start:
How did you do?
- 4-5 correct: Solid fundamentals — focus on IoT-specific applications in Ohm’s Law.
- 2-3 correct: Start with the Introduction and work through each section.
- 0-1 correct: No worries! Begin with the Introduction — it teaches everything from scratch.
2.8 Worked Example: Smart Thermostat Power Budget
Ready to see all these concepts working together? This end-to-end design walkthrough combines Ohm’s Law, power budgeting, duty cycling, and component selection into a single real project.
Complete Design Walkthrough
Scenario: You’re designing a wall-powered smart thermostat with battery backup. Calculate the complete power budget and determine battery backup runtime.
System Components:
- ESP32 microcontroller (Wi-Fi enabled)
- 2.4” TFT display (always on)
- Temperature sensor (DHT22)
- Relay (controls HVAC system)
- Battery backup: 2×AA NiMH in series (2500mAh @ 2.4V nominal)
Series vs. Parallel: Batteries in series add voltage but keep the same capacity (2 × 1.2V = 2.4V, still 2500mAh). Batteries in parallel keep voltage but add capacity (still 1.2V, but 5000mAh). Confusing these is one of the most common exam mistakes!
Step 1: Current Draw for Each Component
| Component | Voltage | Current (mA) | Duty Cycle | Avg Current (mA) | Power (mW) |
|---|---|---|---|---|---|
| ESP32 (Wi-Fi TX) | 3.3V | 200 | 2% (4s every 200s) | 4.0 | 13.2 |
| ESP32 (active) | 3.3V | 80 | 98% | 78.4 | 258.7 |
| TFT display | 3.3V | 50 | 100% | 50.0 | 165.0 |
| DHT22 sensor | 3.3V | 2.5 | 100% | 2.5 | 8.3 |
| Relay (energized) | 5V | 70 | 20% (HVAC on 20%) | 14.0 | 70.0 |
| 3.3V rail total | 3.3V | 134.9 | 445 | ||
| 5V rail total | 5V | 14.0 | 70 | ||
| System total | — | 515 |
Why no total current? The relay draws 14mA at 5V while everything else runs at 3.3V. You cannot add currents across different voltage rails — that’s like adding apples and oranges. Always sum power (watts) when mixing voltages. The buck converter’s ~15% efficiency loss is accounted for in the battery runtime calculation below.
Step 2: Wall Power Supply
The system draws 515mW average. Peak during Wi-Fi TX + relay + display: (200 + 50) × 3.3V + 70 × 5V = 1175mW at the output. From a 5V supply: 1175mW / 5V ≈ 235mA peak. A 5V/1A USB adapter provides 4× safety margin for inrush currents.
Step 3: Battery Backup Runtime
Full operation: Available energy = 2.4V × 2500mAh × 0.85 (converter efficiency) = 5.1 Wh. Runtime = 5.1Wh / 0.515W = 9.9 hours.
Emergency mode (display off, BLE instead of Wi-Fi):
- ESP32 BLE: 40mA × 3.3V = 132mW
- DHT22: 2.5mA × 3.3V = 8mW
- Relay: 14mA × 5V = 70mW
- Total: 210mW
Runtime = 5.1Wh / 0.210W = 24.3 hours ≈ 1 day.
Step 4: Relay Drive Circuit
Can ESP32 GPIO drive the relay directly? No — relay needs 70mA but GPIO max is 40mA.
Solution: NPN transistor switch (2N2222)
- GPIO → 1kΩ → NPN base. Base current = (3.3V - 0.7V) / 1kΩ = 2.6mA
- With transistor gain β=100: collector capacity = 260mA (safely exceeds 70mA)
- Add flyback diode (1N4007) across relay coil to protect transistor
Step 5: Thermal Check
Peak simultaneous dissipation (worst case — Wi-Fi TX + relay energized): ESP32 at 200mA × 3.3V = 660mW, relay at 70mA × 5V = 350mW, plus ~10% regulator losses = 1.1W peak. Average is much lower (~515mW). For a 50mm × 80mm enclosure, passive cooling over PCB copper pour is sufficient for both peak and average loads.
Step 6: Bill of Materials
| Item | Cost |
|---|---|
| ESP32 module | $3.50 |
| TFT display | $6.00 |
| DHT22 sensor | $2.50 |
| 5V relay + transistor | $1.30 |
| Buck converter | $1.50 |
| Battery holder + 2×AA | $2.50 |
| 5V/1A power supply | $3.00 |
| PCB + passives + enclosure | $9.00 |
| Total BOM | $29.30 |
Key Insights:
- Duty cycling saves power: Relay at 20% duty = 5× less power than always-on
- Wi-Fi is expensive: 200mA peak, but 2% duty cycle makes it manageable
- Emergency mode extends backup 2.5×: Turning off the display (165mW saved) has the biggest single impact
- GPIO limits are real: 70mA relay needs a transistor driver — connecting directly would damage the ESP32
- Always add safety margins: 5-10× on power supply ratings for inrush currents
2.9 Hands-On Preview: LED Current Limiting
Want to try the most common calculation in IoT electronics? This is the first thing you’ll do in every ESP32 project with LEDs.
Problem: Connect a red LED (2V forward voltage, 20mA max) to an ESP32 GPIO pin (3.3V output). What resistor do you need?
Solution using Ohm’s Law:
- Voltage across resistor = \(V_{supply} - V_{LED} = 3.3\text{V} - 2\text{V} = 1.3\text{V}\)
- Target current = 10mA (safe value, below 20mA max)
- Resistor = \(V / I = 1.3\text{V} / 0.010\text{A} = 130\text{Ω}\)
Answer: Use a 150Ω resistor (next standard value up), which limits current to \(1.3\text{V} / 150\text{Ω} = 8.7\text{mA}\) — safe for both the LED and the GPIO pin.
Try different values — what if you use a 3V blue LED? A 5V supply?
Build and test this circuit virtually in Applications and Labs using interactive Wokwi simulations.
Check your understanding – why do we need that resistor at all?
2.10 Test Your Knowledge
2.11 Summary
Remember the three failures from the introduction? Here’s how this chapter’s concepts prevent each one:
- Power (\(P = V \times I\)) and duty cycling determine battery life — the vineyard sensor failed because nobody calculated that 100mA continuous drains 2000mAh in 20 hours
- Always use current-limiting resistors with LEDs — the student’s LED needed a 150Ω resistor to survive
- Power supply design matters — the noisy temperature logger needed proper filtering and decoupling, covered in Common Pitfalls
- Ohm’s Law (\(V = I \times R\)) is the foundation — every calculation above starts here
- GPIO pins have current limits (20-40mA) — exceed them and you damage the microcontroller
2.12 What’s Next
| Chapter | Focus | Why It Matters |
|---|---|---|
| Ohm’s Law Deep Dive | Practical circuit calculations | Master LED current limiting, battery life estimation, voltage dividers, and I2C pull-up sizing |
| Common Pitfalls | Mistakes that burn hardware | Prevent unit confusion, voltage drop errors, and GPIO overcurrent damage before they happen |
| Applications and Labs | Hands-on IoT circuits | Build and test real circuits with interactive Wokwi ESP32 simulations |
| Analog and Digital Electronics | Signal conversion | Apply electrical knowledge to ADCs, DACs, and the analog-digital boundary in IoT sensors |
| Sensor Fundamentals and Types | Sensor electrical interfaces | Connect voltage, current, and resistance knowledge to real sensor circuits |
| Energy-Aware Design | Power optimization | Extend battery life with duty cycling, sleep modes, and energy harvesting strategies |