Electronics for Building Things · Lesson 18 · Motion & the Physical World

Sensors: Reading 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 one win For any sensor, you can tell how it connects (digital pin, analog pin, or a bus) and how your code will read it.

Three kinds, by how you read them

1. Digital (on / off)

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

2. Analog (a varying level)

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.

3. Digital-bus ("smart") sensors

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.

SensorSensesHow you read it
PIRMotionDigital pin
Reed switchDoor/window openDigital pin
PhotoresistorLight levelAnalog pin (divider)
ThermistorTemperatureAnalog pin (divider)
BME280 / DHTTemp, humidityI²C (library)
Ultrasonic / ToFDistanceDigital timing or I²C
Rule of thumb Before buying or wiring a sensor, check two things: its interface (digital / analog / I²C-SPI) and its voltage (3.3V vs 5V — Lesson 4 still rules). When you want real units with little effort, prefer an I²C "smart" sensor.

The whole gadget, at last

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.

Check yourself

Read this next (primary source) Browse SparkFun's Sensors tutorials and pick the guide for a sensor you actually want to use — they include wiring and code.
I'm your teacher — ask me anything. Tell me what you want to sense in your home and I'll recommend a specific sensor, its interface, and how to read it. This is a great place to start designing your first real gadget together.

See also: Glossary · Component field guide · Signals & buses