22  Sensor Circuits and Signals

22.1 Learning Objectives

By the end of this chapter series, you will be able to:

  • Interpret Sensor Output Signals: Distinguish between analog voltage, digital pulse, and serial data outputs
  • Design Signal Conditioning Circuits: Apply amplification, filtering, and level shifting for sensor signals
  • Calculate ADC Resolution: Compute voltage resolution and select appropriate ADC bit depth for applications
  • Implement Noise Reduction: Apply hardware and software techniques to improve signal quality
  • Build Sensor Interface Circuits: Create voltage dividers, pull-up/down resistors, and protection circuits
  • Diagnose Signal Problems: Troubleshoot sensor circuit issues using oscilloscopes and multimeters
In 60 Seconds

Every sensor signal must pass through three conditioning stages: amplification (boost millivolt outputs to span the ADC range), filtering (remove noise above signal bandwidth with an RC low-pass filter at fc = 1/(2piRC)), and analog-to-digital conversion (sample at 2x the signal frequency per Nyquist). Master voltage dividers and RC filters — they solve 80% of sensor interfacing problems.

Key Concepts
  • Signal Conditioning: The process of amplifying, filtering, and level-shifting a raw sensor output to make it suitable for ADC input on a microcontroller
  • Voltage Divider: Two resistors in series where the output is tapped from the midpoint; converts resistance changes in thermistors and LDRs into proportional voltage changes the ADC can measure
  • RC Low-Pass Filter: A resistor-capacitor network with cutoff frequency fc = 1/(2piRC) that passes slow sensor signals while attenuating high-frequency electrical noise
  • Op-Amp Gain: Non-inverting amplifier gain = 1 + Rf/Rg; amplifies weak millivolt sensor signals to span the full ADC input range, maximizing measurement precision
  • ADC Resolution: Smallest detectable voltage change = Vref / 2^bits; a 12-bit ADC with 3.3 V reference resolves approximately 0.8 mV per step
  • Nyquist Criterion: Sampling rate must be at least 2x the highest signal frequency to avoid aliasing — false frequencies appearing in the digitized data
  • Level Shifting: Adapting a sensor’s output voltage to match the MCU’s input voltage range, e.g., dividing 5 V sensor output down to 3.3 V for an ESP32 ADC pin
  • Signal-to-Noise Ratio: Ratio of desired signal amplitude to background noise; higher SNR means more reliable measurements and less dependence on software filtering

22.2 MVU: Minimum Viable Understanding

Core concept: Sensor circuits translate physical measurements into electrical signals that microcontrollers can process–requiring amplification, filtering, and analog-to-digital conversion.

Why it matters: Raw sensor outputs are rarely suitable for direct ADC connection. Signals may be millivolts (too weak), noisy (motor interference), or wrong voltage level (5V sensor on 3.3V MCU). Proper signal conditioning is the difference between accurate measurements and garbage data.

Key takeaway: Every sensor circuit needs three considerations: (1) voltage/current levels match MCU input range, (2) noise filtering appropriate to signal bandwidth, (3) adequate ADC resolution for measurement precision. Master voltage dividers and RC filters–they solve 80% of sensor interfacing problems.

Sensors produce tiny electrical signals, but microcontrollers need those signals in a specific format and voltage range. Sensor circuits are the “adapters” in between – they amplify weak signals, filter out electrical noise, and convert smooth analog voltages into the digital numbers a computer can understand. Think of it like translating a whisper into a clear message that a computer can read.

How It Works: Sensor Signal Conditioning Pipeline

The sensor signal path follows three essential stages:

Step 1: Signal Amplification

  • Weak sensor output (millivolts) enters an op-amp or instrumentation amplifier
  • Gain calculation: Gain = V_ADC_range / V_sensor_range
  • Example: 50mV sensor signal amplified 66x to fill 3.3V ADC range
  • Result: Maximum use of ADC resolution for precision

Why Amplifier Gain Matching Matters for ADC Resolution

A 12-bit ADC with 3.3V reference has resolution: \[\text{LSB} = \frac{3.3\text{ V}}{2^{12}} = \frac{3.3}{4096} = 0.806\text{ mV per step}\]

Unamplified 50 mV sensor signal uses only: \(\frac{50}{0.806} = 62\) ADC steps out of 4096 (1.5% utilization).

With gain = \(\frac{3.3}{0.05} = 66\times\): Signal now spans 0-3.3V, using all 4096 steps.

Effective resolution improvement: \(\frac{4096}{62} = 66\times\) finer measurements. This demonstrates why matching sensor output to ADC input range through amplification is critical for maximizing measurement precision—unused ADC range is wasted resolution.

Step 2: Noise Filtering

  • RC low-pass filter removes high-frequency noise above signal bandwidth
  • Cutoff frequency formula: fc = 1 / (2 × π × R × C)
  • Example: 10kΩ + 100nF = 159 Hz cutoff blocks motor noise
  • Result: Clean signal with preserved slow temperature/pressure changes

Step 3: Analog-to-Digital Conversion

  • MCU’s ADC samples filtered voltage at regular intervals
  • Sampling rate must be at least 2× the highest signal frequency (Nyquist criterion) – sampling a 50 Hz vibration signal requires ≥100 Hz sampling rate, otherwise aliasing distorts the measurement
  • Resolution determines smallest detectable change: 3.3V / 4096 = 0.8mV per step (12-bit)
  • Digital value stored in register for software processing
  • Result: Binary number representing physical measurement

This three-stage pipeline transforms unreliable millivolt signals into accurate digital data the microcontroller can process for IoT applications.

22.3 Chapter Overview

This chapter has been organized into focused sections for easier learning. Work through them in order, or jump to the topic most relevant to your current needs:

22.3.1 1. Sensor Circuit Fundamentals

Essential building blocks for sensor interfaces

Learn the fundamental circuit patterns that form the backbone of sensor interfaces: voltage dividers, RC filters, transistor switches, and LED indicators.

  • Voltage dividers for resistive sensors
  • RC low-pass filters for noise reduction
  • Transistor switches for load control
  • LED current limiting resistors
  • Basic debugging with multimeters

22.3.2 2. Signal Conditioning

Transforming raw sensor signals for ADC input

Master the signal conditioning chain: amplification, filtering, and level shifting. Includes worked examples for thermistor and strain gauge interfaces.

  • Signal conditioning pipeline overview
  • Amplifier gain calculations
  • Wheatstone bridge circuits
  • Instrumentation amplifiers
  • Worked example: HVAC thermistor
  • Worked example: Strain gauge load cell

22.3.3 Interactive Simulators

This chapter series includes hands-on Wokwi simulators and interactive tools for practical learning. Find them in the sub-chapter pages:

  • DHT22 Temperature & Humidity Sensor – Digital signal timing, humidity and temperature reading, error handling (Sensor Circuit Fundamentals)
  • LED PWM Control with Light Sensor Feedback – Photoresistor voltage divider, PWM brightness control, feedback loops (Sensor Circuit Fundamentals)
  • Voltage Divider Calculator and RC Filter Designer – Interactive design tools for sensor circuits (Signal Conditioning)

You can also try the Voltage Divider Calculator, RC Filter Designer, and ADC Resolution Explorer on this page below.

22.4 Quick Reference: Sensor Signal Types

Signal Type Example Sensors Interface Method
Analog Voltage Thermistor, LDR, Potentiometer Voltage divider + ADC
Analog Current 4-20mA industrial sensors Current-to-voltage conversion
Digital Pulse DHT22, Ultrasonic, Encoder Digital GPIO + timing
I2C/SPI Serial BME280, MPU6050, ADS1115 Protocol library
PWM/Frequency Hall effect, Flow meters Period/frequency measurement

22.5 Key Formulas

Formula Purpose
Vout = Vin * (R2 / (R1 + R2)) Voltage divider output
fc = 1 / (2 * pi * R * C) RC filter cutoff frequency
R = (Vsupply - Vled) / Iled LED current limiting resistor
ADC_resolution = Vref / 2^bits ADC voltage per step
Gain = 1 + (Rf / Rg) Non-inverting op-amp gain
fs >= 2 * fmax Nyquist sampling rate (minimum)

22.6 Interactive Calculators

22.6.1 Voltage Divider Calculator

Use this calculator to design voltage dividers for resistive sensors. Adjust the input voltage and resistor values to see the output voltage and what percentage of the ADC range is used.

22.6.2 RC Filter Designer

Calculate the cutoff frequency for a low-pass RC filter. Signals below the cutoff pass through; signals above are attenuated. Use this to size components for noise filtering on sensor signals.

22.6.3 ADC Resolution Explorer

Compare how different ADC bit depths affect your ability to detect small sensor changes. Enter the smallest voltage change you need to measure.

Key Takeaway

Every sensor circuit must address three challenges: signal level matching (voltage dividers, amplification), noise removal (RC filters, shielding), and format conversion (ADC). Master voltage dividers and RC filters first – they solve 80% of sensor interfacing problems. For the remaining 20%, dedicated signal conditioning ICs like instrumentation amplifiers and load cell ADCs (HX711) provide optimized, application-specific solutions.

Sammy the Sensor had a problem. “I’m trying to tell Max what the temperature is, but my voice is SO quiet that he can’t hear me!”

Max the Microcontroller cupped his hand to his ear. “What did you say, Sammy? All I hear is 0.02 volts… that’s like a whisper!”

Lila the LED had an idea. “You need an AMPLIFIER! It’s like a megaphone for electrical signals. It takes your tiny 0.02 volt whisper and boosts it to a nice loud 2 volts that Max can easily hear!”

“But wait,” said Bella the Battery, “even with the megaphone, there’s so much background noise from that motor over there! It’s like trying to listen to a whisper at a rock concert!”

“That’s what FILTERS are for!” Sammy explained. “An RC filter is like noise-canceling headphones. It blocks the high-pitched buzzing from motors and power lines, letting through only the slow, steady temperature changes I’m measuring.”

Max drew the whole process on his whiteboard: “Step 1: Sammy whispers (tiny voltage) Step 2: Amplifier makes it louder (bigger voltage) Step 3: Filter removes background noise (clean signal) Step 4: I convert it to a number I understand (ADC: analog to digital)!”

“So sensor circuits are basically translators?” Lila asked.

“Exactly! We translate from Sensor Language (analog voltages) into Computer Language (digital numbers). And just like any translation, you need to make sure the message is clear, loud enough, and free of background chatter!”

When selecting sensors for a new IoT design, one fundamental choice is between analog sensors with custom signal conditioning versus integrated digital sensors with built-in ADC and communication protocols.

Factor Analog Sensor + Signal Conditioning Digital Sensor (I2C/SPI)
Initial Cost Lower sensor ($0.50-$5), higher conditioning ($1-$10) Higher sensor ($3-$30), minimal external parts
Development Time 2-4 weeks (circuit design, PCB, calibration, debugging) 3-7 days (library exists, minimal hardware)
BOM Line Items 8-15 components (sensor, op-amp, resistors, caps, diodes) 2-4 components (sensor, decoupling caps)
PCB Area 500-2000 mm² (conditioning circuit, wide traces for analog) 50-200 mm² (single IC, compact I2C routing)
Power Consumption Sensor: 0.1-5mA, Conditioning: 1-10mA Total: 0.1-5mA (integrated, optimized)
Noise Immunity Poor - susceptible to EMI on long traces, ground loops Excellent - digital signals immune to minor noise
Measurement Accuracy Customizable - optimize gain/filtering for your range Fixed - use manufacturer’s calibration (often excellent)
Flexibility High - adjust gain, filters, sampling rate in hardware Limited - constrained by IC configuration options
Calibration Effort High - two-point or multi-point calibration required Low - factory calibrated, may need offset correction
Troubleshooting Difficult - oscilloscope needed, analog debug skills Easier - logic analyzer, I2C scanner, clear error codes
Failure Modes Drift, offset, gain errors (gradual degradation) Digital: works or doesn’t (clear failure)
Best Applications Custom ranges, unusual sensors, high-volume cost optimization Quick prototypes, standard measurements, small-batch production

Decision Tree:

START: Need to measure [temperature/pressure/light/etc]
  |
  ├─ Is a digital sensor available with I2C/SPI interface?
  │   ├─ YES → Does it meet your accuracy requirements?
  │   │   ├─ YES → Does it fit your power budget?
  │   │   │   ├─ YES → **USE DIGITAL SENSOR** ✓
  │   │   │   └─ NO → Is power critical or just nice-to-have?
  │   │   │       ├─ Critical → Consider analog with duty cycling
  │   │   │       └─ Nice → **USE DIGITAL SENSOR** (simplicity wins)
  │   │   └─ NO → Do you need custom measurement range?
  │   │       ├─ YES → **ANALOG + SIGNAL CONDITIONING** ✓
  │   │       └─ NO → Can you compromise on accuracy?
  │   │           ├─ YES → **USE DIGITAL SENSOR** (good enough)
  │   │           └─ NO → **ANALOG + SIGNAL CONDITIONING** ✓
  │   └─ NO → Is this a standard sensor type (thermistor, photodiode, etc)?
  │       ├─ YES → **ANALOG + SIGNAL CONDITIONING** ✓ (only option)
  │       └─ NO → Research specialty digital sensors first
  │
  └─ Is this a high-volume product (>10,000 units)?
      ├─ YES → Cost optimization matters
      │   └─ Analog sensor ($2) + conditioning ($3) vs digital ($8)?
      │       ├─ Analog cheaper → Is BOM cost reduction worth development time?
      │       │   ├─ YES → **ANALOG + SIGNAL CONDITIONING** ✓
      │       │   └─ NO → **USE DIGITAL SENSOR** (faster to market)
      │       └─ Digital cheaper → **USE DIGITAL SENSOR** ✓
      └─ NO → **USE DIGITAL SENSOR** (default for most projects)

Real-World Examples:

Measurement Recommended Choice Reasoning
Temperature (-40 to +85°C, ±1°C) Digital (DS18B20, DHT22) Standard range, digital sensors are accurate and cheap ($2-5)
Temperature (0-500°C, ±0.1°C) Analog (K-type thermocouple + MAX31855) Extreme range, need specialized amplifier regardless
Light (0-100k lux, ±10%) Digital (BH1750, VEML7700) Excellent digital sensors available, auto-ranging
Soil Moisture (capacitive) Analog (capacitive probe + RC filter + ADC) No good digital options, simple analog circuit works
Pressure (0-100 PSI, ±0.5%) Digital (BMP390, MS5611) High-accuracy digital sensors standard in industry
Distance (2cm-4m, ±1cm) Digital (HC-SR04 ultrasonic, VL53L1X laser) Timing-based, inherently digital measurement
Current (0-50A, ±1%) Analog (shunt resistor + INA219, or hall effect sensor) High current needs analog sensing; INA219 is a shunt-based I2C digital output
pH (0-14, ±0.01 pH) Analog (glass electrode + pH amplifier) No reliable digital pH sensors, analog with careful conditioning

Key Insight: For most IoT projects, default to digital sensors unless you have a specific reason not to (unusual measurement range, extreme cost sensitivity at high volume, or no digital sensor exists for that parameter). The development time savings and reliability improvements usually outweigh any cost or power consumption benefits of analog solutions.

22.7 Concept Relationships

This Concept Relates To Relationship Type
Voltage Divider Resistive Sensors Circuit pattern converts resistance changes to voltage
RC Filter Noise Reduction Passive circuit removes high-frequency interference
ADC Resolution Measurement Precision Bit depth determines smallest detectable voltage change
Amplification Signal Scaling Gain calculation maps sensor range to ADC range
Digital vs Analog Interface Selection Output type determines required circuitry
Sampling Rate Nyquist Criterion ADC must sample at ≥2× signal frequency to avoid aliasing

22.8 Summary

  • Signal Conditioning Pipeline: Raw sensor outputs require amplification, filtering, and analog-to-digital conversion before a microcontroller can process them – skipping any stage leads to inaccurate or unusable data
  • Voltage Dividers and RC Filters: These two simple circuits solve roughly 80% of sensor interfacing problems by converting resistance changes to voltage and removing high-frequency noise
  • ADC Resolution Selection: Higher bit depth provides finer voltage resolution (e.g., 12-bit gives 0.8 mV steps at 3.3V reference), and the chosen resolution must match the precision requirements of the application
  • Signal Type Dictates Interface Method: Analog sensors need voltage dividers and ADC channels, digital pulse sensors need GPIO timing, and serial sensors (I2C/SPI) use protocol libraries – choosing the right method depends on the sensor output
  • Three Design Considerations: Every sensor circuit must ensure voltage and current levels match the MCU input range, noise filtering matches the signal bandwidth, and the ADC provides sufficient resolution and sampling rate (≥2× signal frequency per Nyquist criterion) for the measurement

22.9 Knowledge Check

Match each circuit component to its primary function in a sensor interface:

Order the steps in the sensor signal conditioning pipeline from raw measurement to processed data:

Common Pitfalls

A 5 V sensor output connected directly to a 3.3 V MCU ADC pin exceeds the absolute maximum rating and can permanently damage the input. Always check the sensor supply voltage and add a resistor divider to bring 5 V down to 3.3 V before the ADC pin.

Placing the RC cutoff below the signal frequency attenuates the measurement you are trying to capture. Set the cutoff at least 5x above the signal’s highest frequency while keeping it well below the dominant noise frequency.

If the sensor output only spans 10% of the ADC reference range, 90% of ADC resolution is unused. Use amplification to map the sensor’s full output range to the full ADC input range, gaining up to 10x finer measurement resolution.

An open-drain or disconnected sensor output leaves the ADC input floating, producing random meaningless readings. Always provide a defined electrical path through a pull-up, pull-down, or sensor output; never leave an analog input electrically unconnected.

22.10 What’s Next

Start with Sensor Circuit Fundamentals for the essential building blocks. If you already know voltage dividers and filters, skip to Signal Conditioning for advanced amplification and bridge circuits.

Chapter Focus Area Why Read It
Sensor Circuit Fundamentals Voltage dividers, RC filters, transistor switches Essential building blocks for all sensor interfaces
Signal Conditioning Amplification, Wheatstone bridges, instrumentation amps Advanced techniques for weak or noisy sensor signals
Sensor Interfacing and Processing MCU integration, ADC configuration, interrupt handling Connect conditioned signals to microcontroller firmware
Analog and Digital Electronics ADC/DAC architectures, quantization, sampling theory Deeper understanding of conversion hardware and tradeoffs
Sensor Labs Hands-on ESP32 projects, Wokwi simulations Practice circuit design and signal conditioning with real hardware

Fundamentals:

Sensors:

Practice:

Advanced:

22.11 Quick Reference Cards

22.11.1 Common Sensor Connections

Sensor Type Typical Connection
Thermistor (NTC) Voltage divider with fixed resistor (10k typical)
LDR (Photoresistor) Voltage divider, R varies ~100 ohms (bright) to ~1M ohms (dark)
DHT22 3.3V, GND, DATA (4.7k pull-up)
I2C Sensors VCC, GND, SDA (4.7k pull-up), SCL (4.7k pull-up)
Ultrasonic VCC, GND, TRIG, ECHO

22.11.2 ADC Resolution Reference

Bits Steps Resolution (3.3V ref) Common MCUs Best For
8 256 12.9 mV ATtiny85 Simple controls
10 1024 3.2 mV Arduino Uno/Nano (ATmega328P) Temperature, light
12 4096 0.8 mV ESP32, STM32, RP2040 Most IoT sensors
16 65536 50 uV ADS1115 (external I2C ADC) Precision measurement

22.11.3 Troubleshooting Checklist

Check Why It Matters
Power supply voltage correct (3.3V vs 5V)? A 5V sensor on a 3.3V MCU can damage the input pin; a 3.3V sensor on 5V may produce out-of-range readings
Ground connection solid? Floating or high-resistance ground causes unpredictable voltage offsets and noisy readings
Pull-up/down resistors present where needed? Open-drain outputs (I2C, DHT22) float without pull-ups, producing erratic data or communication failures
Voltage divider output within ADC range? Output exceeding Vref clips at maximum ADC value and may damage the pin; use the calculator above to verify
Decoupling capacitors (100nF) near sensor? Power supply noise couples directly into sensor readings; a capacitor within 10mm of the sensor’s VCC pin filters this
RC filter cutoff above signal, below noise? Cutoff too low attenuates your signal; too high lets noise through; use the RC filter calculator above to verify
Sampling rate ≥ 2× highest signal frequency? Violating the Nyquist criterion causes aliasing – the ADC reports false frequencies that don’t exist in the real signal