%%{init: {'theme':'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#ECF0F1','fontSize':'12px'}}}%%
flowchart TD
Start([What do you need to measure?])
Start --> Temp{Temperature?}
Start --> Motion{Motion/Presence?}
Start --> Distance{Distance?}
Start --> Env{Environment?}
Temp --> TempAccuracy{Accuracy needed?}
TempAccuracy -->|"+/-2C OK"| DHT11[DHT11 $2]
TempAccuracy -->|"+/-0.5C"| DHT22[DHT22 $5]
TempAccuracy -->|"+/-0.1C"| SHT31[SHT31 $15]
Motion --> MotionType{Detection type?}
MotionType -->|"Presence only"| PIR[PIR $2]
MotionType -->|"Tilt/orientation"| Accel[MPU6050 $5]
MotionType -->|"Through walls"| Radar[RCWL-0516 $3]
Distance --> DistRange{Range needed?}
DistRange -->|"<2m, precise"| ToF[VL53L0X $10]
DistRange -->|"2-400cm"| Ultrasonic[HC-SR04 $3]
Env --> EnvType{What parameter?}
EnvType -->|"Air quality"| AirQ{Budget?}
EnvType -->|"Pressure"| BMP280[BMP280 $5]
AirQ -->|"Basic"| MQ135[MQ-135 $5]
AirQ -->|"Quality"| BME680[BME680 $15]
style Start fill:#2C3E50,color:#fff
style DHT11 fill:#16A085,color:#fff
style DHT22 fill:#16A085,color:#fff
style SHT31 fill:#16A085,color:#fff
style PIR fill:#16A085,color:#fff
style Accel fill:#16A085,color:#fff
style Radar fill:#16A085,color:#fff
style ToF fill:#16A085,color:#fff
style Ultrasonic fill:#16A085,color:#fff
style BMP280 fill:#16A085,color:#fff
style MQ135 fill:#16A085,color:#fff
style BME680 fill:#16A085,color:#fff
544 Sensor Selection Guide
Learning Objectives
After completing this chapter, you will be able to:
- Apply a systematic process for sensor selection
- Use selection criteria to narrow down options
- Balance tradeoffs (cost, accuracy, power, complexity)
- Make informed purchasing decisions
544.1 Prerequisites
- Sensor Specifications: Understanding key specs
- Common IoT Sensors: Available options
544.2 How to Choose the Right Sensor: A Step-by-Step Process
544.3 Step 1: Define Requirements
Before looking at sensors, answer these questions:
| Question | Your Answer | Impact on Selection |
|---|---|---|
| What physical quantity? | (temp, pressure, motion…) | Determines sensor category |
| Required accuracy? | (+/-X units) | Filters cheap vs expensive options |
| Required range? | (min to max value) | Must cover all expected conditions |
| Response time needed? | (ms, seconds, minutes) | Fast control vs slow logging |
| Power budget? | (mA, battery life) | Active vs passive, duty cycling |
| Interface preference? | (analog, I2C, SPI, UART) | Hardware/software compatibility |
| Environmental conditions? | (temp, humidity, vibration) | IP rating, industrial-grade |
| Budget per unit? | ($) | Narrows options significantly |
544.4 Step 2: Create a Shortlist
Based on requirements, identify 3-5 candidate sensors:
Example: Temperature Sensor Selection
| Requirement | DHT11 | DHT22 | DS18B20 | BME280 | SHT31 |
|---|---|---|---|---|---|
| Accuracy +/-0.5C | No (+/-2C) | Yes | Yes | Marginal (+/-1C) | Yes (+/-0.3C) |
| Range -20 to 60C | Yes | Yes | Yes | Yes | Yes |
| Humidity reading | Yes | Yes | No | Yes | Yes |
| I2C interface | No | No | No (1-Wire) | Yes | Yes |
| Power <1mA | Yes | Yes | Yes | Yes | Yes |
| Cost <$10 | Yes ($2) | Yes ($5) | Yes ($3) | Yes ($8) | No ($15) |
| PASS | No | Yes | Partial | Yes | No |
Result: DHT22 or BME280 meet requirements. Choose BME280 if pressure is useful, DHT22 if simpler is better.
544.5 Step 3: Verify with Datasheets
For each shortlisted sensor:
- Download official datasheet
- Verify specs match your requirements
- Check interface details (voltage, pull-ups, timing)
- Review application notes
- Check library availability
544.6 Sensor Selection Decision Tree
544.7 Quick Sensor Selector by Application
| Application | Primary Sensor | Alternative | Key Spec |
|---|---|---|---|
| Smart thermostat | DHT22 | BME280 | +/-0.5C accuracy |
| Weather station | BME280 | SHT31 + BMP280 | Pressure for altitude |
| Motion lighting | PIR HC-SR501 | Radar RCWL-0516 | 7m range |
| Parking detection | HC-SR04 | VL53L0X | 2-400cm range |
| Step counting | ADXL345 | MPU6050 | +/-16g range |
| Smoke detection | MQ-2 | MQ-135 | Gas sensitivity |
| Water leak | Conductivity probe | Float switch | Digital output |
| Door/window | Reed switch | Hall sensor | Magnet detection |
544.8 Worked Example: Selecting a Temperature Sensor for Outdoor Deployment
Requirements: - Measure temperature -20C to +50C - Accuracy +/-0.5C - Battery-powered (2 years target) - Read every 5 minutes - Outdoor enclosure (IP65) - Budget: $10 per sensor
Analysis:
| Criterion | DS18B20 | DHT22 | BME280 | Decision |
|---|---|---|---|---|
| Range | -55 to +125C | -40 to +80C | -40 to +85C | All pass |
| Accuracy | +/-0.5C | +/-0.5C | +/-1C | DS18B20, DHT22 |
| Current (active) | 1mA | 1.5mA | 0.3mA | BME280 best |
| Current (sleep) | 1uA | 50uA | 0.1uA | DS18B20, BME280 |
| Interface | 1-Wire | Digital | I2C | All OK |
| Waterproof option | Yes (probe) | No | No | DS18B20 |
| Cost | $3 | $5 | $8 | All within budget |
Battery Life Calculation (DS18B20): - 288 readings/day x 0.75s x 1mA = 0.06mAh active - 23.94 hours x 0.001mA = 0.024mAh sleep - Total: 0.084mAh/day - 2000mAh battery: 23,800 days (65 years theoretical)
Selection: DS18B20 - Best for outdoor due to waterproof probe option, excellent power efficiency, and meets accuracy requirement.
544.9 Budget Optimization Strategies
- Buy in bulk - 10+ units often 30-50% cheaper
- Use modules - Breakout boards include passives, save soldering
- Skip unnecessary features - DHT11 vs DHT22 if +/-2C is acceptable
- Check Chinese sources - AliExpress sensors 3-5x cheaper (longer shipping)
- Open-source designs - Community-validated circuits save development time
544.10 Summary
Key sensor selection takeaways:
- Define requirements first - Then find sensors, not the other way around
- Create a shortlist - Compare 3-5 candidates systematically
- Verify with datasheets - Don’t trust marketing specs alone
- Consider total cost - Includes development time, libraries, support
- Prototype before production - Test in real conditions
544.11 What’s Next
Now that you know how to select sensors:
- To avoid mistakes: Common Mistakes - Top 10 pitfalls
- To go deeper: Advanced Topics - Noise, fusion, optimization
- To test knowledge: Quiz and Exercises - Self-assessment