ADC & Sensor Interfacing Notes
Analog Signals
- Continuous-time signals that represent physical parameters.
- Values vary smoothly and infinitely over time.
- Examples: temperature, light, sound.
- Core characteristics: continuity, amplitude range, time-varying, smooth curves.
Analog vs Digital Signals
- Analog: Continuous, infinite values, varying voltage, prone to noise.
- Digital: Discrete, finite values (0 and 1), noise-resistant, compatible with digital logic.
- Analog signals require ADC for processing in microcontrollers.
ADC (Analog-to-Digital Converter)
- Translates continuous analog voltage into discrete digital value.
- Physical quantity (e.g., temperature, light) → Binary number
- Arduino Uno uses
analogRead() for this conversion.
ADC Block Diagram
- Sampler: Takes samples from the continuous analog signal according to its sample frequency, converting the continuous-time-continuous amplitude signal into a continuous amplitude-discrete time signal.
- Holding Circuit: Holds the samples generated by the sampler circuit.
- Quantizer: Converts the continuous amplitude-discrete time signal into a discrete time-discrete amplitude signal.
- Encoder: Generates the digital signal in binary form.
ADC in Arduino Uno (ATmega328P)
- Resolution: 10-bit (0 to 1023)
- Voltage Range: 0V to Vref (usually 5V)
- Number of Channels: 6 analog input pins (A0–A5)
- Default Reference: 5V (from USB or external supply)
- Internal Reference: 1.1V (optional via
analogReference(INTERNAL))
Internal Reference Voltage (Vref)
- Fixed, stable voltage inside the microcontroller.
- Used as the upper limit for ADC conversions.
- Using 1.1V internal reference provides more stable and precise ADC results for low-voltage sensors.
Available Reference Options on Arduino Uno
- DEFAULT: ~5.0V (Vcc)
- INTERNAL: 1.1V (built-in)
- EXTERNAL: Custom voltage applied to AREF pin (< 5V)
Basic Conversion Process
- Sensor produces analog voltage.
- ADC samples this voltage.
- Converts it to a digital number based on reference voltage and resolution.
With 10-bit ADC & 5V reference.
Example Code
int rawValue = analogRead(A0);
float voltage = rawValue * (5.0 / 1023.0);
- Using internal reference:
analogReference(INTERNAL); // Set ADC reference to 1.1V
float voltage = sensorValue * (1.1 / 1023.0); // Use 1.1V as reference
Resolution in ADC
- Smallest measurable change in analog input that can be detected by the ADC.
- Formula: Resolution=2nVref
- Vref = Reference Voltage
- n = bit depth of the ADC (10 for Arduino Uno)
Resolution Calculation for Arduino Uno (10-bit ADC)
- ADC range: 0 to 1023 (210−1)
- Reference Voltage (Vref): 5V (default)
- Formula: Resolution=10245V≈0.0049V
Sampling Rate in ADC
- Number of times per second the analog signal is sampled.
- Measured in samples per second (SPS) or Hertz (Hz).
- Arduino Uno: Default sampling rate for
analogRead() is approximately 9.6 kHz.
Calculation of Arduino Sampling Rate
- ADC Clock: Derived from the system clock (16 MHz) and divided by a prescaler.
- Formula: Sampling Rate = ADC Clock / Conversion Time.
- Arduino Uno (16 MHz clock and default prescaler of 128): ≈ 9.6 kHz.
Why is Sampling Rate Important?
- Higher Sampling Rate = More Accurate Representation.
- Trade-Offs: Higher sampling rate → more power consumption, processing load.
- Nyquist Theorem: Ensure the signal you're measuring is below half of the sampling rate to avoid aliasing.
Optimizing Sampling Rate in Arduino
- Reduce the delay between readings.
- Use
analogRead() with lower resolution. - Consider using direct register access.
Improving Accuracy in ADC Readings
- Raw analog readings can fluctuate due to electrical noise, sensor instability, and rapid environmental changes.
- Techniques: Averaging (Smoothing), Median Filtering, Software Debouncing, Shielding/Grounding, Low-pass Filtering.
Common Accuracy-Improving Techniques
- Averaging (Smoothing): Reduces noise from erratic ADC readings.
- Median Filtering: Remove outliers by choosing the middle value.
Rolling Average (Moving Average Filter)
- Keeps a fixed number of past readings, adds the new one, removes the oldest, and averages the rest.
Exponential Smoothing (Low-Pass Filter)
- Blends the previous smoothed value and the new sensor reading using a weighting factor (alpha).
- Formula: smoothedValue=alpha∗raw+(1−alpha)∗previousSmoothedValue
Rolling vs. Exponential Smoothing
- Rolling Average: Higher memory usage, slower reaction to changes, best for stable, noise-heavy data, moderate complexity.
- Exponential Smoothing: Very low memory usage, faster reaction to changes, best for real-time feedback with smoothness, simple complexity.