Sensors are classified by measurement type (environmental, motion, chemical), output type (analog, digital, I2C, SPI, UART, 1-Wire), and power requirement (active vs passive). Use analog for simple low-cost sensors, I2C when sharing a bus with multiple devices, SPI for high-speed data, and UART for smart sensors with built-in processing. Passive sensors consume far less power than active sensors, making them ideal for battery-powered IoT deployments.
Key Concepts
Active vs. Passive Sensor: Active sensors require external power to operate (thermistors, LDRs, strain gauges); passive sensors generate their own electrical output from the measured phenomenon (thermocouples, piezoelectric sensors)
Contact vs. Non-Contact Sensor: Contact sensors must physically touch the measured object (thermistors, strain gauges); non-contact sensors measure from a distance (IR thermometers, ultrasonic range finders, capacitive proximity sensors)
Absolute vs. Relative Sensor: Absolute sensors reference to a fixed standard (GPS coordinates, absolute barometric pressure); relative sensors reference to a condition (differential pressure, incremental encoder position)
Analog vs. Digital Output: Analog sensors produce a continuous voltage or current proportional to the measured quantity; digital sensors produce discrete values through I2C, SPI, UART, or PWM protocols
Scalar vs. Vector Sensor: Scalar sensors measure a single-value quantity (temperature, pressure, distance); vector sensors measure magnitude and direction (3-axis accelerometers, 3-axis magnetometers)
Intrinsic vs. Extrinsic Optical Fiber Sensor: In intrinsic sensors the fiber itself is the sensing element (fiber Bragg gratings); in extrinsic sensors the fiber only carries light to and from an external sensing element
Primary vs. Derived Measurement: A primary measurement directly senses the physical quantity (RTD measures resistance); a derived measurement computes the quantity from other measurements (wind speed from anemometer pulse frequency)
Self-Calibrating Sensor: Sensors with internal reference elements or automatic compensation circuits that adjust for temperature drift and aging without user intervention; reduces maintenance burden in deployed IoT systems
Learning Objectives
After completing this chapter, you will be able to:
Classify sensors by measurement type (environmental, motion/position, chemical/gas)
Compare output types (analog, digital, I2C, SPI, UART, 1-Wire) and their trade-offs
Differentiate between active and passive sensors based on power and energy emission characteristics
Select appropriate sensor interfaces for a given IoT project based on GPIO, cost, and noise constraints
For Beginners: Sensor Classifications
Just like animals can be classified into mammals, birds, and fish, sensors can be grouped by what they measure (temperature, motion, light) and how they communicate with a microcontroller (analog voltage, digital pulses, or data protocols like I2C). Understanding these categories helps you quickly narrow down which sensor to use for your project, rather than being overwhelmed by the thousands of options available.
Sensor classification follows a hierarchical approach:
Identify measurement domain - What physical property needs sensing? (temperature, motion, chemical concentration)
Determine signal path - How does the signal reach your microcontroller? (analog voltage, digital protocol, frequency modulation)
Assess power source - Does the sensor emit energy (active) or detect existing energy (passive)?
Match to application - Cross-reference requirements with sensor categories to narrow choices
Example flow: “I need to measure room occupancy” → Motion sensing → Passive IR detection → PIR sensor (detects existing thermal radiation, no emitted energy) → Digital output (HIGH/LOW) → Battery-friendly (50μA standby)
The first question when selecting a sensor is: “What physical quantity do I need to measure?” Sensors fall into three broad families, each targeting different aspects of the physical world. This classification matters because it determines not only the sensor technology but also the signal conditioning, calibration procedures, and maintenance requirements for your IoT deployment.
9.2.1 Environmental Sensors
Environmental sensors are the workhorses of IoT – they monitor the ambient conditions that affect human comfort, crop growth, equipment health, and building efficiency. Most IoT projects start here because environmental data is easy to collect, immediately useful, and the sensors are mature and inexpensive.
Sensor Type
What It Measures
Common Models
Typical Accuracy
Temperature
Thermal energy
DHT22, DS18B20, BME280
±0.5°C
Humidity
Moisture in air
DHT22, SHT31, BME280
±2-3% RH
Pressure
Atmospheric pressure
BMP280, MS5611
±1 hPa
Light
Ambient illumination
BH1750, TSL2561
±5% lux
Air Quality
CO2, VOCs, particulates
MQ-135, BME680, PMS5003
Varies
9.2.2 Motion and Position Sensors
Motion sensors answer the question “Where is it, and how is it moving?” These sensors are essential for wearables, robotics, asset tracking, and any IoT system that needs spatial awareness. A key design decision is whether you need absolute position (GPS gives latitude/longitude) or relative motion (accelerometers detect changes in velocity). Many applications combine both – a fitness tracker uses GPS for outdoor routes and accelerometers for indoor step counting where GPS signals cannot penetrate.
Sensor Type
What It Measures
Common Models
Applications
Accelerometer
Linear acceleration
ADXL345, MPU6050
Step counting, tilt
Gyroscope
Angular velocity
MPU6050, L3GD20
Rotation, orientation
Magnetometer
Magnetic field
QMC5883L, LIS3MDL
Compass, heading
GPS
Geographic position
NEO-6M, NEO-M8N
Location tracking
Proximity
Object presence
HC-SR04, VL53L0X
Distance, presence
9.2.3 Chemical and Gas Sensors
Chemical sensors detect the invisible – gases, compounds, and chemical concentrations that human senses cannot reliably measure. These sensors are critical for safety (detecting carbon monoxide or gas leaks), environmental monitoring (measuring air quality in cities), and industrial process control (ensuring food production stays within safe pH ranges). A distinctive characteristic of many chemical sensors is the “burn-in” period: metal-oxide gas sensors like the MQ series need 24-48 hours of initial heating before their readings stabilize. Plan for this during deployment – a freshly powered sensor gives unreliable readings.
Sensor Type
What It Detects
Common Models
Notes
CO2
Carbon dioxide
MH-Z19, SCD30
NDIR or electrochemical
VOC
Volatile organics
BME680, SGP30
Air quality index
Smoke/Gas
Combustible gases
MQ-2, MQ-5
Requires 24-48h burn-in
pH
Acidity/alkalinity
pH probe + ADC
Needs regular calibration
Cross-Classification: Sensors That Span Categories
Some sensors appear in multiple categories because their classification depends on application context. For example, the MQ-135 (listed under Environmental > Air Quality) is technically a metal-oxide gas sensor in the same family as the MQ-2 and MQ-5 (listed under Chemical/Gas). Similarly, the BME680 combines environmental measurements (temperature, humidity, pressure) with a VOC gas sensor. When you encounter a sensor that fits multiple categories, classify it based on its primary role in your specific application – air quality monitoring is “Environmental,” while detecting specific gas leaks is “Chemical.”
9.3 By Output Type
The output type determines how a sensor communicates with your microcontroller, and this choice has cascading effects on wiring complexity, power consumption, noise immunity, and how many sensors you can connect to a single board. Choosing the wrong interface can mean running out of GPIO pins, introducing noise into sensitive measurements, or making your PCB layout unnecessarily complex.
Worked Example: Interface Choice Shapes an Entire Product
A company is designing a greenhouse monitoring node with 6 sensors: temperature, humidity, soil moisture, light level, CO2, and wind speed. The ESP32-WROOM-32 has 2 I2C buses, 2 SPI buses, 3 UART ports, and 18 analog-capable GPIOs (other ESP32 variants may differ – e.g., the ESP32-S2 has only 1 I2C bus). The interface choice for each sensor has cascading effects on GPIO usage, wiring complexity, power, and cost.
Option 1: All Analog Sensors
Sensor
Part
Interface
GPIO Pins Used
Unit Cost
Temperature
NTC thermistor + voltage divider
Analog
1 ADC
$0.30
Humidity
HR202 resistive + 555 timer circuit
Analog
1 ADC
$0.80
Soil moisture
Capacitive probe (raw voltage)
Analog
1 ADC
$1.50
Light
LDR + resistor divider
Analog
1 ADC
$0.15
CO2
MG-811 electrochemical
Analog
1 ADC + 1 heater GPIO
$18.00
Wind speed
Anemometer pulse output → RC filter → analog
Analog
1 ADC
$12.00
Totals
6 analog + 1 digital
7 GPIOs
$32.75
Problems: Each analog sensor needs individual signal conditioning (resistor dividers, amplifiers, RC filters). The MG-811 CO2 sensor requires a 6V heater drawing 200 mA – a separate voltage regulator and MOSFET driver circuit. Thermistor accuracy is +/-2C without calibration lookup table. Total wiring: 14 individual wires to the ESP32 (power + signal per sensor), plus 6 signal conditioning circuits on the PCB. Firmware needs 6 separate ADC calibration routines.
Option 2: Digital Bus Sensors (I2C + UART)
Sensor
Part
Interface
GPIO Pins Used
Unit Cost
Temperature + humidity
SHT41
I2C (0x44)
Shared SDA/SCL
$2.80
Soil moisture
Stemma soil sensor
I2C (0x36)
Shared SDA/SCL
$6.00
Light
BH1750
I2C (0x23)
Shared SDA/SCL
$1.20
CO2
SCD41 (photoacoustic NDIR, no heater needed)
I2C (0x62)
Shared SDA/SCL
$28.00
Wind speed
Ultrasonic anemometer module
UART
TX + RX
$35.00
Totals
4 I2C + 1 UART
4 GPIOs
$73.00
Advantages: All I2C sensors share just 2 wires (SDA + SCL). No signal conditioning circuits needed – each sensor has built-in ADC, calibration, and digital output. SHT41 replaces two separate sensors (temperature + humidity) in one package. SCD41 uses photoacoustic NDIR sensing instead of electrochemical, eliminating the 200 mA heater (the infrared-based approach detects CO2 without a high-temperature heating element). Total unique signal lines to ESP32: 4 GPIOs (2 I2C + 2 UART), with power distributed via a shared 3.3V/GND bus rail – compared to 7 signal wires plus 6 conditioning circuits for the analog option. Zero analog calibration code.
In this scenario, analog remains cheaper even at production scale because the sensor cost premium ($74.20 - $43.25 = $30.95) is larger than the labor savings ($18.75 - $6.25 = $12.50). Digital only wins when sensor prices drop or when the accuracy, power efficiency, and reduced maintenance justify the higher upfront cost.
Decision: At prototype and production scale, analog sensors have lower upfront cost ($31,000 vs $40,225 at 500 units). However, the greenhouse company chose Option 2 (digital) despite the higher initial cost because: (1) factory-calibrated sensors eliminate $5,000+ in field calibration visits over 3 years, (2) 10x better temperature accuracy (±0.2°C vs ±2°C) prevents crop loss, (3) 5x lower power draw (40 mA vs 200 mA for CO2) extends battery life significantly in solar installations, and (4) simplified firmware reduces engineering time by 40 hours ($4,000 saved). Total 3-year TCO favors digital by $15,000+ when accounting for operational costs.
Key lesson: Interface choice is not just a technical decision – it determines PCB size, assembly time, calibration requirements, and total cost of ownership. Cheap analog sensors can become expensive at scale due to their wiring and calibration burden.
9.4 By Power Requirement
The active/passive distinction is one of the most important for battery-powered IoT deployments. An active sensor emits energy into the environment and measures what comes back (like sonar sending out sound waves), while a passive sensor detects energy that already exists (like a thermometer reading ambient heat). This difference can mean orders of magnitude in power consumption – a typical passive PIR motion sensor draws roughly 50 microamps in standby, while an active radar sensor draws around 50 milliamps – roughly a 1,000x difference that translates directly to battery life.
The wired vs wireless choice is closely tied to power requirements: wireless sensors must carry their own batteries (making the active/passive distinction even more critical), while wired sensors can draw power continuously from the cable.
The three classification dimensions – measurement type, output interface, and power requirement – converge when selecting sensors for a specific application domain. Each domain has its own priorities:
Domain
Common Sensors
Key Requirements
Smart Home
Temperature, humidity, motion, door/window
Low power, easy setup
Industrial IoT
Vibration, temperature, pressure, current
Rugged, accurate, reliable
Agriculture
Soil moisture, temperature, light, weather
Outdoor-rated, long battery
Healthcare
Heart rate, SpO2, temperature, glucose
Medical-grade accuracy
Automotive
Accelerometer, gyroscope, GPS, radar
Fast response, safety-critical
9.6 Practical Implementation: I2C Multi-Sensor Bus
With classification concepts in hand, let us see how sensor interfaces work in practice. I2C is the most common bus protocol in IoT because multiple devices share just two wires. Here is how to scan and read from multiple sensors on the same bus using an ESP32:
# MicroPython: I2C multi-sensor scanning and readingfrom machine import I2C, Pinimport time# Initialize I2C busi2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)# Scan for connected devicesdevices = i2c.scan()print(f"Found {len(devices)} devices:")for addr in devices:print(f" Address: 0x{addr:02X}", end=" ")if addr ==0x76:print("(BMP280 pressure sensor)")elif addr ==0x68:print("(MPU6050 accelerometer/gyroscope)")elif addr ==0x23:print("(BH1750 light sensor)")else:print("(Unknown device)")# --- BMP280 Temperature Reading ---# Read temperature from BMP280 (simplified)def read_bmp280_temp(i2c, addr=0x76): # Use 0x77 if SDO pin is connected to Vddio"""Read raw temperature from BMP280 sensor."""# Read calibration data (registers 0x88-0x9F) cal = i2c.readfrom_mem(addr, 0x88, 6) dig_T1 = cal[0] | (cal[1] <<8) dig_T2 = cal[2] | (cal[3] <<8)if dig_T2 >32767: dig_T2 -=65536 dig_T3 = cal[4] | (cal[5] <<8)if dig_T3 >32767: dig_T3 -=65536# Trigger forced measurement i2c.writeto_mem(addr, 0xF4, bytes([0x25])) time.sleep_ms(50)# Read raw temperature (registers 0xFA-0xFC) raw = i2c.readfrom_mem(addr, 0xFA, 3) raw_temp = (raw[0] <<12) | (raw[1] <<4) | (raw[2] >>4)# Compensation formula from datasheet var1 = ((raw_temp /16384.0) - (dig_T1 /1024.0)) * dig_T2 var2 = (((raw_temp /131072.0) - (dig_T1 /8192.0)) **2) * dig_T3 temp_c = (var1 + var2) /5120.0returnround(temp_c, 2)# Read and displaytemp = read_bmp280_temp(i2c)print(f"Temperature: {temp} C")
Key I2C design considerations:
Parameter
Guideline
Why It Matters
Pull-up resistors
4.7k ohm to 3.3V on SDA and SCL
Required for I2C communication. Some breakout boards include them; check before adding duplicates.
Bus length
< 1 meter for 400 kHz, < 3 meters for 100 kHz
Longer wires increase capacitance, causing signal degradation
Max devices
112 usable addresses (128 minus 16 reserved), practically 10-20
Address conflicts and bus capacitance limit practical count
Clock speed
100 kHz (standard), 400 kHz (fast)
Faster = more data, but more sensitive to noise
9.7 Signal Conditioning: From Raw Sensor to Usable Data
Raw sensor outputs are rarely ready for direct use. A strain gauge might produce only 2 millivolts of signal buried in noise, a thermistor has a non-linear resistance curve, and a 5V sensor output could damage a 3.3V microcontroller. Signal conditioning is the chain of analog circuits that transform a raw sensor signal into a clean, proportional voltage that your ADC can read accurately. Skipping or underdesigning this stage is the most common cause of unreliable sensor readings in IoT prototypes.
Stage
Purpose
Example
Amplification
Boost weak signals
Strain gauge outputs 2 mV; amplify to 0-3.3V range
Filtering
Remove noise
RC low-pass filter removes 50/60 Hz power line noise
Level shifting
Match ADC voltage range
0-5V sensor output shifted to 0-3.3V for ESP32
Linearization
Correct non-linear response
Thermistor follows Steinhart-Hart equation, not linear
Thermistor linearization example:
import mathdef thermistor_temp(adc_value, r_series=10000, beta=3950, r_nominal=10000):"""Convert thermistor ADC reading to temperature. Uses Steinhart-Hart simplified (Beta equation): 1/T = 1/T0 + (1/Beta) * ln(R/R0) Args: adc_value: Raw ADC reading (0-4095 for 12-bit) r_series: Series resistor value (ohms) beta: Thermistor Beta coefficient r_nominal: Resistance at 25C (ohms) """# Calculate thermistor resistance from voltage dividerif adc_value <=0or adc_value >=4095:returnNone# Sensor disconnected or shorted resistance = r_series * (4095.0/ adc_value -1.0)# Steinhart-Hart simplified equation t_kelvin =1.0/ ( (1.0/298.15) +# 1/T0 (T0 = 25C = 298.15K) (1.0/ beta) *# 1/Beta math.log(resistance / r_nominal) # ln(R/R0) )returnround(t_kelvin -273.15, 1) # Convert to Celsius
Sensor classification is the foundation of good sensor selection. Match the measurement type to your application, choose the interface that fits your hardware constraints (I2C for multi-sensor, SPI for speed, analog for simplicity), and consider whether active or passive sensing meets your power budget. Every classification decision affects cost, complexity, power consumption, and reliability.
For Kids: Meet the Sensor Squad!
The Sensor Squad decided to organize themselves! Max the Microcontroller made a big chart on the wall.
“First, what do you MEASURE?” Max asked. Sammy the Sensor said “Temperature!” Others shouted: “Light!” “Motion!” “Gas!” “Distance!” Max wrote them all under different categories: Environmental, Motion, Chemical, and more.
“Next, how do you TALK to me?” Max continued. Some sensors spoke “Analog” (like a dimmer switch – any value from 0 to 100). Others spoke “Digital” (just ON or OFF, like a light switch). And some spoke fancy protocols: “I2C uses two wires and gives everyone a name-tag (address),” explained one. “SPI is faster but needs four wires!” said another.
Lila the LED asked about power. “Some sensors are ACTIVE – they send out energy and listen for echoes, like ultrasonic sensors shouting sound waves,” Max explained. “Others are PASSIVE – they just listen for what is already there, like PIR sensors feeling body heat.”
Bella the Battery smiled: “I like passive sensors best – they use way less of my energy!”
## Concept Relationships
Concept
Related To
Connection Type
Analog Sensors
ADC Resolution
Analog output quality depends on ADC bit depth
I2C Interface
Pull-up Resistors
I2C requires 4.7kΩ pull-ups to function
Active Sensors
Power Budget
Active sensors draw 10-1000x more power than passive
Passive Sensors
Battery Life
Passive PIR (50μA) enables years of battery operation
Digital Protocols
Noise Immunity
Digital signals resist interference better than analog
🏷️ Label the Diagram
Code Challenge
9.8 Summary
Key classification takeaways:
Match measurement type to application - Environmental, motion/position, or chemical/gas
Choose interface wisely - Analog for simple, I2C/SPI for digital, UART for smart sensors
Consider power requirements - Active vs passive impacts battery life
Wired vs wireless - Based on installation constraints and reliability needs
9.9 See Also
Reading Datasheets - How to verify sensor specifications before purchase
1. Misclassifying Output Type When Selecting Libraries
A sensor labeled ‘digital’ may mean it uses a digital communication protocol (I2C, SPI) OR that it produces a simple HIGH/LOW output. Using an I2C library for a PWM-output sensor produces completely incorrect readings. Always check the datasheet’s output type section before selecting a library.
2. Assuming All Analog Sensors Are Low Precision
High-precision industrial 4-20 mA transmitters achieve +-0.1% accuracy — far exceeding many digital consumer sensors. Do not dismiss analog output sensors as inferior; their precision depends on the signal conditioning and ADC resolution in the interface circuit.
3. Confusing Absolute and Gauge Pressure Sensors
Absolute pressure sensors reference a perfect vacuum; gauge pressure sensors reference ambient atmospheric pressure. Using an absolute sensor to measure tire pressure gives readings around 101 kPa + gauge pressure, not just the gauge reading. Selecting the wrong type produces values that appear correct but are practically meaningless.
4. Treating Vector Sensor Axes as Independent Scalars
3-axis accelerometers report gravity components on all three axes simultaneously. Analyzing only one axis ignores the others, producing orientation-dependent readings that change when the device tilts. Always consider the full 3D vector and compensate for static gravity offset.