Data Acquisition and Device Control
Data acquisition and device control: from sensor to ADC to actuator
The signal chain
A common data-acquisition and closed-loop control path runs:
physical quantity → sensor → signal conditioning → analog-to-digital converter (ADC) → microcontroller → driver → actuator
Not every system uses every stage. An acquisition-only instrument may have no driver or actuator, an open-loop controller may have no sensor or ADC, and a digital sensor performs its own conditioning and conversion, so those do not appear as separate stages.
Treat the chain as a checklist of functions to account for rather than a fixed list of parts.
Each link can limit the whole system. A good design asks at every stage: What voltage range comes out? How fast does it change? How finely must it be resolved? Can this stage safely supply or accept the current involved?
Sensors and conditioning
- Voltage-output sensors give a voltage proportional to the quantity. For example, a TMP36 temperature sensor outputs 10 mV per °C with a 500 mV offset at 0 °C, so T = (V − 0.500 V)/(0.0100 V °C−1).
- Resistive sensors (thermistors, photoresistors, strain gauges) are read with a voltage divider or a bridge.
- Digital sensors (I²C, SPI) do their own conversion and send numbers.
- Switches need a defined idle level from a pull-up or pull-down resistor, and debouncing in software or hardware.
Conditioning adapts the signal to the converter. It scales and offsets the signal so it fills most of the ADC input range, removes frequency content the sampler cannot represent (anti-alias filtering), and protects inputs from overvoltage. Amplifier and filter circuit design are treated separately. Here the point is deciding what the conditioning must achieve.
Resolution and range matching
An N-bit ADC with reference Vref divides its range into 2N codes. Its step size (1 LSB) is Vref/2N. With the common convention, code = ⌊Vin × 2N/Vref⌋, capped at 2N − 1, and a code is converted back with V ≈ code × Vref/2N. (Some code uses 2N − 1 instead; the difference is below one LSB.)
Example. A 12-bit ADC with Vref = 2.50 V has an LSB of 2.50/4096 = 0.610 mV. A TMP36 reading of code 1250 means V = 1250 × 2.50/4096 = 0.763 V, so T = (763 − 500)/10 = 26.3 °C.
Range matching decides how many of those codes your signal actually uses. A sensor that swings 0–1.0 V into a 10-bit, 5.00 V converter spans only 1.0 × 1024/5.00 ≈ 205 of the 1024 codes.
Four-fifths of the resolution is wasted. Gain before the ADC spreads the signal over more codes. Leave headroom, though: an input that exceeds Vref saturates at the top code, and that information is lost.
Keep in mind that more codes improve resolution, not accuracy. Noise, reference error and sensor calibration still set the true uncertainty.
Sampling rate and aliasing
A signal sampled at rate fs can be represented faithfully only up to the Nyquist frequency fs/2. Any component at frequency f above that folds down to an alias at |f − k fs| for the integer k that brings it into 0 to fs/2.
Example. A 90 Hz vibration sampled at 100 Hz shows up as a 10 Hz oscillation.
Once sampled, an alias is indistinguishable from a genuine signal at that frequency, so no digital filter can remove it afterwards.
The cure is an analog low-pass (anti-alias) filter before the ADC, a higher sample rate, or both. In practice designers sample several times faster than the highest frequency of interest, because real filters roll off gradually.
On a microcontroller, set the sample timing with a timer or by comparing elapsed time (for example, micros()) against a schedule. A blocking delay() plus the loop’s own execution time lets the actual rate drift.
Driving devices safely
- Pins are signals, not power supplies. A typical 5 V AVR pin should source or sink no more than about 20 mA in normal use, with an absolute maximum of 40 mA. Motors, solenoids, heaters, relay coils and long LED strips need a driver: a BJT, or a logic-level MOSFET fully on at the available gate voltage, or a driver IC or relay module.
- Separate power, shared reference. Power the load from its own supply. Connect the supply ground to the controller ground so the gate or base drive has a common reference.
- Inductive loads kick back. Switching off a motor, solenoid or relay coil produces a voltage spike. A flyback diode across the load, reverse-biased in normal operation, gives the current a safe path.
- PWM controls average power. Switching a load fully on for a fraction D of each period delivers average power D × V2/R to a resistive load, as long as the load responds slowly compared with the PWM period (heaters, motors, LEDs viewed by eye). Example: a 12 V source across a 9.00 Ω load at D = 0.25 gives 0.25 × 144/9.00 = 4.00 W. Squaring the average voltage instead, (3.0 V)2/9.00 Ω = 1.00 W, is wrong, because power depends on the square of the instantaneous voltage.
- Fail safe. Choose pin states and pull-down resistors so that actuators are off during reset and power-up. Use isolation (optocouplers, rated relay modules) and qualified enclosures for mains voltages.
Common errors to avoid: powering loads from I/O pins; forgetting the common ground; omitting the flyback diode on inductive loads; sampling below twice the highest frequency present, rather than the highest frequency of interest; expecting digital filtering to remove aliases; wasting ADC range; and computing PWM power from the average voltage.
Binary logic and converter internals are covered with their own topics.
Mark Yourself Question
- Grab a piece of paper and try this problem yourself.
- When you're done, check the "I have answered this question" box below.
- View the solution and report whether you got it right or wrong.
A TMP36 sensor (output 10.0 mV °C−1, 500 mV at 0 °C) is read by a 10-bit ADC with Vref = 5.00 V. The reading is code 164. Using V = code × Vref/1024, find the temperature to one decimal place. Also state the temperature step corresponding to one ADC code, to three significant figures.
A sensor signal of interest contains frequencies from 0 to 40 Hz. The wiring also picks up interference at 170 Hz. The signal is sampled at 200 Hz with no analog filter before the ADC. What happens to the interference?