ESP32 & analog: the world is more than on and off
420-302-VA · WEEK 8 · FALL 2026

Week 8 · Monday, October 26, 2026 · Room D-221

A second computer joins the bench, and it can do something the Pi cannot.

The Raspberry Pi, for all its Linux muscle, has no analog input: it can ask "is the pin high or low?" but never "how much?". Today the ESP32 microcontroller arrives to answer that question, running Python you already know, reading light as a number from 0 to 65535, and taking its place as the sensor node of the system this course has been promising since Week 1. Assignment 2 is released today.

1 h theory 2 h lab Bring the breadboard kit A2 released · 15% · due Week 10
The Week 8 path: why a second computer, meet the ESP32, analog in, analog out, Assignment 2, and the hand-in 1Two computers 2Meet the ESP32 3Analog in 4Analog out 5Assignment 2 6Hand-in Week 9: MQTT

What happens today

Theory · first hour

Microcontrollers, ADCs and PWM

What a microcontroller is and why it exists beside computers rather than instead of them; firmware and MicroPython; how an analog-to-digital converter turns a voltage into a number (resolution, quantization, the divider circuit); and how pulse-width modulation fakes an analog output with a fast digital one.

Start with Meet the ESP32 →

Lab · two hours

From box to light meter

Flash MicroPython onto your ESP32, blink its LED from a serial REPL, wire the light-divider circuit, watch raw counts respond to your hand, then close the week with a PWM LED that follows the light, a ladder of specs ending in a LightNode class, and the first pass through the Assignment 2 brief.

What Assignment 2 asks →

In the course outline

This is Week 8 of 420-302-VA and the start of phase 3, sensors and network. Assignment 2, the PID light-harvesting brief (15%), is released today on Omnivox and is due in Week 10 (Monday, November 9); its own document governs the details, and the Assignment 2 page is the guide to working it. The ESP32 you receive today is the system's sensor node: Week 9 connects it to the Pi over Wi-Fi and MQTT, Week 10 closes the control loop, and the same board carries into the LIA project. The administrative course-drop deadline (AE) is Tuesday, November 3.

The second half begins

The midterm is behind you; feedback follows in class. Whatever Monday felt like, the plan from here is the same: the second half of the course is where the six weeks of toolkit get spent. Nothing from Weeks 1 to 7 retires today, quite the opposite: you will Git-manage this week's code, SSH habits return next week, the W5 design method is how A2 is meant to be worked, and the W6 classes run unchanged on the new board. The reflection habit continues too; the project's milestones will ask for it.

Why a second computer

Put the two machines side by side and the question answers itself: they are good at different things, and real IoT systems use both.

  • The Pi is a computer: an operating system, a filesystem, networking, a browser's worth of horsepower. It is superb as a hub, storing data, running services, serving a dashboard, and helpless at the physical edge: it has no analog input at all, boots in half a minute, and burns watts doing nothing.
  • The ESP32 is a microcontroller: one chip holding processor, memory, storage, Wi-Fi and a rack of peripherals, analog converters included. It runs your program and nothing else, starts in under a second, sips milliamps, costs a few dollars, and can sit next to a sensor for months. It is superb at the edge and cramped as a hub.
  • So the architecture splits the work: cheap, low-power nodes sense and act where the physics is; a hub collects, decides at the system level, and talks to humans. That split is not a classroom simplification; it is how greenhouses, factories and buildings are actually instrumented, and it is the course's target system exactly.

Why this course teaches it now

The skills transfer whole

MicroPython is Python: your variables, loops, functions and classes from Weeks 4 to 6 run on the ESP32 unchanged in all but detail. Seven weeks of investment pays out on new hardware in one afternoon.

A2 needs this week

The light-harvesting brief stands on exactly today's bench: an analog light reading in, a PWM output out. This week builds the sensing and acting; Week 10 adds the control law between them.

The network needs a node

Week 9's MQTT lesson is only interesting if something has data worth publishing. After today, something does: a calibrated light percentage, ticking along once a second, waiting for a network.

Three ideas you will reuse for the rest of the course

Measurement is discretization

An ADC chops a continuous voltage into one of 2N steps. Resolution, counts and quantization error are the vocabulary of every sensor you will ever read, from today's light level to any plant's 4-to-20 mA loop.

Average output from fast switching

PWM makes an analog-feeling output from a digital pin by controlling the fraction of time spent on. Duty cycle runs LEDs today, and motors, heaters and valves for the rest of your career.

Node and hub

Small machine at the edge, big machine in the middle. Every design decision from here, what runs where, what gets sent, what gets stored, is an application of this split.

What you will be able to do by the end of the week

  • Explain the microcontroller/computer split and place each machine in the course architecture.
  • Flash MicroPython firmware onto an ESP32 and drive it from a serial REPL in Thonny.
  • Compute an ADC's step size from its resolution and reference, and convert counts to volts.
  • Derive the voltage-divider equation and predict the light circuit's voltage for a given LDR resistance.
  • Read a calibrated light percentage, smoothed by averaging, from your own LightNode class.
  • Dim an LED with PWM, explain duty cycle, and distinguish open-loop from closed-loop behaviour.
  • Make the first engineering pass through the Assignment 2 brief and start its verification table.

Words you will hear all day

TermPlain meaningCommon mix-up to avoid
Microcontroller (MCU)A one-chip computer: CPU, memory, storage and peripherals together, running one program.Not a small Raspberry Pi; there is no operating system under your code.
FirmwareThe program stored in the chip's flash, running from power-on.On a microcontroller the firmware is not "low-level extras"; it is everything.
MicroPythonA firmware that is a Python interpreter, so your scripts become the board's behaviour.A lean subset of Python, not a different language; machine replaces gpiozero.
REPL (serial)The live >>> prompt, reaching the board over the USB cable.Same REPL idea as Week 4, different transport: serial line, not SSH.
ADCAnalog-to-digital converter: turns a voltage into a number.It measures voltage at its pin, not "light"; the circuit turns light into voltage first.
Resolution / countsHow many steps the ADC can tell apart (12-bit = 4096); a reading is a count of steps.More counts is finer, not more accurate; noise and calibration decide accuracy.
Voltage dividerTwo resistances in series splitting a voltage in proportion.The output comes from the midpoint node, not across either part alone.
LDRLight-dependent resistor: resistance falls as light rises.It is a resistor, not a voltage source; it only senses inside a circuit.
PWMPulse-width modulation: fast on/off switching whose on-fraction sets the average.The pin still only outputs 0 or 3.3 V; the average is in the timing.
Duty cycleThe on-fraction of each PWM period, 0 to 100% (0 to 65535 in code).Duty sets level; frequency sets how fast the switching repeats. Different knobs.
CalibrationMapping raw counts to meaning using readings you took (dark, bright).Your bench's numbers, not the internet's; every bench is different.
Open / closed loopOutput follows input blindly vs output corrected by measuring its own effect.This week is open loop by design; A2 and Week 10 close it.

Where this fits in the course

Week 7 · Oct 19

Midterm and reflection log

The consolidation point: everything revised there, tools, Python, design, classes, is in active service again today.

Week 8 · Oct 26 · this hub

ESP32 and analog

The second computer: MicroPython, the ADC and the light divider, PWM, a LightNode class, and the Assignment 2 launch.

Week 9 · Nov 2

MQTT: the boards talk

The node's readings leave the USB cable for Wi-Fi: a broker on the Pi, publish and subscribe, and the message format you design this week going live.

Working at home

This week is the most home-portable bench of the term: the ESP32 travels in your kit, Thonny runs on any laptop (thonny.org, the same editor from Week 4), and the whole lab needs only a USB data cable, no Pi, no network. The one caveat is the cable: many phone-charging cables carry power but no data, and a board that powers up yet never shows a port is usually that cable, not a broken board. The troubleshoot page starts there.