Skip to main content

How This System Works

Tracing a number's journey from the real world to your screen

Grades 9–11 45 min experiment live IESH data

Students trace the complete pathway of a single temperature reading — from the physical world, through the sensor, ADC, microcomputer, database and web server, to the browser — understanding how each step works and what can go wrong at each stage.

  • Describe the function of each hardware component in the sensor hub (sensor, ADC, microcomputer, database, web server).
  • Explain the role of analogue-to-digital conversion in measuring physical quantities.
  • Identify at least two places in the data pipeline where errors or noise could be introduced.
  • Evaluate the concept of "the stack" as a framework for understanding complex systems.

A sensor hub like this one consists of a layered "stack" of hardware and software, each layer serving a specific function. The physical sensors (BMP280, DHT22, DS18B20, MCP3208) measure physical phenomena and produce either analogue voltages or digital signals. Analogue sensors are connected to the MCP3208 ADC (analogue-to-digital converter), which samples the voltage at high speed and converts it to a 12-bit number (0–4095). Digital sensors communicate directly with the Raspberry Pi over I2C, SPI or 1-Wire protocols.

The Raspberry Pi is a single-board computer running Linux. It runs Python code that reads from each sensor, logs readings to a SQLite database on its internal storage, and serves a Flask web application accessible over the local network. The web application reads data from the database and serves it as both an HTML dashboard and a JSON API at /api/data. When you open the dashboard on your device, your browser fetches the HTML once, then polls the /api/data endpoint every 15 seconds for updated readings.

Each step in this pipeline can introduce errors. The sensor may have a calibration offset (the BMP280 temperature reading may be 1–2°C higher than actual due to self-heating). The ADC has quantisation noise — a 12-bit converter can represent 4,096 distinct levels; the real-world value falls somewhere between two of those levels. The database might have a write failure during a power cut. The web server might deliver a cached value rather than the latest reading. Understanding these failure modes is what separates a competent engineer from someone who just uses the hardware.

  1. Read the current air temperature: ___ °C. This number has travelled a long path to reach your screen. You will trace it.
  2. Stage 1 — Sensor: The DHT22 sensor uses a capacitive element to measure humidity and a thermistor to measure temperature. It produces a digital signal, not an analogue voltage. Why does this mean it does NOT need the MCP3208 ADC?
  3. Stage 2 — Protocol: DHT22 sends data over a single GPIO pin using a proprietary timing protocol. The Raspberry Pi reads 40 bits: 16 bits temperature + 16 bits humidity + 8 bits checksum. What is a checksum and why is it useful?
  4. Stage 3 — Database: The reading is stored in a SQLite table called "telemetry" with columns for timestamp, temperature, humidity, etc. Write the SQL query that would retrieve the last 10 temperature readings.
  5. Stage 4 — API: The Flask web server has a route /api/latest that returns JSON. Write what you think the JSON response for the current temperature reading looks like.
  6. Stage 5 — Browser: JavaScript on the dashboard page fetches /api/latest every 15 seconds and updates the display. Identify one thing that could go wrong at this step and how the dashboard handles it.
  1. The dashboard shows air temperature updating every 15 seconds, but the DHT22 sensor is read every 1 second. Why might there be a gap between reality and display?
  2. If the Raspberry Pi's clock is wrong (e.g. it has been disconnected from the internet for a month), how would this affect the timestamps in the database?
  3. If you wanted to scale this from one station to 100 stations across Nepal, what parts of the system would need to change? What parts could stay the same?

1. Draw a simple block diagram showing the data flow from sensor to browser. Label each stage with its function. [6 marks]

Answer guide (for teachers)

Should include: Physical sensor → (ADC for analogue, direct for digital) → Raspberry Pi Python code → SQLite database → Flask web server → JSON API → Browser JavaScript → Display. Award marks for correct sequence and appropriate labels.

2. What is analogue-to-digital conversion? Why do the MQ gas sensors need an ADC but the DHT22 temperature sensor does not? [4 marks]

Answer guide (for teachers)

ADC converts a continuous analogue voltage to a discrete digital number. MQ sensors output an analogue voltage proportional to gas concentration — this must be digitised. DHT22 outputs a digital bit stream that the computer can read directly without conversion.

3. The MCP3208 is a 12-bit ADC. How many distinct values can it represent? If it is connected to a 3.3V reference, what is the smallest voltage change it can detect? [4 marks]

Answer guide (for teachers)

2¹² = 4,096 distinct values (0–4095). Resolution = 3.3V ÷ 4,096 ≈ 0.000806V ≈ 0.8 mV. Award full marks for correct calculation and correct unit.

ADC (Analogue-to-Digital Converter)
A device that samples an analogue voltage at regular intervals and converts each sample to a digital number.
Protocol
An agreed set of rules for how data is formatted and transmitted between devices; I2C, SPI and 1-Wire are all communication protocols.
API (Application Programming Interface)
A defined way for software systems to communicate; the /api/data endpoint is an HTTP API that returns sensor data as JSON.
Checksum
A value calculated from a data transmission and sent alongside it; the receiver recalculates and compares to verify the data arrived intact.

SSH into the Raspberry Pi and examine the Python code in core_dash.py. Identify: (1) where the DHT22 sensor is read, (2) where data is written to the database, (3) what happens if a sensor read fails. Write a one-page annotated code walkthrough explaining what each section does.