class 10 · unit II · sensors, signals and sources of data
Every model starts at a sensor
Unit I treated the board as a box. Unit II opens it, starting where every pipeline starts: the sensor that turns the physical world into numbers.
Hand out the kits before you start: ESP32-S3, INMP441, MPU6050, breadboard. Today only the board and the MPU6050 are wired.
Unit II: what feeds the model, and what runs it.
Today is the first box: the ideas every sensor shares, before we meet the families one by one.
One line per box. The point is the split: five classes on what comes in, four on what computes.
Your phone has at least ten sensors. Name them.
Let the room shout answers first; reveal one label per click. The class numbers show where each family comes back in this unit. Exact sensors vary by phone model; not every phone has a barometer.
Every sensor is the same chain of six steps.
Walk a microphone along it: air pressure moves a diaphragm, the gap changes a capacitance, a tiny amplifier boosts it, an ADC samples it 16,000 times a second, and the samples leave on an I2S wire.
One box per click. Notice the signal gets small and noisy at step 2 and is restored at step 3: that is what conditioning is for.
In a modern digital sensor, four steps live in one chip.
You never see the analog signal. You configure the sensor (range, rate, filters) by writing to its registers, and read finished numbers back. That is why the datasheet matters so much: it is the only window into what happened inside.
The MPU6050 and INMP441 in the kit are both like this. A potentiometer or an LDR is the opposite: the board's own ADC does step 4. The 4 × 4 mm package size is the MPU6050's QFN package.
Five numbers to find on every datasheet.
range
how big?
the largest value before it saturates
resolution
how fine?
the smallest step it can report
rate
how often?
samples per second it can deliver
noise
how steady?
how much it wobbles when nothing changes
power
how costly?
current when active, and when asleep
MPU6050 accelerometer
from its datasheet
range
±2, ±4, ±8 or ±16 g, selectable
resolution
16-bit output
sensitivity at ±2 g
16,384 counts per g
INMP441 microphone
from its datasheet
output
24-bit audio over I2S
frequency response
about 60 Hz to 15 kHz
signal-to-noise ratio
about 61 dB
Bring both datasheets and show where each number sits. Values here are from the InvenSense datasheets; confirm them against your copies before class, especially the INMP441 figures.
try it live · an accelerometer on a table that gets tapped
Pick a range and a bit depth. What do you lose?
range
bits
WHOLE SIGNAL · 0 TO 4 g
ZOOM ON THE QUIET PART · 0.95 TO 1.05 g
The signal: gravity (1 g) plus a 20 mg wobble, then a tap that peaks near 3.4 g. ±2 g clips the tap; ±16 g at 8-bit flattens the wobble. Step size = 2 × range ÷ 2^bits. The MPU6050 is always 16-bit; the 8- and 12-bit options show what cheaper sensors and ADCs do.
Noise hides small signals. Power decides how often you can look.
noise · a small wave under heavy noise
Averaging 16 readings cuts random noise by about 4× (√16). The price: you see changes later. Class 8's filter trade-off again.
power · sleep most of the time
average ≈ active × duty + sleep
Illustrative: 1 mA active for 1% of the time, 10 µA asleep → about 20 µA on average, 50× less than always on.
The √N rule holds for random, independent noise. The power numbers are round illustrative values; the formula is the point. Link to Class 9's battery chart.
Who does the converting?
analog
digital
cost
very cheap
a little more
noise
picks up noise on the wire
immune once digitised
effort
you calibrate the ADC
configure registers
pins
one ADC pin each
many sensors share a bus
Ask why long analog wires are a bad idea near a motor (they pick up electrical noise). Digital sensors solved that by converting inside the package.
The S3's ADC turns a voltage into a number from 0 to 4,095.
12 bits → 212 = 4,096 levels
raw count
≈ voltage, 3.3 V full scale
0
0 V
2,048
≈ 1.65 V
4,095
≈ 3.3 V
one step
≈ 0.8 mV
the honest caveat
Real microcontroller ADCs are not perfectly linear, and their full-scale voltage depends on an attenuation setting.
Use the calibrated reading the framework provides (analogReadMilliVolts on the S3) rather than the simple formula.
A recurring lesson: the datasheet number and the measured number are not the same. Measure.
The 3.3 V full-scale mapping is a simplification for the arithmetic. 3.3 ÷ 4,096 ≈ 0.8 mV per step. The live demo prints both the raw count and the calibrated millivolts so students see the difference.
Four buses carry almost every sensor you will meet.
Camera modules use a fifth: a parallel bus with eight data lines and clocks (Class 12). Speeds are typical ranges.
I2C's trick: many devices on two wires, each with its own address. The MPU6050 answers at 0x68 (or 0x69 if its AD0 pin is pulled high). The live demo scans the bus and finds it.
an SD card for loggingfast, one chip-select per device
a camera moduleeight data lines and clocks
Hands up for each row before clicking. A wrong click turns red and shows the reason; the right one turns green.
Not every useful input comes from a sensor.
device state
battery voltage, Wi-Fi signal strength, free memory
e.g. is the device itself healthy?
user input
buttons, settings, corrections
e.g. the user just labelled a sample
other devices
a phone over BLE, a gateway's broadcast
e.g. context the device cannot sense
time
time of day, day of week, time since last event
e.g. a ring at 3 a.m. is unusual
the cloud
weather, schedules, a shared model
e.g. when the network is there
The prescribed topic is "sources of data", not just sensors. Some of the strongest features are free: the clock costs nothing and often beats a fancier sensor.
Ask what the doorbell could use from each tile. Time of day and Wi-Fi strength (is the network about to fail?) are the usual best answers.
// ESP32-S3 · Arduino core · three sources of data#include<Wire.h>const int POT_PIN = 4; // an ADC1 pin; check your boardvoidsetup() {
Serial.begin(115200);
Wire.begin(); // default I2C pinsfor (byte a = 1; a < 127; a++) { // 1 · scan the bus
Wire.beginTransmission(a);
if (Wire.endTransmission() == 0)
Serial.printf("I2C device at 0x%02X\n", a);
}
}
voidloop() {
int raw = analogRead(POT_PIN); // 2 · analogint mv = analogReadMilliVolts(POT_PIN);
float chip = temperatureRead(); // 3 · on-chip
Serial.printf("raw %4d %4d mV chip %.1f C\n", raw, mv, chip);
delay(200);
}
live demo · 10 minutes
Three sources, one sketch.
1. The scan should print 0x68: the MPU6050 answering on I2C.
2. Turn the potentiometer: raw counts and calibrated millivolts. Do they agree with 3.3 × raw ÷ 4,095?
3. The chip's own temperature. Touch the chip and watch it rise. It measures the chip, not the room.
Uses the Arduino-ESP32 core: analogReadMilliVolts and temperatureRead are available on the S3 in recent core versions; check yours. GPIO 4 is on ADC1 on the S3; confirm against your board's pin map. Without a potentiometer, an LDR with a resistor divider works.
our running example
Every input to the doorbell, through today's lens.
input
physical quantity
how it reaches the S3
more in
microphone
sound pressure
digital · I2S
Class 11
camera
light
digital · parallel
Class 12
touch button
capacitance
on-chip touch channel
Class 13
PIR wake-up
heat movement
digital · one GPIO high/low
Class 14
clock
time of day
not a sensor: free
today
Wi-Fi strength
signal level
not a sensor: device state
today
The next four classes take these families one at a time. The last two rows are today's point: the cheapest inputs are often not sensors at all.
exit ticket · on paper, before you leave
Pick one sensor in your phone. Name its physical quantity, its likely interface, and one number you would need from its datasheet before using it in a model.
Next class: acoustic and vibration sensors. Bring the INMP441; we record sound on the board.
Good answers name a concrete number: the accelerometer's range, the microphone's frequency response, the camera's frame rate.