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.
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.