Skip to content
Home » Embedded Systems » Complete Guide to Sensors for Embedded Systems

Complete Guide to Sensors for Embedded Systems

Embedded Systems Learning Path
Part 110 of 129View Full Path →

KEY TAKEAWAYS

  • Sensors convert physical phenomena (temperature, pressure, light, motion) into electrical signals that microcontrollers can read.
  • Choosing the right sensor requires evaluating accuracy, range, response time, power consumption, output type, and environmental conditions.
  • Analog sensors output variable voltage/current and need ADC conversion; digital sensors communicate via protocols like I2C, SPI, or 1-Wire.
  • Signal conditioning (amplification, filtering, linearization) is essential for reliable sensor readings in production systems.

Sensors are the eyes and ears of every embedded system. Without sensors, a microcontroller has no way to perceive the physical world — it cannot measure temperature, detect motion, gauge pressure, or sense light. This guide covers everything you need to know about sensors in embedded systems: how they work, how to choose them, how to interface them with microcontrollers, and how to get reliable readings in real-world conditions.

What Is a Sensor?

A sensor is a device that detects changes in a physical quantity — temperature, pressure, humidity, light, distance, acceleration — and converts it into an electrical signal. This electrical signal (voltage, current, resistance change, or digital data) is then read by a microcontroller for processing and decision-making.

Every sensor has a transducer element that physically reacts to the measured quantity. For example, a thermistor changes its resistance with temperature, a photodiode generates current proportional to light intensity, and a piezoelectric element produces voltage when subjected to pressure or vibration.

Sensors can be classified by their output type (analog vs digital), their power source (active vs passive), and the physical quantity they measure (thermal, optical, mechanical, chemical, magnetic).

Analog vs Digital Sensors

Analog sensors output a continuously varying voltage or current proportional to the measured quantity. Examples include LM35 (temperature), LDR (light), and potentiometers (position). The microcontroller reads these using an ADC (Analog-to-Digital Converter), which samples the voltage and converts it to a numerical value.

The resolution of an analog measurement depends on the ADC bit depth. A 10-bit ADC divides the reference voltage into 1024 levels, while a 12-bit ADC provides 4096 levels. For a 3.3V reference with a 12-bit ADC, each level represents about 0.8mV — sufficient for most temperature and pressure applications.

Digital sensors, on the other hand, have built-in ADCs and processing circuitry. They output data as digital values over a communication protocol — I2C, SPI, 1-Wire, or UART. Examples include DHT22 (temperature/humidity), BMP280 (pressure), and MPU6050 (accelerometer/gyroscope). Digital sensors are easier to interface (no ADC calibration needed) and less susceptible to noise, but they are typically more expensive and consume more power.

  • Analog sensors: simpler, cheaper, require ADC, susceptible to noise over long wires
  • Digital sensors: built-in processing, noise-resistant, use serial protocols, higher cost
  • Choosing between them depends on required accuracy, distance from MCU, power budget, and available MCU peripherals

How to Choose the Right Sensor

Selecting a sensor is one of the most critical design decisions in an embedded system. A poor choice leads to inaccurate readings, excessive power consumption, or an unreliable product. Here are the key factors to evaluate:

Measurement Range: The sensor must cover the full range of values your application needs to measure. A temperature sensor rated for -40°C to +85°C is useless if your application operates up to 150°C.

Accuracy and Resolution: Accuracy is how close the reading is to the true value. Resolution is the smallest change the sensor can detect. A ±0.5°C accuracy sensor with 0.1°C resolution is suitable for HVAC; a ±2°C sensor is not.

Response Time: How quickly the sensor reacts to changes. Fast-changing measurements (vibration, motor RPM) need sensors with millisecond response times. Slow measurements (room temperature) can use sensors with second-level response.

Output Type: Analog (voltage/current) or digital (I2C/SPI/UART). Match to your MCU capabilities. If you have limited ADC channels, prefer digital sensors.

Power Consumption: Critical for battery-powered devices. Some sensors draw microamps in sleep mode and milliamps during measurement. Check both active and standby current.

Environmental Conditions: Operating temperature range, humidity tolerance, vibration resistance, IP rating. Industrial environments need ruggedized sensors; consumer electronics can use standard packages.

Cost and Availability: For prototyping, cost matters less. For production volumes, a $0.50 sensor vs a $5.00 sensor is a 10x difference in BOM cost.

Temperature Sensors Compared

Temperature measurement is the most common sensing application in embedded systems. There are four main types:

Thermistors (NTC/PTC): Resistance changes with temperature. NTC resistance decreases as temperature increases. Cheap ($0.10-$1), fast response, but nonlinear — requires a lookup table or Steinhart-Hart equation for conversion. Range typically -55°C to +150°C. Use for simple temperature monitoring, overcurrent protection, battery charging.

RTDs (Resistance Temperature Detectors): Platinum wire whose resistance increases linearly with temperature. Very accurate (±0.1°C), stable over time, but expensive ($5-$50) and require excitation current and a Wheatstone bridge circuit. Range -200°C to +850°C. Use for industrial process control, laboratory equipment.

Thermocouples: Two different metal wires joined at a junction produce a voltage proportional to temperature. Widest range (-270°C to +1800°C), rugged, but low output voltage (microvolts per degree) requiring amplification and cold junction compensation. Use for furnace monitoring, exhaust gas measurement, extreme environments.

IC Temperature Sensors: Integrated circuits like LM35 (analog, 10mV/°C), TMP36, or DS18B20 (digital, 1-Wire). Easy to use, accurate (±0.5°C), moderate cost ($1-$3), but limited range (-55°C to +150°C). Use for consumer electronics, environmental monitoring, HVAC.

Pressure Sensors

Pressure sensors measure force per unit area and are used in weather stations, altimeters, tire pressure monitoring, industrial process control, and medical devices.

MEMS Piezoresistive Sensors: A silicon diaphragm with piezoresistive elements changes resistance under pressure. The BMP280 and BME280 are popular I2C/SPI sensors combining pressure, temperature, and humidity. They measure 300-1100 hPa with ±1 hPa accuracy — sufficient for altitude estimation (±1 meter).

Capacitive Pressure Sensors: A flexible diaphragm changes capacitance as it deflects under pressure. Higher accuracy than piezoresistive for low-pressure ranges. Used in medical ventilators and precision instruments.

Strain Gauge Pressure Sensors: Metal foil strain gauges bonded to a diaphragm. Very linear, used in load cells and industrial pressure transmitters. Require bridge excitation circuits and instrumentation amplifiers.

For most embedded projects, MEMS sensors like BMP280 ($2-$5) are the best choice — they integrate ADC, temperature compensation, and I2C communication in a tiny package.

Motion and Proximity Sensors

Motion sensing is used in robotics, drones, fitness trackers, game controllers, and security systems.

Accelerometers: Measure linear acceleration along one or more axes. MEMS accelerometers (ADXL345, MPU6050) detect tilt, vibration, free-fall, and activity. Range ±2g to ±16g, with 10-bit to 16-bit resolution. The MPU6050 combines a 3-axis accelerometer and 3-axis gyroscope in one chip.

Gyroscopes: Measure angular velocity (rotation rate). Used for orientation tracking, image stabilization, and navigation. Combined with accelerometers in IMUs (Inertial Measurement Units).

Ultrasonic Sensors: HC-SR04 measures distance by sending ultrasonic pulses and timing the echo. Range 2cm to 400cm, ±3mm accuracy. Simple trigger/echo interface. Used for obstacle avoidance, parking sensors, and liquid level measurement.

PIR (Passive Infrared) Sensors: Detect infrared radiation from warm bodies (humans, animals). Used in motion-activated lights and security systems. Binary output (motion detected or not). Low power, wide detection angle (110°), range up to 7 meters.

IR Proximity Sensors: Emit infrared light and measure reflection. Used for object detection, line following robots, and touchless switches.

Sensor Signal Conditioning

Raw sensor output is rarely suitable for direct ADC input. Signal conditioning prepares the sensor signal for accurate measurement.

Amplification: Many sensors produce millivolt-level signals (thermocouples, strain gauges). An instrumentation amplifier boosts the signal to fill the ADC input range. For example, a thermocouple producing 0-40mV can be amplified 100x to 0-4V for a 5V ADC.

Filtering: Noise from power supplies, motor EMI, and radio interference corrupts sensor readings. A low-pass RC filter (hardware) or moving average filter (software) removes high-frequency noise. For 50/60Hz mains interference, a notch filter is effective.

Linearization: NTC thermistors and some pressure sensors have nonlinear transfer functions. Linearization converts the raw reading to the actual physical value using lookup tables, polynomial equations, or the Steinhart-Hart equation (for NTC thermistors).

Level Shifting: When a 5V sensor connects to a 3.3V microcontroller, a voltage divider or level shifter prevents damage. Conversely, some sensors need pull-up resistors for open-drain outputs (I2C).

Oversampling and Averaging: Reading the ADC multiple times and averaging reduces quantization noise. Oversampling by 4x effectively adds 1 bit of resolution. A 10-bit ADC with 16x oversampling achieves near 12-bit performance.

Sensor Calibration

Even the best sensor needs calibration to achieve its specified accuracy. Calibration maps raw sensor readings to known reference values.

Single-Point Calibration: Measure one known reference point and apply an offset. For temperature: if the sensor reads 22.3°C when the reference thermometer shows 22.0°C, apply a -0.3°C offset. Simple but only accurate near the calibration point.

Two-Point Calibration: Measure two known reference points (e.g., ice water at 0°C and boiling water at 100°C) and calculate slope and offset. This corrects both gain error and offset error, providing good accuracy across the full range.

Multi-Point Calibration: Measure multiple reference points and fit a polynomial curve. Required for highly nonlinear sensors. Store calibration coefficients in EEPROM so they persist across power cycles.

Factory vs Field Calibration: Factory calibration uses precision references and is done once during manufacturing. Field calibration allows the end user to recalibrate against local conditions. Many digital sensors (BME280, SHT31) come factory-calibrated with compensation coefficients stored in internal memory.

Noise and Error Sources in Sensor Measurements

Understanding noise sources helps you design circuits and software that produce reliable measurements.

Thermal Noise (Johnson-Nyquist): Random voltage fluctuations in resistors caused by electron movement. Proportional to temperature and bandwidth. Cannot be eliminated but can be reduced by filtering and averaging.

Electromagnetic Interference (EMI): Nearby motors, switching power supplies, and wireless transmitters inject noise into sensor wires. Mitigation: twisted pair wiring, shielding, keeping sensor wires short, using differential signaling.

Quantization Error: ADC resolution limits the smallest measurable change. A 10-bit ADC with 3.3V reference has 3.2mV per step. If the sensor produces a 1mV change per degree, you cannot measure individual degrees. Solution: use a higher-resolution ADC or amplify the signal.

Self-Heating: Current flowing through a sensor generates heat, causing the sensor to read its own temperature rather than the environment. RTDs and thermistors are susceptible. Mitigation: minimize excitation current, use pulsed measurement.

Drift: Sensor readings change over time due to aging, contamination, or mechanical stress. Periodic recalibration is necessary for precision applications.

Interfacing Sensors with Microcontrollers

The interface between sensor and microcontroller depends on the sensor output type.

Analog Interface (ADC): Connect sensor output to an ADC pin. Configure reference voltage, sample rate, and resolution. Read the value, apply calibration, and convert to engineering units. Use decoupling capacitors (100nF) close to the sensor power pins.

I2C Interface: Two-wire bus (SDA + SCL) with pull-up resistors. Multiple sensors share the same bus using different addresses. Typical speed 100kHz (standard) or 400kHz (fast mode). Libraries handle the protocol — you read registers.

SPI Interface: Four-wire bus (MOSI, MISO, SCK, CS). Faster than I2C (up to 10MHz), full-duplex, but requires one chip-select pin per sensor. Preferred for high-speed sensors (accelerometers, ADC chips).

1-Wire Interface: Single data wire plus ground. Used by DS18B20 temperature sensors. Multiple sensors on one pin using unique 64-bit addresses. Slow but requires minimal wiring.

PWM/Frequency Output: Some sensors output a PWM signal or frequency proportional to the measured value. Use timer capture to measure pulse width or frequency. DHT11/DHT22 use a custom single-wire timing protocol.

For reliable operation: always add bypass capacitors, keep analog wires away from digital/power traces, use proper grounding, and handle sensor errors gracefully in software (timeout, range check, retry).

Common Sensor Projects to Build

The best way to learn sensor interfacing is by building real projects:

  • Weather Station: BME280 (temperature, humidity, pressure) + rain gauge + wind speed sensor. Display on LCD or send to cloud via WiFi.
  • Obstacle-Avoiding Robot: HC-SR04 ultrasonic sensors mounted at multiple angles. Firmware reads distances and steers motors to avoid collisions.
  • Home Security System: PIR motion sensors + reed switches on doors + buzzer/SMS alert via ESP8266.
  • Temperature Logger: LM35 or DS18B20 + SD card module. Log temperature every minute for days or weeks.
  • Smart Agriculture: Soil moisture sensor + DHT22 (air temp/humidity) + relay to control water pump. Automate irrigation.
  • Air Quality Monitor: MQ-135 gas sensor + PM2.5 particle sensor. Display on OLED, alert when levels are unhealthy.

Each project teaches different aspects: analog vs digital interfacing, signal conditioning, data logging, wireless communication, and real-time decision making.

Articles in This Sensors Series

Explore each topic in depth with these dedicated guides:

Worked Example: Choosing a Temperature Sensor for an Automotive Engine Bay

Let us walk through a real sensor selection decision step by step. The requirement: measure coolant temperature in an automotive engine bay, displayed on a dashboard gauge, with data logged to an ECU.

Step 1: Define the Requirements

  • Temperature range: Engine coolant runs from -40°C (cold start in winter) to +150°C (extreme conditions). The sensor must cover this full range.
  • Accuracy: ±2°C is sufficient for a dashboard gauge. ±1°C if feeding a closed-loop cooling system.
  • Response time: Coolant temperature changes slowly (seconds to minutes), so response time is not critical.
  • Environment: Engine bay — vibration, thermal cycling, exposure to oil and coolant fluids. The sensor must be mechanically rugged and chemically resistant.
  • Interface: Analog output preferred for simplicity. The ECU has a 12-bit ADC available.
  • Cost: This is a production vehicle, so cost matters. Target under $5 per unit at volume.

Step 2: Evaluate the Candidates

Option A — NTC Thermistor: Range -40°C to +150°C (with correct type). Cost: $0.50–$2. Non-linear response requires a lookup table or Steinhart-Hart equation in firmware. Very rugged — no moving parts, available in sealed probe housings. Fast response. Verdict: Strong candidate.

Option B — RTD (PT100): Range -200°C to +600°C. Cost: $5–$15. Linear response, high accuracy (±0.1°C possible). Requires a Wheatstone bridge and instrumentation amplifier — adds circuit complexity and cost. Fragile element needs protection in vibration environments. Verdict: Over-specified for ±2°C accuracy. Too expensive for production vehicle.

Option C — K-Type Thermocouple: Range -200°C to +1350°C. Cost: $2–$5. Extremely rugged. But requires cold-junction compensation circuit, amplifier (e.g., MAX31855), and produces only ~41 µV/°C — susceptible to electrical noise in an engine bay. Verdict: Overkill for +150°C max. Added complexity with no benefit.

Option D — Digital sensor (DS18B20): Range -55°C to +125°C. Verdict: Eliminated — does not reach +150°C.

Step 3: Decision

The NTC thermistor in a sealed stainless-steel probe wins on every criterion: it covers the temperature range, costs under $2, survives the harsh environment, and interfaces directly to the ADC with just a voltage divider. The non-linear response is handled with a simple lookup table in the ECU firmware — a solved problem with many reference implementations available.

This is how sensor selection works in practice: you do not pick the “best” sensor in the abstract. You define your constraints, eliminate candidates that fail any hard requirement, and then choose the simplest and cheapest option that meets all of them.

📖 Related: LM35 Temperature Sensor: Working, Circuit, and Arduino CodeDHT11 and DHT22 Sensor: Working Principle and Interfacing Guide

Going further: For the analog interface side — how the MCU actually reads sensor voltages — see ADC in Microcontrollers.

Going further: And for software cleanup of noisy readings, see Filtering Noisy ADC Readings.

Going further: For force sensing in particular, see our FlexiForce calibration deep-dive for the rubber-pad mounting trick and full polynomial fit.

Leave a Reply

Your email address will not be published. Required fields are marked *