Your ADC tells you a number. The hard part is making that number mean something.[1]
§ 01What the ADC Is Actually Doing
Every microcontroller with analogue capability contains an analogue-to-digital converter — an ADC — that samples a voltage and returns an integer. On a twelve-bit ADC with a 3.3 V reference, the full range of 0 to 4095 maps linearly across 0 to 3.3 V. That much is simple. What's harder is understanding what the voltage at the pin actually represents by the time you read it.
Enlarge ⤢
The ADC can only sample the world at one instant. Between samples, anything can happen. Internally, it works by charging a small capacitor to the input voltage and then measuring that charge — a process called sample-and-hold. The capacitor needs time to charge fully, especially if the source impedance driving the pin is high. Drive an ADC input through a high-value resistor divider and the conversion result will lag behind reality, or simply read low, because the capacitor never fully charged before conversion started. Datasheets quote a maximum source impedance for this reason; stay inside it, or add a buffer.
Reference voltage matters equally. If the ADC compares the input against a supply rail that sags when a relay clicks, every reading sags with it. A dedicated, low-noise voltage reference — or at minimum a well-decoupled supply — keeps the denominator of that division stable. Treat the reference as carefully as the signal itself.
§ 02Why Noise Shows Up and Where It Comes From
A sensor sitting quietly in a stable environment still produces a reading that jitters by a few counts. Some of this is inherent: thermal noise in the sensor's output impedance, quantisation rounding, and the ADC's own front-end noise floor. Accept a few counts of jitter as normal — it costs nothing and averaging smooths it out.
The problem is structured noise, and motors are its most reliable source. A brushed DC motor commutates — its brushes make and break contact dozens of times per revolution, each break a small inductive spike. Those spikes couple into the PCB through shared power rails, through stray capacitance between nearby traces, and through ground — particularly if the motor's ground return shares copper with your analogue circuitry. The result is a reading that changes in step with motor speed or load, even when the sensor hasn't moved.
The fix is separation. Analogue and digital grounds are often joined at a single point near the power entry, not allowed to run together as a shared plane. Motor drive circuitry lives on its own area of the board, its decoupling capacitors placed close to the driver chip, not near the ADC. Filtering helps too: an RC low-pass filter — resistor in series, capacitor to ground — on the analogue input attenuates high-frequency interference before it reaches the ADC pin. Choose the cutoff frequency to pass the signal you care about and reject motor switching frequencies, which typically sit well above any slow sensor output.
Ground bounce is subtler. Digital logic switching — especially a processor fetching from flash or toggling a bus — can shift the local ground reference by tens of millivolts. At ten-bit resolution that's several LSBs; at twelve bits, tens of counts. A separate analogue supply pin and analogue ground pin, routed carefully back to the star point, keeps the measurement reference as quiet as possible.
§ 03Making the Reading Trustworthy
Hardware alone rarely solves everything, so firmware takes on the rest. Oversampling — taking multiple ADC readings and averaging them — reduces random noise by a factor related to the square root of the sample count, and in some architectures can be used to increase effective bit depth beyond the hardware resolution. Eight samples averaged costs eight times the conversion time but cuts random noise to roughly a third.
More useful still is taking the sample at the right moment. If you know a PWM signal switches every millisecond, sample in the quiet middle of the cycle, not at the edge. If a relay fires, wait for the transient to die — tens of milliseconds is usually enough. Synchronising ADC conversions to a known quiet window is sometimes called coherent sampling, and it's often more effective than any amount of filtering.
Calibration closes the last gap. A sensor's output drifts with temperature; so does an internal voltage reference. Two-point calibration — measuring a known low value and a known high value at startup or periodically — establishes a real-world offset and gain to apply to every reading. The ADC gives you a number. The reference, the layout, the filtering and the calibration together make that number mean something.
Notes
- A reading that moves when a motor turns is a grounding result, not a sensor result. ↩