Electronics for Building Things · Lesson 18 · Motion & the Physical World
The input half of every gadget — and how each kind hands you its reading.
A home-automation device senses, then decides, then acts. You've built the acting (relays, motors, servos) and the deciding (the microcontroller). This lesson completes the loop: turning temperature, light, motion, and distance into numbers your code can use. The good news — you already know all three ways to read a sensor.
The sensor reports a yes/no, read with digitalRead (Lesson 14).
Examples: a PIR motion sensor (someone moved: yes/no), a reed switch
(door open/closed), a button. Often pair with a pull resistor (Lesson 5).
The sensor's resistance or voltage changes smoothly with the world; you read it with
analogRead (Lesson 10). Examples: a
photoresistor (light), a thermistor (temperature). These are usually
resistive, so you wire them as a voltage divider — exactly the
Lesson 8 pattern.
The richest type: a tiny module measures something precisely and reports real numbers over
I²C or SPI (Lesson 15). You install its library
and call sensor.readTemperature(). Examples: a BME280 (temperature,
humidity, pressure), distance sensors, accelerometers. For home automation, these give you the cleanest
data with the least fuss.
| Sensor | Senses | How you read it |
|---|---|---|
| PIR | Motion | Digital pin |
| Reed switch | Door/window open | Digital pin |
| Photoresistor | Light level | Analog pin (divider) |
| Thermistor | Temperature | Analog pin (divider) |
| BME280 / DHT | Temp, humidity | I²C (library) |
| Ultrasonic / ToF | Distance | Digital timing or I²C |
Put the course together and a home-automation device is a loop:
SENSE (this lesson) → DECIDE (your code on the ESP32) → ACT (relay / motor / servo) → and, with Wi-Fi, REPORT.
Every piece of that sentence is something you can now reason about from first principles. That's the whole point of the course.
See also: Glossary · Component field guide · Signals & buses