Chapter 02
Electronics you need
Enough circuit theory to wire things without smoke: Ohm's law, resistors for LEDs, dividers, logic levels, pull-ups, a shared ground and clean power.
Ohm's law and power
Also called V = IR, P = VI, voltage, current, resistance
- What
- Voltage equals current times resistance (V = I x R), and power equals voltage times current (P = V x I).
- Why
- Every resistor value, current limit and battery estimate in this track starts from these two lines.
- Example
- 5 V across 1 kilohm gives 5 mA. That resistor then turns 5 V x 0.005 A = 25 mW into heat, well inside a quarter-watt rating.
Watch out
Mixing units, such as milliamps with ohms, and ending up a factor of 1,000 out.
LED current-limiting resistor
Also called series resistor, forward voltage
- What
- A resistor in series with an LED sets its current: R = (supply voltage minus LED forward voltage) / desired current.
- Why
- An LED has almost no resistance once it conducts. Without a resistor it draws as much current as the pin can give and can damage both.
- Example
- A red LED with about 2 V forward voltage on a 3.3 V pin at 5 mA needs (3.3 - 2) / 0.005 = 260 ohms, so use the next standard value, such as 270 ohms.
Watch out
Driving LEDs or anything else at the pin's absolute maximum current instead of a comfortable fraction of it.
Voltage divider
Also called potential divider, resistor divider
- What
- Two resistors in series across a voltage give Vout = Vin x R2 / (R1 + R2) at their midpoint.
- Why
- It scales a battery or a 5 V signal down into your ADC or input range, and it is how potentiometers and many resistive sensors are read.
- Example
- To measure a 12 V battery with a 3.3 V ADC, 100 kilohm over 27 kilohm gives 12 x 27 / 127 = 2.55 V at full charge.
Watch out
Using a divider to power a module: its output voltage sags as soon as the module draws current.
Logic levels: 3.3 V and 5 V
Also called level shifting, 5V tolerant, logic level converter
- What
- The voltages a chip reads as low and high. Classic Arduino Uno boards use 5 V logic; the ESP32, STM32 and Raspberry Pi GPIO use 3.3 V.
- Why
- A 5 V signal into a 3.3 V-only pin can destroy it. A 3.3 V high into a 5 V input may or may not be read reliably.
Watch out
Connecting a 5 V sensor output straight to an ESP32 or Raspberry Pi pin, or assuming every STM32 pin is 5 V tolerant when only pins marked FT in the datasheet are.
Pull-up and pull-down resistors
Also called pull-up, pull-down, floating input, INPUT_PULLUP
- What
- A resistor that holds an input at a known level when nothing drives it: a pull-up to the supply, a pull-down to ground. Most chips have weak internal ones you can enable.
- Why
- An unconnected input floats and reads random values. Buttons, I2C lines and open-drain outputs all depend on a pull resistor.
Watch out
Wiring a button without any pull resistor and chasing a "haunted" input that changes when you move your hand.
Common ground
Also called GND, ground reference
- What
- All connected devices must share the same ground, because every voltage is measured relative to it.
- Why
- A sensor on its own supply without a shared ground sends signals the board cannot interpret. Missing ground is the most common wiring bug.
Watch out
Powering a motor from a separate battery and forgetting to join its negative to the board's GND.
Power supply and decoupling
Also called decoupling capacitor, bypass capacitor, regulator, brownout
- What
- A regulator gives the board a steady voltage, and small capacitors (often 100 nF) placed next to each chip smooth out quick dips in current.
- Why
- Wi-Fi transmit bursts, motors and relays pull sudden current. Without enough supply and decoupling the board browns out and resets.
Watch out
Powering motors, servos or LED strips from the board's 3.3 V or 5 V pin instead of their own supply.