Sensors, Analogue-to-Digital Conversion, Sampling and Data Logging

IB Computer Science · Control (HL)

The world is analogue; the computer is digital. Temperature, pressure, light, sound and position vary continuously. A sensor converts a physical quantity into an electrical signal, usually a voltage that varies continuously with the quantity. A computer cannot store a continuously varying voltage; it needs a number. An analogue-to-digital converter (ADC) measures the voltage at an instant and outputs a binary number. On the way back out, a digital-to-analogue converter turns a number into a voltage that drives an actuator — a motor, heater, valve or speaker. The full chain is: physical quantity → sensor → ADC → processor → DAC → actuator, and every control system, from a thermostat to a self-driving car, is built on it.

Two parameters, two kinds of error. Sampling rate is how many times per second the ADC takes a reading. Sample too slowly and a short peak between two samples is missed entirely; the rule is to sample at least twice as fast as the fastest change you need to capture. Resolution is the number of bits per sample, which sets how many distinct levels can be distinguished: 8 bits give 256 levels, 12 bits give 4 096. A range of 0–100 °C at 8 bits has a step of about 0.4 °C, so every reading is rounded to the nearest step — quantisation error. Raising either parameter improves accuracy but multiplies the data produced and the power consumed, which matters on a battery. The correct choice depends on the phenomenon: a room's temperature once a minute is enough; vibration in a machine bearing needs thousands of samples a second.

Data logging. A data logger combines sensors, a clock and memory, and records readings at set intervals without a person present — for hours, months or years. It is used where humans cannot stay (a river gauge, a weather station on a mountain), where readings must be continuous (a patient monitor), or where the phenomenon is slow (glacier movement). Advantages over manual recording: no gaps, no transcription errors, readings at night and in hazardous places, timestamps that are exact, and data that is already digital for analysis. Costs: equipment, calibration, and the risk that a faulty sensor produces plausible-looking wrong data for months before anyone notices — which is why loggers are checked against a manual reading periodically.

Sensor limitations to mention. Every sensor has a range outside which it saturates, an accuracy (how close to the true value), a precision (how repeatable), a response time (a thermometer takes seconds to follow a change), and drift over time that requires recalibration. Noise from electrical interference adds random error, which is reduced by averaging several samples — at the cost of slower response. An answer that names the sensor and its limitation, and then says what the system does about it, is what the mark scheme rewards.

SENSORS FOR A CONTINUOUS WAVE — THE COMPUTER RECEIVES ONLY DISCRETE NUMBERS time → (each tick = one sample) temperature 11 10 01 00 10 10 01 00 10 11 blue line: the real, continuous signal · red dots: the values the computer keeps TWO PARAMETERS, TWO ERRORS Sampling rate how many measurements per second low: misses a short peak between two samples rule: at least 2 times the frequency of the fastest change to capture Resolution (number of bits) how many levels can be distinguished 2 bits = 4 levels · 8 bits = 256 · 12 bits = 4,096 low: rounding — quantization error 0–100 °C with 8 bits: step ~0.4 °C raising both → more data, drains the battery THE CHAIN FROM THE REAL WORLD TO THE PROGRAM physical quantity → sensor (voltage) → ADC converter (digital) → processor → DAC converter → actuator data logger: sensor + clock + memory, records periodically, unattended — for long-term monitoring choose rate and resolution according to the phenomenon to capture: room temperature once a minute is enough, machine vibration needs thousands of times a second
The figure on the left draws what happens when a continuous signal — here temperature over time, the blue line — is fed into a computer. The computer cannot keep the curve; it only measures at evenly spaced moments, the dashed lines, and rounds each measured value to the nearest of a finite number of levels, here the four levels of two bits; the red dots are everything the program receives. The box on the right separates two parameters and the two corresponding kinds of error. The sampling rate is the number of measurements per second; too low and it misses a short peak occurring between two samples, and the rule is to sample at least twice the frequency of the fastest change to be captured. The resolution is the number of bits, which determines the number of distinguishable levels: 2 bits give 4 levels, 8 bits give 256, 12 bits give 4,096; too low and every value is coarsely rounded, called quantization error, and for example a range of 0 to 100 degrees with 8 bits gives a step of about 0.4 degrees. Raising both gives more accurate data but more of it and drains the battery more. The bottom box is the full chain from the real world to the program and back: physical quantity, sensor giving a voltage, analog-to-digital converter, processor, digital-to-analog converter, actuator; and a data logger is a sensor plus a clock plus memory recording periodically without a person. The last line is the principle for choosing: according to the phenomenon to be captured, room temperature once a minute is enough while machine vibration needs thousands of times a second.

Worked example: Example 1 — choosing sampling rate and resolution for three applications

Choose a sampling rate and resolution, with reasons, for: (a) a cold-storage temperature logger running on a battery for one year, range −30 to +10 °C, needing to detect a deviation of 0.5 °C; (b) an electrocardiogram machine; (c) a vibration sensor to detect early bearing failure in a motor rotating at 3,000 revolutions per minute.

Solution

(a) Cold storage — slow and coarse. The temperature of a cold store changes over many minutes, not milliseconds, so sampling every 1–5 minutes is enough to catch every meaningful incident, and at each measurement the device wakes for a few milliseconds and then sleeps — the decisive factor for a battery to last a year. Resolution: a 40 °C range needing to distinguish 0.5 °C means 80 levels; 8 bits gives 256 levels, a step of about 0.16 °C, more than enough. Using 12 bits is not wrong but wastes memory and power.

(b) Electrocardiogram — medium on both. The heart signal has sharp spikes lasting a few tens of milliseconds; to draw their shape correctly requires a few hundred samples per second, typically 250–500. Resolution of 12 bits or more because the signal is very small (millivolts) and doctors read amplitude details; 8 bits rounds away diagnostic detail. It is mains-powered so the battery is not a constraint.

(c) Vibration — very fast. 3,000 revolutions per minute is 50 revolutions per second, and a failing bearing produces oscillations at high multiples of the rotation frequency, typically a few kilohertz. By the doubling rule, it needs tens of thousands of samples per second; sampling slower would completely miss the sign of failure or create false frequencies. Resolution of 16 bits to catch small oscillations superimposed on large vibration. The data is enormous so the device analyzes on the spot and sends only the result, instead of logging raw data.

General principle. Start from the phenomenon: the fastest change to be captured decides the rate, the smallest difference to be distinguished decides the number of bits, and the battery and memory set a ceiling on both. An answer that says only the higher the better loses marks because it ignores the cost.

Worked example: Example 2 — why a data logger gave wrong results for three months

An air-quality monitoring station records dust concentration every 10 minutes. After three months it is discovered that all the data from one sensor is about 40% lower than reality yet still fluctuates quite naturally between day and night. Explain how this happens, why no one noticed, and design to prevent it.

Solution

The mechanism. The optical dust sensor gradually gets dirty on its measuring window, so the amount of scattered light measured decreases, and every value is multiplied by a factor less than 1. Because the factor applies to every sample, the day-night fluctuation keeps its shape — only the amplitude gets smaller. This is systematic drift, different from random noise: noise makes the data look bad, drift makes the data look good but wrong.

Why no one noticed. The logger does its job exactly: records evenly, no gaps, accurate timestamps. There is no software error to report, and the data remains plausible — high in the daytime, low at night, rising in traffic jams. Someone looking at the chart has nothing to be suspicious about. This is precisely the characteristic risk of automatic data logging: it replaces humans even in the step of doubting.

Design to avoid it. One, periodic cross-checking against a reference instrument or a manual measurement — weekly — and recording the calibration factor in a log. Two, a redundant sensor: two sensors of the same kind at one point, and an alert when they deviate by more than a threshold — drift seldom occurs identically on both. Three, automatic plausibility checks: compare with neighboring stations, and alert when the weekly average gradually falls while the neighboring station does not. Four, a physical maintenance schedule to clean the measuring window, because the cause is mechanical, not software. A good answer states clearly: a data logger does not remove the need for humans, it changes the human's job from recording to checking.

Common mistake

Trap 1 — saying the more samples and the more bits the better. You must state the cost: data, battery, memory; choose according to the phenomenon.
Trap 2 — confusing resolution with accuracy. 12 bits gives a small step, but a sensor that is off by 2 degrees is still off by 2 degrees.
Trap 3 — treating a data logger as needing no people. Drift gives data that looks good but is wrong; periodic cross-checking is required.

Key takeaway

Lesson 3 wrap-up. Four things to take into the exam room. One, the chain sensor → ADC → processor → DAC → actuator. Two, the sampling rate captures fast change, the number of bits distinguishes small differences, and both have a cost. Three, a data logger gives continuous records with no gaps, in places where people cannot be. Four, sensor limits: range, accuracy, repeatability, response, drift — and what the system does about them.

← Centralised and Distributed Control, Automation and Its Consequences · All IB Computer Science lessons · Practice IB Computer Science questions (free, instant scoring) · Autonomous Agents, Multi-Agent Systems and the Ethics of Autonomy →