Assignment 1: From Physical Stimulus to Digital Data

12-778 — Sensors, Data, and Models in Engineering Systems

Author

Mario Bergés and Codex

Published

September 3, 2026

Why we are doing this

A facilities engineer wants to use two inexpensive sensors to control lights and document how a room is used. Connecting them to a microcontroller will produce data almost immediately. Producing trustworthy data is the harder part: What physical quantity caused each value? What did the interface circuit do to it? What information was discarded before the value reached the computer? Could the same setup distinguish a person sitting still from an empty room?

In this assignment, you will commission a small sensing node built from the hardware supplied in class. The GL5528 photoresistor will expose the complete analog measurement chain: light changes a resistance, a voltage divider turns that resistance into a voltage, and the ESP32 turns the voltage into an integer. The HC-SR501 takes a different route: its circuit converts the response of a passive infrared sensing element into a binary motion/no-motion decision before the ESP32 sees it. By the end, you should be able to explain not only how to collect both channels, but also what claims those channels do and do not support.

Learning objectives

By completing this assignment, you should be able to:

  • Trace the measurement chain from illumination or motion to a value reported by an ESP32.
  • Classify the transduction and output modality of the GL5528 and HC-SR501, distinguishing a sensing element from a sensor module.
  • Design and assemble a 3.3 V voltage divider that converts the GL5528 resistance into an ADC-compatible voltage.
  • Compute the divider output, its Thévenin equivalent, an ideal ADC code, nominal voltage resolution, and a bound on ideal quantization error.
  • Acquire and visualize analog and digital measurements from an ESP32 using supplied firmware.
  • Compare predicted behavior with observed data and identify plausible reasons for discrepancies.
  • Evaluate what light and PIR measurements can and cannot establish about a building space.

What you receive

  • one GL5528 photoresistor;
  • one HC-SR501 passive infrared (PIR) motion-sensor module;
  • one 30-pin ESP32 DEVKITV1 development board;
  • one 10 k\(\Omega\) resistor;
  • one breadboard and jumper wires; and
  • the starter firmware in starter/assignment01_logger/assignment01_logger.ino.

You will also need a data-capable micro-USB cable and access to a computer on which you can install Arduino IDE 2. A cable that only supplies power will turn an otherwise straightforward afternoon into an unusually dull debugging exercise, so check the cable early.

What you submit

Submit one archive named andrewID-assignment01.zip containing:

  1. A single PDF with your name and Andrew ID, all requested calculations and written answers, the required tables and plots, and a clear photograph of your completed circuit.
  2. The Arduino sketch you actually used (.ino).
  3. Your unaltered raw serial log (.txt) and cleaned data (.csv). If you correct or exclude any observation during analysis, preserve the original and document the change in the PDF.
  4. Any source files needed to reproduce your plots and calculations: a notebook, script, spreadsheet, or equivalent.

State whom you discussed the assignment with and acknowledge any use of generative AI, following the course syllabus. You may troubleshoot with classmates, the TA, and the lab assistants, but you must assemble your own node, collect your own data, perform your own analysis, and write your own submission.

WarningProtect the hardware

Disconnect the USB cable before changing any wire. Use the labels printed on your board and PIR module; do not infer a pin from where it appears in a photograph. Never connect 5 V to an ESP32 GPIO or ADC pin. Stop and ask for help if the labels on your hardware disagree with the connection table in this assignment.

Task 1: Know what the node measures (10%)

Two numbers arriving in the same CSV file can hide very different measurement chains. Before touching the breadboard, establish what the two channels mean.

1.1 Measurement chains (6%)

Draw one block diagram for each of the following chains:

  1. illumination \(\rightarrow\) value in the adc_code column; and
  2. motion in front of the PIR module \(\rightarrow\) value in the pir_state column.

Include every stage from the physical stimulus through transduction, signal conditioning, digitization (if present), processing, transmission, and storage. Mark the stages that occur inside the HC-SR501 and the ESP32. If a listed stage does not exist in one chain, say so rather than drawing it automatically.

1.2 Two different kinds of output (4%)

For each channel, identify:

  • the transduction principle;
  • the electrical quantity produced by the sensing element itself;
  • whether the sensing element requires excitation under the active/passive convention from Lecture 2;
  • the electrical quantity presented to the ESP32 pin; and
  • whether the signal at that pin is analog or digital, and how the stored value represents it.

Classify the pyroelectric sensing element inside the HC-SR501 separately from the complete powered module. Explain in two or three sentences why pir_state = 1 is not a measurement of either the number of occupants or the amount of motion in a room.

Task 2: Predict the photoresistor channel (20%)

The ESP32 ADC accepts a voltage, but the GL5528 presents a resistance. The 10 k\(\Omega\) resistor supplies the missing interface.

Consider this circuit, where \(R_L\) is the resistance of the GL5528:

3V3 ---- GL5528 (R_L) ----+---- GPIO34 (ADC input)
                           |
                         10 kΩ
                           |
                          GND

Use \(V_s=3.3\) V and \(R_f=10\) k\(\Omega\) unless a question says otherwise.

2.1 Divider model (7%)

  1. Derive \(V_{out}\) as a function of \(V_s\), \(R_L\), and \(R_f\). Do not begin with a memorized divider formula: label the current and show how Ohm’s and Kirchhoff’s laws produce the result.
  2. Compute the divider current and \(V_{out}\) for each hypothetical photoresistor value below. These are circuit-analysis cases, not claims about the resistance you will observe.
\(R_L\) Divider current \(V_{out}\)
1 M\(\Omega\)
100 k\(\Omega\)
20 k\(\Omega\)
10 k\(\Omega\)
5 k\(\Omega\)
  1. State whether \(V_{out}\) should increase or decrease as illumination increases. Connect the direction of change in both steps: illumination \(\rightarrow R_L \rightarrow V_{out}\).

2.2 Thévenin equivalent and loading (5%)

  1. Derive the Thévenin voltage \(V_{Th}\) and resistance \(R_{Th}\) seen looking into the measurement node, with the GL5528 held at a fixed resistance. Add both quantities to your table from Section 2.1.
  2. When \(R_L=10\) k\(\Omega\), suppose the measuring instrument could be modeled as a 100 k\(\Omega\) input resistance to ground. Compute the loaded voltage and the percentage difference from the unloaded voltage. Is the measured value higher or lower, and why?

This 100 k\(\Omega\) load is a deliberately simplified circuit-analysis case. It is not a model of every detail of the ESP32 ADC input.

2.3 Ideal digitization (5%)

For this calculation, use the ideal ADC model from Lecture 4: \(n=12\) bits, \(V_{FS}=3.3\) V, codes from 0 through \(2^n-1\), and

\[ Q=\frac{V_{FS}}{2^n}, \qquad k=\operatorname{round}\!\left(\frac{V_{in}}{Q}\right), \]

with \(k\) clipped to the available code range. Away from saturation, this rounding model bounds the quantization error by \(\pm Q/2\).

  1. Compute the number of available codes, the resolution \(Q\), and the maximum magnitude of the ideal quantization error under this rounding model.
  2. Compute the ideal ADC code for every unloaded \(V_{out}\) in your table.
  3. Compute the quantization-limited full-scale signal-to-noise ratio using the approximation from Lecture 4.
  4. Explain why twelve bits of nominal resolution do not establish twelve bits of measurement accuracy.

2.4 One circuit choice, two consequences (3%)

  1. Sketch the circuit with the GL5528 and fixed resistor exchanged. Derive its output and state how its direction of response to illumination changes.
  2. Explain what region of \(R_L\) the 10 k\(\Omega\) fixed resistor makes most sensitive. Why can no choice of \(R_f\) make \(V_{out}\) linear in \(R_L\) over the entire range?

Task 3: Bring up and document the hardware (15%)

A good commissioning sequence tests one uncertain thing at a time. First establish communication with the ESP32; only then add the sensing circuit.

3.1 Install and test the toolchain (5%)

  1. Install Arduino IDE 2.
  2. Follow Espressif’s Arduino-ESP32 installation instructions to install the stable esp32 by Espressif Systems platform through Boards Manager.
  3. Open assignment01_logger.ino. Replace the STUDENT_ID placeholder with your Andrew ID.
  4. Connect the ESP32 with a data-capable micro-USB cable.
  5. Select Tools \(\rightarrow\) Board \(\rightarrow\) ESP32 Arduino \(\rightarrow\) DOIT ESP32 DEVKIT V1, then select the serial port that appears when you connect the board.
  6. Upload the sketch with both sensors disconnected. Open Serial Monitor at 115200 baud. Save the text showing the firmware banner, CSV header, and at least five data rows.

Most boards enter download mode automatically. If uploading remains stuck at Connecting..., hold BOOT, begin the upload, and release BOOT once data begin transferring. The EN button resets the board; it does not erase your program.

3.2 Assemble the node (5%)

Disconnect USB power and make the following connections. GPIO34 and GPIO27 refer to the labels printed along the ESP32 board.

From To Purpose
ESP32 3V3 one GL5528 leg divider excitation
other GL5528 leg ESP32 GPIO34 divider output to ADC
same GL5528/GPIO34 node one 10 k\(\Omega\) resistor leg lower divider element
other 10 k\(\Omega\) resistor leg ESP32 GND divider return
HC-SR501 VCC ESP32 VIN/5V PIR-module supply
HC-SR501 GND ESP32 GND common reference
HC-SR501 OUT ESP32 GPIO27 digital motion state

Follow the VCC, OUT, and GND labels on your own PIR circuit board. Similar-looking versions of this module are not always photographed in the same orientation. Leave both PIR potentiometers and the trigger-mode jumper at the supplied settings.

Check every connection against the table before reconnecting USB. Then open Serial Monitor and verify that covering/uncovering the GL5528 changes adc_code and that motion in front of the PIR eventually changes pir_state.

Identify whether the GPIO34 voltage measurement is single-ended or differential and name its reference node. Explain why the divider, PIR module, and ESP32 must share a common ground in this circuit.

3.3 Reproducible documentation (5%)

Submit:

  • a clear photograph of the complete powered-off circuit in which the relevant labels and connections can be inspected;
  • your own completed connection table, adding wire colors or breadboard coordinates so another student could reconstruct your circuit; and
  • a brief account of any problem you encountered, the evidence you collected, and how you isolated its cause. If everything worked on the first attempt, describe one plausible failure and the observation that would distinguish it from another failure.

Recording data

The starter sketch prints four comma-separated fields:

condition,time_ms,adc_code,pir_state

Set Serial Monitor’s line ending to New Line. Type a short label such as ambient_1 and press Send; subsequent rows will carry that label. Use only letters, digits, hyphens, and underscores in labels.

Before each experiment, clear or visually mark the Serial Monitor output. At the end, copy the complete output into a plain-text file without editing it. You may use the supplied clean_serial_log.py script to remove banner and status lines:

python clean_serial_log.py raw_serial_log.txt measurements.csv

You may instead clean the log with a tool of your choice, provided that you retain and submit the untouched raw file. Inspect the resulting CSV before analysis: timestamps should parse as nonnegative integers, ADC codes should lie between 0 and 4095, and PIR states should be either 0 or 1.

Task 4: Characterize the light channel (25%)

The GL5528 gives you no calibrated lux value, and the lamp, geometry, and surrounding surfaces are not controlled instruments. That does not make the experiment useless. It changes the question from “How many lux did I measure?” to “Does this channel behave as the measurement model predicts, and where does that model become inadequate?”

4.1 Repeatable conditions (8%)

Define four illumination conditions that you can reproduce. They must include:

  • the photoresistor covered with an opaque object;
  • ambient room light; and
  • a fixed lamp at two documented distances from the sensor.

Avoid direct sunlight and do not use a lamp that noticeably heats the sensor. Describe the light source, distances, approximate angle, room, time of day, and anything you did to keep the geometry fixed.

Record each condition for at least 20 seconds and repeat it three times. Use a distinct condition label for every repeat. Do not touch or move the circuit between repeated measurements unless movement is part of your documented protocol.

4.2 Response and repeatability (9%)

Produce:

  1. a time-series plot of raw ADC code for all twelve trials, with condition changes visible;
  2. a summary plot comparing the distribution of ADC codes across the four conditions; and
  3. a table giving the number of observations, mean, standard deviation, median, minimum, and maximum for each condition.

Explain whether the direction and rough ordering of the response agree with Section 2.1. Compare within-condition variation with between-condition changes. Identify any values near 0 or 4095 and explain why those observations deserve special attention.

Use the timestamps to estimate the median recording interval and sampling frequency, and compare them with the firmware’s intended values. State the corresponding Nyquist frequency. If an unfiltered 3 Hz periodic component entered a channel sampled at the intended rate, at what frequency would it appear in the record? Explain why the samples alone could not distinguish that alias from a genuine component at the apparent frequency. You do not need to create a flickering 3 Hz light source.

4.3 From code back to resistance (5%)

For each condition, use its median ADC code and the ideal model from Section 2.3 to calculate a nominal voltage. Then invert your divider equation to estimate \(R_L\). Show the inverse equation, units, and one complete numerical substitution; tabulate the remaining results.

Call these values nominal estimates. Espressif describes analogRead() as returning a raw, uncalibrated value, and the measurable range depends on the configured attenuation. The starter firmware uses 11 dB attenuation; the Arduino-ESP32 ADC documentation reports an approximate measurable range of 0.15–3.10 V for the classic ESP32 under that setting. Explain how the ideal 0–3.3 V calculation and the physical ADC’s range can disagree, particularly near the rails.

4.4 What you did not measure (3%)

Can these data establish the GL5528’s accuracy in lux? Can they validate a manufacturer resistance-versus-lux curve? Explain what reference instrument and additional controls would be needed. Distinguish repeatability from accuracy in your answer.

Task 5: Characterize the PIR channel (15%)

A PIR module is often sold as an “occupancy sensor,” but it reports a thresholded response to changing infrared radiation. Commissioning it means discovering how that decision behaves before treating it as evidence about people.

Place the PIR where it has an unobstructed view and wait until its output returns to a stable low state. Record how long stabilization took rather than assuming a universal warm-up time. Do not adjust its potentiometers or trigger-mode jumper during the assignment.

5.1 Observation protocol (6%)

Collect and label data for:

  1. at least 30 seconds with no deliberate movement in view;
  2. three isolated walks across the field of view, returning out of view and waiting for pir_state to return to 0 between trials;
  3. three approaches directed approximately toward the sensor from the same starting point; and
  4. one trial in which you enter the field of view and then remain as still as practical for at least 30 seconds; and
  5. one trial in which you continue moving within the field of view for at least 30 seconds.

Keep the approximate starting distance and walking speed consistent across comparable trials. If the output remains high for more than 60 seconds after a trial, record the duration as a lower bound and continue rather than waiting indefinitely.

5.2 Analyze the decision signal (5%)

Submit a plot of pir_state against elapsed time with the trial labels visible. From the recorded transitions, report:

  • how many transverse and approach trials caused a detection;
  • the observed high-state duration for each isolated trigger that returned low; and
  • what happened while you remained stationary.

Compare transverse motion with direct approach, but do not claim a general performance difference from three trials. State whether repeated movement appears to extend the high state under the supplied settings.

5.3 From motion to occupancy claims (4%)

Explain at least three distinct reasons why this binary channel cannot, by itself, determine whether a room is occupied continuously. For each reason, identify whether the limitation arises from the physical transduction, the module’s hidden signal conditioning and decision logic, or your experimental design.

Task 6: Commissioning judgment (15%)

Return to the facilities engineer. In 300–500 words, recommend whether this prototype is suitable for one of the following purposes:

  • switching room lights in response to available light and apparent activity; or
  • documenting room use for a building-energy study.

Support your recommendation with your circuit analysis and observed data. Your response must identify:

  • the as-built DAQ specification: analog and digital channel counts, ADC bit depth and nominal input range, and recording interval;
  • one limitation introduced by each sensor or sensing element;
  • one limitation introduced by the interface circuit or ADC;
  • one physical variable that could confound the interpretation;
  • one claim the prototype can support and one it cannot support; and
  • one concrete improvement needed before deployment, including any DAQ requirement you would change for the selected application.

The goal is not to sell the prototype. It is to decide what evidence it produces well enough to be useful.

Grading summary

Task Weight
1. Know what the node measures 10%
2. Predict the photoresistor channel 20%
3. Bring up and document the hardware 15%
4. Characterize the light channel 25%
5. Characterize the PIR channel 15%
6. Commissioning judgment 15%
Total 100%

Credit depends on the reasoning and evidence supporting an answer, not merely the final number or whether inexpensive hardware behaves perfectly. Report unexpected behavior honestly and investigate it. A carefully diagnosed failure is better engineering than a graph whose inconvenient observations disappeared.

Resources

The HC-SR501 is manufactured in several variants without a single authoritative module datasheet. Treat settings and behaviors not specified in this assignment as properties to observe on your supplied unit, not as universal specifications copied from a vendor page.