Back to Sensors & Actuators Series

Part 2: Understanding Sensors

July 14, 2025 Wasil Zafar 40 min read

Deep dive into sensor fundamentals — transducers vs sensors, analog vs digital signals, key characteristics like accuracy and sensitivity, and the physics behind signal conversion.

Table of Contents

  1. Transducers vs Sensors
  2. Analog vs Digital Signals
  3. Sensor Characteristics
  4. Signal Types & Outputs
  5. Sensor Interfacing Basics
  6. Conclusion & Next Steps

Transducers vs Sensors

The terms “sensor” and “transducer” are often used interchangeably, but they have distinct technical meanings. A transducer converts energy from one form to another. A sensor is a transducer that converts a physical phenomenon into an electrical signal for measurement.

Key Distinction:
  • Transducer: Any device that converts energy between forms (e.g., speaker converts electrical → sound)
  • Sensor: A transducer that specifically converts a measurand → electrical signal (input transducer)
  • Actuator: A transducer that converts electrical signal → physical action (output transducer)

Sensor Classification

Sensors can be classified along multiple axes depending on the application context:

Sensor Classification Framework

Taxonomy Reference
ClassificationCategoriesExamples
By MeasurandTemperature, pressure, light, motion, chemicalThermocouple, strain gauge, photodiode
By OutputAnalog (continuous) vs Digital (discrete)LM35 (analog), DHT22 (digital)
By PowerActive (self-generating) vs Passive (needs excitation)Thermocouple (active), RTD (passive)
By ContactContact vs Non-contactThermocouple (contact), IR pyrometer (non-contact)
By TechnologyResistive, capacitive, inductive, piezoelectric, opticalPotentiometer, capacitive touch, LVDT
Sensor Classification Taxonomy
graph TD
    S["🔍 Sensor Classifications"] --> M["By Measurand"]
    S --> O["By Output"]
    S --> P["By Power Source"]
    S --> C["By Contact"]
    S --> T["By Technology"]
    M --> M1["Temperature"]
    M --> M2["Pressure"]
    M --> M3["Light"]
    M --> M4["Motion"]
    M --> M5["Chemical"]
    O --> O1["Analog
Continuous"] O --> O2["Digital
Discrete"] P --> P1["Active
Self-generating"] P --> P2["Passive
Needs excitation"] C --> C1["Contact"] C --> C2["Non-contact"] T --> T1["Resistive"] T --> T2["Capacitive"] T --> T3["Inductive"] T --> T4["Piezoelectric"] T --> T5["Optical"] style S fill:#3B9797,stroke:#3B9797,color:#fff style M fill:#e8f4f4,stroke:#3B9797,color:#132440 style O fill:#e8f4f4,stroke:#3B9797,color:#132440 style P fill:#e8f4f4,stroke:#3B9797,color:#132440 style C fill:#e8f4f4,stroke:#3B9797,color:#132440 style T fill:#e8f4f4,stroke:#3B9797,color:#132440

Active vs Passive Sensors

Active Sensors generate their own electrical signal from the measured energy:
  • Thermocouple: Seebeck effect generates voltage from temperature difference
  • Piezoelectric: Mechanical stress generates charge/voltage
  • Photodiode: Light energy generates photocurrent
Passive Sensors require external excitation (voltage/current) to produce a measurable output:
  • RTD: Resistance changes with temperature — needs excitation current
  • Strain Gauge: Resistance changes with deformation — needs Wheatstone bridge
  • Thermistor: Resistance varies with temperature — needs voltage divider

Analog vs Digital Signals

Analog Signal Characteristics

Analog signals are continuous in both time and amplitude. They represent physical quantities as proportional voltages or currents. A temperature sensor might output 0–3.3V corresponding to 0–100°C.

Analog Signal Properties:
  • Continuous amplitude: Infinite resolution — any value between min and max
  • Susceptible to noise: EMI, ground loops, and cable length degrade signal quality
  • Bandwidth-limited: Signal frequency content determines required sampling rate
  • Requires ADC: Must be digitized before an MCU can process the data

Digital Signal Characteristics

Digital sensors output data in discrete formats — serial protocols (I2C, SPI, UART), pulse trains, or simple on/off states. They internally handle ADC conversion and often include calibration data in on-chip memory.

Analog vs Digital Sensor Comparison

FeatureAnalog SensorDigital Sensor
OutputContinuous voltage/currentSerial data (I2C, SPI, UART)
Noise ImmunityLow — susceptible to EMIHigh — digital encoding resists noise
Cable LengthShort (signal degrades)Long (digital protocols tolerate noise)
ResolutionLimited by ADC bitsBuilt-in ADC (often 12-24 bit)
CostGenerally cheaperHigher but more integrated
CalibrationExternal (software or hardware)Factory-calibrated on-chip
ExamplesLM35, potentiometer, photoresistorDHT22, BME280, MPU6050

ADC Conversion Basics

An Analog-to-Digital Converter (ADC) samples a continuous voltage and quantizes it into a discrete digital value. The key parameters are:

For an $n$-bit ADC with reference voltage $V_{ref}$:

$$\text{Resolution} = \frac{V_{ref}}{2^n - 1}$$

$$V_{measured} = \text{ADC\_value} \times \frac{V_{ref}}{2^n - 1}$$

A 12-bit ADC with 3.3V reference has a resolution of $\frac{3.3}{4095} \approx 0.806 \text{ mV}$ per step.

// Reading an analog sensor with STM32 ADC
#include "stm32f4xx.h"

void adc_init(void) {
    // Enable clocks
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
    RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;

    // PA0 as analog input
    GPIOA->MODER |= (3U << (0 * 2));   // Analog mode (11)

    // ADC1 configuration
    ADC1->CR1  = 0;                     // 12-bit resolution
    ADC1->CR2  = 0;
    ADC1->SQR3 = 0;                     // Channel 0 (PA0)
    ADC1->SMPR2 = (7U << 0);           // 480 cycles sample time

    ADC1->CR2 |= ADC_CR2_ADON;         // Enable ADC
}

uint16_t adc_read(void) {
    ADC1->CR2 |= ADC_CR2_SWSTART;      // Start conversion
    while (!(ADC1->SR & ADC_SR_EOC));   // Wait for completion
    return (uint16_t)ADC1->DR;          // Read result (0-4095)
}

float adc_to_voltage(uint16_t raw) {
    return raw * (3.3f / 4095.0f);      // Convert to voltage
}

float voltage_to_temp_lm35(float voltage) {
    return voltage * 100.0f;            // LM35: 10 mV/°C
}

Sensor Characteristics

Selecting the right sensor requires understanding its static and dynamic characteristics. These describe how accurately, precisely, and quickly a sensor responds to changes.

Static Characteristics

Static Sensor Parameters

Specifications Selection Criteria
  • Range: Min to max measurable value (e.g., -40°C to +125°C)
  • Sensitivity: Output change per unit input change (e.g., 10 mV/°C for LM35). Formally: $S = \frac{\Delta \text{output}}{\Delta \text{input}}$
  • Accuracy: Closeness of reading to true value (±0.5°C)
  • Precision: Repeatability of readings under identical conditions
  • Resolution: Smallest detectable change in input (0.01°C)
  • Linearity: How closely output follows a straight line vs input. Non-linearity is specified as ±% of full scale
  • Hysteresis: Difference in output when approaching the same input from opposite directions
  • Drift: Gradual change in output over time at constant input (aging, thermal effects)
  • Offset: Non-zero output when input is zero (zero error)

Dynamic Characteristics

How Fast Can a Sensor Respond?
  • Response Time: Time to reach 90% of final value after a step change (typically $\tau_{90}$)
  • Time Constant ($\tau$): Time to reach ~63.2% of final value (first-order systems)
  • Rise Time: Time from 10% to 90% of final value
  • Bandwidth: Frequency range where sensitivity remains within ±3 dB
  • Natural Frequency: Resonant frequency of the sensing element (accelerometers, pressure sensors)

For a first-order sensor with time constant $\tau$, the step response is:

$$y(t) = y_{final} \left(1 - e^{-t/\tau}\right)$$

Error Sources

Common Sensor Errors:
  • Systematic Errors: Offset, gain error, non-linearity — correctable via calibration
  • Random Errors: Noise, thermal fluctuations — reduced by averaging/filtering
  • Environmental: Temperature drift, humidity effects, vibration
  • Loading Effects: Measurement circuit alters the quantity being measured
  • EMI: Electromagnetic interference from motors, switches, radios

Signal Types & Outputs

Voltage Output

The simplest sensor output is a proportional voltage. Common ranges include 0–5V, 0–3.3V, and ±10V for industrial sensors.

// Voltage divider sensor reading (thermistor)
#include <stdio.h>
#include <math.h>

// Steinhart-Hart equation for NTC thermistor
float thermistor_to_temp(uint16_t adc_raw) {
    float R_fixed = 10000.0f;         // 10k reference resistor
    float V_ref = 3.3f;
    float V_adc = adc_raw * (V_ref / 4095.0f);

    // Calculate thermistor resistance
    float R_therm = R_fixed * (V_ref / V_adc - 1.0f);

    // Steinhart-Hart coefficients (for 10k NTC)
    float A = 1.009249e-3f;
    float B = 2.378405e-4f;
    float C = 2.019202e-7f;
    float ln_R = logf(R_therm);

    float T_kelvin = 1.0f / (A + B * ln_R + C * ln_R * ln_R * ln_R);
    return T_kelvin - 273.15f;        // Convert to Celsius
}

Current Loop (4–20 mA)

Industrial sensors often use 4–20 mA current loops because current signals are immune to voltage drops over long cable runs. The 4 mA baseline also enables broken-wire detection — if the current drops to 0 mA, the wire is broken.

4–20 mA Advantages:
  • Immune to cable resistance (voltage drop doesn’t affect current)
  • Can transmit over 1000+ meters without signal degradation
  • 4 mA = minimum (live zero) for fault detection
  • 20 mA = full scale; linear mapping to measured range
  • Two-wire operation — power and signal on same pair

The conversion from current to measured value:

$$\text{Value} = \text{Range}_{min} + \frac{(I - 4\text{ mA})}{16\text{ mA}} \times (\text{Range}_{max} - \text{Range}_{min})$$

Frequency & Pulse Output

Some sensors output a frequency or pulse train proportional to the measured quantity. Examples include flow meters (pulses per liter) and optical encoders (pulses per revolution).

// Timer Input Capture: Measure sensor frequency
#include "stm32f4xx.h"

volatile uint32_t capture_value = 0;
volatile uint32_t frequency_hz = 0;

void TIM3_IRQHandler(void) {
    if (TIM3->SR & TIM_SR_CC1IF) {
        TIM3->SR &= ~TIM_SR_CC1IF;

        uint32_t current = TIM3->CCR1;
        if (current > 0) {
            // Timer clock = 1 MHz (after prescaler)
            frequency_hz = 1000000 / current;
        }
    }
}

void input_capture_init(void) {
    RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

    // PA6 = TIM3_CH1 (AF2)
    GPIOA->MODER  |= (2U << 12);
    GPIOA->AFR[0] |= (2U << 24);

    TIM3->PSC   = 84 - 1;           // 1 MHz timer clock
    TIM3->ARR   = 0xFFFF;
    TIM3->CCMR1 = TIM_CCMR1_CC1S_0; // Input capture on TI1
    TIM3->CCER  = TIM_CCER_CC1E;     // Enable capture
    TIM3->DIER  = TIM_DIER_CC1IE;    // Interrupt on capture

    NVIC_EnableIRQ(TIM3_IRQn);
    TIM3->CR1 |= TIM_CR1_CEN;
}

Sensor Interfacing Basics

Reading Analog Sensors

Analog sensors connect to ADC input pins. The interface typically involves a voltage divider or signal conditioning circuit to match the sensor output range to the ADC input range.

#!/usr/bin/env python3
"""Read analog sensor via MCP3008 ADC on Raspberry Pi"""

import spidev
import time

# Initialize SPI for MCP3008
spi = spidev.SpiDev()
spi.open(0, 0)          # Bus 0, Device 0
spi.max_speed_hz = 1350000

def read_adc(channel):
    """Read a single ADC channel (0-7) from MCP3008"""
    if channel < 0 or channel > 7:
        return -1
    # MCP3008 SPI protocol: start bit, single/diff, channel
    cmd = [1, (8 + channel) << 4, 0]
    result = spi.xfer2(cmd)
    value = ((result[1] & 3) << 8) | result[2]
    return value  # 10-bit: 0-1023

# Read temperature from LM35 on channel 0
for i in range(10):
    raw = read_adc(0)
    voltage = raw * (3.3 / 1023.0)
    temp_c = voltage * 100.0
    print(f"Reading {i+1}: ADC={raw}, V={voltage:.3f}V, Temp={temp_c:.1f}°C")
    time.sleep(1)

spi.close()

Reading Digital Sensors

#!/usr/bin/env python3
"""Read BME280 digital sensor via I2C on Raspberry Pi"""

import smbus2
import time

BME280_ADDR = 0x76
bus = smbus2.SMBus(1)

# Read chip ID (should be 0x60 for BME280)
chip_id = bus.read_byte_data(BME280_ADDR, 0xD0)
print(f"BME280 Chip ID: 0x{chip_id:02X}")

# Configure: forced mode, 1x oversampling
bus.write_byte_data(BME280_ADDR, 0xF2, 0x01)  # Humidity OS x1
bus.write_byte_data(BME280_ADDR, 0xF4, 0x27)  # Temp/Press OS x1, Normal mode

time.sleep(0.1)

# Read raw temperature (20-bit)
data = bus.read_i2c_block_data(BME280_ADDR, 0xFA, 3)
raw_temp = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4)
print(f"Raw temperature: {raw_temp}")

# Read raw pressure (20-bit)
data = bus.read_i2c_block_data(BME280_ADDR, 0xF7, 3)
raw_press = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4)
print(f"Raw pressure: {raw_press}")

bus.close()

Conclusion & Next Steps

You now understand the fundamental concepts behind sensors — the difference between transducers, active and passive sensors, analog vs digital signals, and the key characteristics that determine sensor suitability for any application.

Key Takeaways:
  • Sensors are input transducers that convert physical quantities into electrical signals
  • Analog sensors need ADC conversion; digital sensors output serial data directly
  • Accuracy, sensitivity, resolution, and response time are critical selection criteria
  • 4–20 mA current loops are preferred for long-distance industrial sensor communication
  • Always account for noise, drift, and environmental effects in sensor system design

In Part 3, we explore Sensor Categories — a comprehensive survey of temperature, pressure, proximity, motion, light, environmental, position, and biomedical sensors with interfacing guides for each.