2  Sensor Fundamentals and Types

sensors
sensing
fundamentals
iot

2.1 Learning Objectives

  • Explain how sensors bridge the physical and digital worlds by converting physical phenomena into electrical signals
  • Interpret sensor specifications including accuracy, precision, resolution, range, and response time from datasheets
  • Apply signal processing techniques such as filtering and calibration to obtain reliable sensor measurements
  • Classify sensors by measurement type, output signal, and power requirements for systematic selection
  • Select appropriate sensors for IoT projects by evaluating cost, performance, environmental constraints, and interface compatibility
In 60 Seconds

Sensors bridge the physical and digital worlds by converting physical phenomena — temperature, pressure, motion, light — into electrical signals a microcontroller can read. Key specifications to compare are: accuracy (closeness to true value), precision (repeatability), resolution (smallest detectable change), range (measurement limits), and response time (how quickly the output tracks a change). Always read the datasheet before selecting a sensor.

2.2 Sensors: The Eyes and Ears of IoT

Welcome to the world of sensors! This is your roadmap for learning everything about how IoT devices “sense” the physical world.

What you’ll learn:

  • What sensors are and why every IoT device needs them
  • How to choose the right sensor for temperature, motion, distance, and more
  • How to read datasheets so you can understand any sensor’s capabilities
  • Common mistakes to avoid that trip up even experienced engineers
  • Hands-on labs where you’ll build real sensor projects

Time commitment: The full series takes about 5-6 hours. But you can jump to any chapter that interests you.

Prerequisites: Basic understanding of electricity (voltage, current) and electronics (circuits, components). See the Prerequisites section below for links.

When two sensors appear to measure the same thing, the real decision usually comes down to four constraints:

  • Measurement fit: Does the range, accuracy, resolution, and response time match the problem?
  • Electrical fit: Does the output type match your hardware: analog, I2C, SPI, UART, or 1-Wire?
  • Deployment fit: Will it still perform under the actual temperature, humidity, vibration, dust, or washdown conditions?
  • System fit: What does it cost in BOM budget, calibration effort, firmware complexity, and battery life?

This chapter introduces the main sensor families first. Later chapters show how datasheets, calibration, signal conditioning, and power management turn that initial choice into a working IoT design.

Sensors are the fundamental building blocks of IoT systems, serving as the bridge between the physical and digital worlds. They convert physical phenomena (temperature, pressure, motion, light, etc.) into electrical signals that can be processed by microcontrollers and computers.

This comprehensive guide has been organized into focused chapters for easier learning. Start with the introduction and work through each chapter, or jump directly to topics of interest.

2.3 Learning Path

Beginner-friendly overview of sensor types showing eight common categories: temperature, light, motion, humidity, distance, pressure, gas, and sound with typical models, specifications, and applications
Figure 2.1: Beginner-friendly overview of sensor types

2.3.1 Getting Started (Beginner)

Chapter Description Time
1. Introduction What are sensors, terminology, and why they matter 15 min
2. Biomimetic Sensing Learn from nature: human skin’s sensor architecture 20 min
3. Sensor Specifications Understanding accuracy, precision, resolution, range 25 min

2.3.2 Core Concepts (Intermediate)

Chapter Description Time
4. Signal Processing Filtering, noise reduction, avoiding pitfalls 20 min
5. Classification Types by measurement, output, and power 15 min
6. Braitenberg Model Sensor-actuator behavior relationships 20 min
7. Infrastructure Sensing Using existing infrastructure as sensors 20 min

2.3.3 Practical Skills (Intermediate)

Chapter Description Time
8. Calibration How to calibrate sensors properly 25 min
9. Reading Datasheets Decode sensor specifications 20 min
10. Common Sensors Popular IoT sensors and MEMS technology 30 min
11. Hands-On Labs Interactive exercises with real sensors 45 min

2.3.4 Application (Intermediate-Advanced)

Chapter Description Time
12. Selection Guide Tools and techniques for choosing sensors 25 min
13. Common Mistakes Top 10 pitfalls and how to avoid them 15 min
14. Advanced Topics Noise, sensor fusion, production systems 30 min
15. Quiz & Exercises Test your knowledge 30 min

2.4 Cross-Hub Connections

Explore Related Learning Resources

Interactive Learning:

Cross-Reference Topics:

2.5 Quick Reference

2.5.1 Key Concepts Summary

Concept Definition Why It Matters
Accuracy How close to true value Determines if measurements are reliable
Precision How repeatable High precision + calibration = good accuracy
Resolution Smallest detectable change Must be finer than required accuracy
Response Time How fast sensor reacts Critical for control loops
Range Min to max measurable Must cover all expected conditions

Check your understanding of these key concepts:

2.5.2 Common Sensor Quick Reference

Sensor Measures Accuracy Interface Cost
DHT22 Temp, Humidity ±0.5°C Digital $5
BME280 Temp, Hum, Pressure ±1°C I2C/SPI $8
DS18B20 Temperature ±0.5°C 1-Wire $3
PIR Motion Binary Digital $2
HC-SR04 Distance ±3 mm Digital $3
MPU6050 Accel, Gyro ±3% I2C $5

2.5.3 Prerequisites

Before diving into sensors, ensure familiarity with:

2.6 Explore the Numbers

Resolution vs Accuracy: The ADC Math

Example Calculation (12-bit ADC, 0-3.3V):

A 12-bit ADC measuring 0-3.3V provides resolution of:

\[\text{Resolution} = \frac{V_{max} - V_{min}}{2^{bits}} = \frac{3.3V - 0V}{2^{12}} = \frac{3.3V}{4096} = 0.805 \text{ mV/step}\]

For a thermistor outputting 10 mV/°C:

\[\text{Temperature resolution} = \frac{0.805 \text{ mV}}{10 \text{ mV/}^\circ\text{C}} = 0.0805\,^\circ\text{C per ADC step}\]

But accuracy depends on the ADC’s INL/DNL errors:

  • INL (Integral Nonlinearity): Typical ±2 LSB for ESP32 ADC = ±1.61 mV error
  • Temperature accuracy: \(\pm 1.61 \text{ mV} \div 10 \text{ mV/°C} = \pm 0.16°C\)

Key insight: 12-bit resolution (0.0805°C steps) does not mean 0.0805°C accuracy. Real accuracy is limited by sensor tolerance (±1-2°C for thermistors) and ADC linearity (±0.16°C). Resolution determines how smoothly readings change, not how correct they are.

Sensor Sampling Power Budget:

Example Calculation (DS18B20 reading every 10 minutes):

\[I_{avg} = \frac{I_{active} \times t_{active} + I_{sleep} \times t_{sleep}}{t_{total}}\]

For DS18B20 reading every 10 minutes:

\[I_{avg} = \frac{1.5\text{ mA} \times 0.75\text{ s} + 0.001\text{ mA} \times 599.25\text{ s}}{600\text{ s}} = \frac{1.125 + 0.599}{600} = 0.0029 \text{ mA}\]

Battery life: \(2500 \text{ mAh} \div 0.0029 \text{ mA} = 862,069 \text{ hours} \approx 98 \text{ years}\) (theoretical, self-discharge dominates)

2.7 Temperature Sensor Selection Calculator

Use this interactive tool to evaluate whether a candidate temperature sensor meets your application requirements. Adjust the sliders to match your sensor’s specifications and your application needs. For other sensor types (humidity, distance, acceleration), apply the same pass/fail methodology with appropriate units.

2.8 Start Learning

Ready to begin? Start with the first chapter:

Begin with Sensor Introduction ->

Or jump to a specific topic using the learning path table above.

2.9 Key Takeaways

  1. Sensors are the interface between physical phenomena and digital processing
  2. Match specifications to requirements – a sensor’s accuracy, resolution, and response time must each meet or exceed your application’s needs, with margin for real-world degradation
  3. High resolution does not guarantee reliability – always verify that accuracy is sufficient for your control tolerance before considering resolution
  4. Calibration is essential for most sensing applications to correct factory tolerances and environmental drift
  5. Read datasheets carefully – distinguish between typical and worst-case specs, and note the conditions under which specifications were measured

2.10 Knowledge Check

Match each sensor specification to its correct definition:

Place these sensor selection steps in the correct order:

Scenario: You’re designing a smart thermostat for residential HVAC control. The system must maintain room temperature within ±1.0°C of the setpoint (e.g., if setpoint is 22°C, acceptable range is 21-23°C). You’re evaluating three temperature sensor options:

Candidate Sensors:

Sensor Accuracy Resolution Conversion / Min Sample Time Cost Interface
A: DHT22 ±0.5°C 0.1°C 2s min sampling period $4 Digital (proprietary)
B: TMP36 ±1°C at 25°C (±2°C full range) ~0.01°C (via ADC) ~1s analog settle $1.50 Analog voltage
C: DS18B20 ±0.5°C 0.0625°C 750ms conversion (12-bit) $3 Digital (1-Wire)

Analysis:

Step 1: Accuracy Requirement Check

  • System must detect ±1.0°C deviations from setpoint
  • Example: If setpoint = 22°C, must reliably distinguish 21°C from 23°C
  • Accuracy requirement: Better than ±0.5°C (half the threshold margin)

Sensor A (DHT22): ±0.5°C accuracy ✓ - At true 21°C, could read 20.5°C to 21.5°C - At true 23°C, could read 22.5°C to 23.5°C - Worst case: True 21°C reads as 21.5°C, just below 22°C threshold → PASS

Sensor B (TMP36): ±1°C accuracy at 25°C ⚠️ (marginal) - At true 21°C, could read 20°C to 22°C - At true 23°C, could read 22°C to 24°C - Worst case: True 21°C reads as 22°C (setpoint) → System fails to detect 1°C undershoot - Verdict: Marginal – the sensor’s accuracy exactly equals the control tolerance, leaving zero margin for drift, aging, or self-heating. In practice, this is risky for reliable ±1°C control

Sensor C (DS18B20): ±0.5°C accuracy ✓ - Same analysis as Sensor A → PASS

Step 2: Resolution Requirement Check

  • Need to distinguish 1°C differences
  • Resolution must be at least 10× finer than accuracy requirement for smooth control
  • Requirement: ≤0.1°C resolution

Sensor A (DHT22): 0.1°C resolution ✓ (exactly meets requirement)

Sensor B (TMP36):

  • Analog output: 10 mV/°C
  • ADC: 12-bit (4096 steps) on 3.3V reference
  • Voltage resolution: 3.3V / 4096 = 0.805mV per ADC step
  • Temperature resolution: 0.805mV / (10mV/°C) = 0.0805°C ✓ (exceeds requirement)
  • Note: High resolution doesn’t compensate for marginal ±1°C accuracy!

Sensor C (DS18B20): 0.0625°C resolution ✓ (far exceeds requirement)

Step 3: Conversion Time and Thermal Response

  • Conversion/sampling time (time to produce a reading): All three sensors are well under 5 seconds
  • Thermal response time (time for sensor package to equilibrate with environment): Typically 5-10s in still air for TO-92 packages (DS18B20, TMP36), longer in protective housings
  • Residential HVAC: thermal mass of room is slow (10-30 minutes to change 1°C), so both conversion time and thermal response are negligible
  • Control loop update rate: 10 seconds sufficient

All sensors meet timing requirements: DHT22 (2s sampling period), TMP36 (~1s analog settle), DS18B20 (750ms conversion) ✓

Step 4: Interface Complexity

  • Digital sensors (DHT22, DS18B20): Software library handles communication
  • Analog sensor (TMP36): Requires ADC pin, voltage divider if 5V sensor on 3.3V MCU

Winner: DS18B20 or DHT22 (both meet all requirements)

Final Selection: DS18B20

Reasoning:

  1. Accuracy: ±0.5°C meets ±1°C control requirement with margin
  2. Resolution: 0.0625°C provides smooth control (16× finer than requirement)
  3. Multi-sensor capability: 1-Wire bus allows multiple DS18B20s on one GPIO pin for zone control or averaging
  4. Cost: $3 is acceptable for residential thermostat BOM
  5. Reliability: Digital interface immune to ADC noise and voltage reference drift

Implementation:

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
    Serial.begin(9600);
    sensors.begin();
}

void loop() {
    sensors.requestTemperatures();
    float temp = sensors.getTempCByIndex(0);
    Serial.print("Temperature: ");
    Serial.print(temp);
    Serial.println(" C");

    // Control logic with hysteresis (±0.5°C band around 22°C setpoint)
    // Note: In production, widen hysteresis to >=2x sensor accuracy
    // to prevent oscillation from measurement noise at switching points
    if (temp < 21.5) {
        // Turn on heating
    } else if (temp > 22.5) {
        // Turn on cooling
    }
    // Else: within comfort range, no action

    delay(10000); // Read every 10 seconds
}

Real-World Validation: After deployment, measure actual performance: - Record 1000 temperature readings over 24 hours - Compare to calibrated reference thermometer - Calculate mean absolute error (MAE) and standard deviation - Expected: MAE < 0.3°C, σ < 0.2°C - If MAE > 0.5°C: perform two-point calibration to correct offset

Cost-Benefit Analysis:

  • DS18B20 ($3) vs TMP36 ($1.50) = $1.50 premium
  • Value: Reliable ±1°C control can prevent up to 10-20% energy waste in scenarios with frequent overshooting (actual savings depend on insulation, climate, and HVAC efficiency)
  • Annual energy savings (2500 kWh HVAC): 500 kWh × $0.12/kWh = $60/year
  • Payback time: $1.50 / $60 = 0.025 years = 9 days

Key Lesson: For control applications, accuracy matters far more than resolution. The TMP36’s excellent 0.0805°C resolution is undermined by its ±1°C accuracy at room temperature, which leaves zero margin for a ±1°C control requirement. Always match sensor specifications to your application requirements with adequate margin, not just “more is better.”

Common Pitfalls

A sensor can be precise (repeatable) but inaccurate (consistently wrong by a fixed offset). Calibration corrects systematic offset errors. A sensor with large random variation is imprecise — filtering reduces the effect but calibration cannot fix random noise.

A sensor with excellent specs at 25 C may perform much worse at the actual deployment temperature. Always check the datasheet for accuracy vs. temperature curves and verify the sensor is rated for the full deployment temperature range.

Choosing a sensor before verifying the microcontroller has enough GPIO pins and the required peripheral hardware wastes design time. Confirm the interface protocol, logic levels, and library availability before purchasing.

The datasheet active current often reflects peak consumption. Calculate average current using the duty cycle formula: Iavg = Iactive x (ton/tperiod) + Isleep x (1 - ton/tperiod) to accurately estimate battery life.

2.11 What’s Next

After completing this series, continue your IoT learning journey with:

Topic Description
Sensor Interfacing and Processing Advanced connection techniques for analog and digital sensor interfaces
Actuators Complete the sensing-actuation control loop with motors, relays, and displays
Mobile Phone as a Sensor Leverage the accelerometer, GPS, camera, and other smartphone sensors for IoT
Applications and Sensors Real-world sensor deployments in smart homes, agriculture, and industry
Signal Processing Essentials Filtering, noise reduction, and linearization techniques for raw sensor data
Energy-Aware Design Optimize sensor sampling strategies for battery-powered IoT deployments