Sensors convert physical quantities into electrical signals. Temperature, pressure, light, motion, humidity, distance, acceleration — if you can measure it, there's a sensor for it. The output is usually a voltage, current, resistance change, frequency, or digital protocol, which a microcontroller reads via ADC or a serial bus. Knowing what kind of output a sensor produces determines how to interface it, and knowing what accuracy and response speed you need narrows down which sensor family to use.
Sensor Output Types
Output type
Interface method
Examples
Notes
Analog voltage
ADC pin
LM35, TMP36, MQ-series gas sensors
Match sensor output range to ADC reference (0–3.3V, 0–5V)
Resistance change
Voltage divider + ADC
NTC thermistor, LDR, strain gauge, FSR
Choose divider resistor ≈ sensor mid-range value for best sensitivity
Current (4–20mA)
Shunt resistor + ADC or current receiver IC
Industrial pressure transducers, flow meters
4mA = zero, 20mA = full scale; loop powered; immune to voltage drop over long cable
Frequency / PWM
Timer input capture or interrupt
Flow sensors, tachometers, DHT22 (RH)
Count edges or measure period with MCU timer
I2C digital
SDA/SCL with 4.7kΩ pull-ups
DS18B20, BMP280, BME280, MPU-6050
Multi-device on one bus; address must be unique per device
SPI digital
MOSI, MISO, SCK, CS
MAX31855, ADXL345, MS5611
Faster than I2C, one CS line per device
1-Wire
Single data pin + 4.7kΩ pull-up to VCC
DS18B20, DS2401
Up to 127 devices on one wire; parasite power mode possible
UART serial
RX/TX at specific baud rate
GPS modules, LoRa modules, PM2.5 sensors
Fixed baud rate in datasheet; often 9600 or 115200
Temperature Sensors
Type
Range
Accuracy
Interface
Notes
NTC Thermistor
−50 to 150°C
±1–3°C
Voltage divider + ADC
Non-linear — needs Steinhart-Hart or lookup table. Very sensitive near nominal temp.
LM35 / TMP36
−40 to 150°C
±1°C
Analog voltage (10mV/°C)
Linear, calibrated, directly readable by ADC. Easy. Lower accuracy than digital.
DS18B20
−55 to 125°C
±0.5°C
1-Wire digital
The default choice for most hobbyist/maker work. Cheap, accurate, parasitic power mode.
BME280
−40 to 85°C
±1°C
I2C / SPI
Also measures humidity (±3%) and pressure (±1 hPa). One IC for three parameters.
Type K thermocouple + MAX31855
−200 to 1350°C
±2°C
SPI (via MAX31855)
For high temperatures that silicon sensors can't handle. Cold junction compensation in the IC.
Pt100 / Pt1000 RTD
−200 to 600°C
±0.1°C
Wheatstone bridge + ADC
Platinum resistance thermometers — highest accuracy, used in industrial/laboratory work
Thermistor Voltage Divider
Thermistor voltage divider: a fixed resistor and NTC thermistor create a temperature-dependent V_out for the ADC.
V_out = VCC × NTC_resistance / (R_fixed + NTC_resistance)
Best R_fixed = NTC value at your target/midpoint temperature
(maximises sensitivity at that temperature)
At 25°C with 10kΩ NTC: use R_fixed = 10kΩ
ADC reading → calculate NTC resistance → Steinhart-Hart → temperature
Light and Optical Sensors
Type
What it measures
Speed
Interface
Notes
LDR (photoresistor)
Light level (rough)
Slow (10–100ms)
Voltage divider + ADC
Non-linear, imprecise. Only use for light/dark detection — not measurement.
Photodiode
Light intensity (broad)
Fast (ns–µs)
Transimpedance amp + ADC
Low dark current, fast response. Needs op-amp to convert current to voltage.
Phototransistor
Light level
Moderate (µs)
Collector resistor + ADC
More sensitive than photodiode but slower. Used in optocouplers.
TSL2561 / BH1750
Lux (calibrated)
Moderate
I2C
Digital output in lux. Temperature-compensated. Use these when you need real light level.
VEML7700
Lux, white light
Moderate
I2C
16-bit, auto-gain, very low light capable. Better dynamic range than TSL2561.
TCS3200 / TCS34725
RGB colour
Moderate
Frequency / I2C
RGB + Clear channels. Used in colour sorting, white balance.
Motion and Position Sensors
Sensor
Measures
Interface
Notes
ADXL345
3-axis acceleration ±2–16g
I2C / SPI
Mature, well-documented, good for tilt sensing and vibration
MPU-6050
3-axis accel + 3-axis gyro
I2C
6-DOF IMU with internal DMP for sensor fusion. Ubiquitous in drone/flight controllers.
ICM-42688-P
6-DOF IMU (high performance)
SPI / I2C
Lower noise than MPU-6050, InvenSense successor
HC-SR501 PIR
Infrared motion (passive)
Digital HIGH/LOW
Detects warm moving objects. Adjustable sensitivity and hold time. Very common in security/alarm.
HC-SR04
Distance (ultrasonic)
Trigger/Echo pulses
2–400cm, ±3mm. Sound-based, affected by soft/angled surfaces. Simple to use.
VL53L0X / VL53L1X
Distance (laser ToF)
I2C
Time-of-flight laser, 2–200cm. Works on all surfaces including glass. Better than HC-SR04 for robotics.
AS5600
Absolute magnetic angle
I2C / Analog
12-bit, 0–360°, contactless (Hall effect over magnet). Motor shaft angle sensing.
HC-SR04 Distance Calculation
Trigger: send 10µs HIGH pulse on TRIG pin
Echo: measure duration of HIGH pulse on ECHO pin
Distance (cm) = pulse_duration_µs / 58
Distance (mm) = pulse_duration_µs × 0.1724
Or: Distance = (pulse_duration × speed_of_sound) / 2
= (pulse_µs × 0.000343m/µs) / 2
Maximum range: ~400cm (echo too weak beyond this)
Minimum range: ~2cm (pulse and echo overlap below this)
Beam angle: ~15–30° cone — surfaces must face sensor squarely
Environmental Sensors
Sensor
Measures
Range
Interface
Notes
BME280
Pressure, humidity, temperature
300–1100 hPa, 0–100%RH, −40–85°C
I2C / SPI
The default all-in-one environmental sensor. Well-supported.
BMP390
Pressure, temperature
300–1250 hPa
I2C / SPI
Higher accuracy and lower noise than BME280 for altitude sensing
SHT31 / SHT40
Humidity + temperature
0–100%RH, −40–125°C
I2C
Better RH accuracy (±2%) than BME280 (±3%). Sensirion Swiss quality.
CCS811 / SGP30
eCO2, TVOC
ppm range
I2C
MOX gas sensors — need warm-up time, affected by humidity. For air quality indication.
SCD40 / SCD41
CO2 (true), humidity, temperature
0–40,000 ppm CO2
I2C
Photoacoustic CO2 measurement — true CO2, not eCO2 estimate. Sensirion.
MQ-2 / MQ-7 / MQ-135
Various gases (flammable, CO, air quality)
ppm range
Analog voltage
Cheap but require significant calibration. Output varies with temperature, humidity, and warm-up.
Analog Sensor Conditioning
Problem: sensor output is 0–100mV, MCU ADC is 0–3.3V
Solution: non-inverting op-amp amplifier
V_out = V_sensor × (1 + R_f/R_g)
Gain = 3.3/0.1 = 33 → R_f/R_g = 32 → use R_g=1kΩ, R_f=33kΩ
Problem: sensor has 4–20mA current output
Solution: shunt resistor (150Ω gives 0.6–3V) + optional op-amp buffer
At 4mA: V = 0.004 × 150 = 0.6V (represents zero)
At 20mA: V = 0.020 × 150 = 3.0V (represents full scale)
Map 0.6–3.0V → 0–100% in MCU code
References
Horowitz & Hill — The Art of Electronics, 3rd ed. Chapters 15 (measurements)
Monk — Programming Arduino: Getting Started with Sketches