Components · 3 min read

Arduino Sensors Guide: The 12 Most Used Sensors

The most used sensors with Arduino: DHT11, DHT22, HC-SR04, LDR, PIR, MQ-2, NTC, flame, soil moisture, RFID and more. What they measure, how to wire them and what to watch out for.

Sensors are the parts that let an Arduino sense the outside world. A sensor turns a physical quantity it measures (temperature, distance, light, gas) into a signal the Arduino can read. In this guide you'll find the most used sensors, what they do and what to watch out for when wiring them.

DHT11
DHT11
HC-SR04
HC-SR04
LDR
LDR

Sensor output types: analog, digital and bus-based

  • Analog sensors (LDR, potentiometer, NTC, MQ gas) give their value as a voltage, read with analogRead as 0–1023.
  • Digital sensors (PIR, flame, reed switch) only report yes/no, read with digitalRead as HIGH/LOW.
  • Bus-based sensors (DHT22, BMP280, RC522) send data over I2C, SPI or their own protocol; they usually need a library.

Temperature and humidity sensors

DHT11
DHT11
DHT22
DHT22
DS18B20
DS18B20
BME280
BME280
NTC thermistor
NTC thermistor
SensorMeasuresAccuracyNote
DHT11Temperature + humidity±2 °C, ±5%Cheap, 1 reading per second
DHT22Temperature + humidity±0.5 °C, ±2–5%More accurate, wider range
NTC thermistorTemperatureDepends on calibrationAnalog, very cheap
DS18B20Temperature±0.5 °CWaterproof version available, single wire
BME280Temperature + humidity + pressure±1 °C, ±3%I2C, ideal for a weather station
Don't try to read DHT sensors more than once a second; you'll get wrong or empty (nan) values. Wait at least 2 seconds between readings.

Distance sensor: HC-SR04

The HC-SR04 sends out a sound wave and measures how long the echo takes to come back; it can measure roughly 2–400 cm. It's the basis of parking sensors, obstacle-avoiding robots and level gauges. It runs on 5 V; with an ESP32 or Pico, put a voltage divider on the ECHO pin.

Light sensor: LDR

An LDR (photoresistor) is a part whose resistance drops in the light. It's read from an analog pin by building a voltage divider with a 10 kΩ resistor. It's used in night lights, automatic blinds and laser alarm projects. For precise light measurement (lux), I2C sensors like the BH1750 are preferred.

Motion sensor: PIR (HC-SR501)

A PIR sensor detects changes in the heat given off by the human body and sets its output HIGH when it sees motion. Its two potentiometers adjust the sensitivity (3–7 m) and how long the output stays on. After power-up it needs about a minute to warm up.

PIR motion sensor

Gas and flame sensors

MQ-2
MQ-2
MQ-135
MQ-135
Flame sensor
Flame sensor
SensorDetects
MQ-2Smoke, LPG, methane, hydrogen
MQ-4Methane (natural gas)
MQ-7Carbon monoxide
MQ-135Air quality (ammonia, CO2-like gases)
Flame sensorThe infrared light of a flame
MQ sensors and flame sensors are for learning and experiments. For home safety, use certified smoke, gas and carbon monoxide detectors.

Other commonly used sensors

Soil moisture sensor
Soil moisture sensor
Reed switch
Reed switch
RC522 RFID
RC522 RFID
IR receiver
IR receiver
Joystick
Joystick
KY-038 sound sensor
KY-038 sound sensor
  • Soil moisture sensor: for automatic watering projects. Capacitive models don't corrode, so they last longer.
  • Reed switch: closes when a magnet comes near; used in door and window sensors.
  • RC522 RFID: reads the IDs of cards and key fobs; used in door locks and attendance systems. It must be powered from 3.3 V.
  • IR receiver (VS1838B/TSOP): reads the signals of TV remotes.
  • Joystick: a two-axis analog controller used in robot and game projects.
  • Sound sensor: detects sound level for projects like turning on a lamp with a clap.

What to look for when choosing a sensor

  1. Operating voltage: does the sensor need 5 V or 3.3 V? Is it compatible with your board's logic level?
  2. Output type: analog, digital or I2C/SPI? Does your board have enough suitable pins?
  3. Accuracy and range: is the value you want to measure within the sensor's range?
  4. Library support: is there an up-to-date, widely used library for the Arduino IDE?
  5. Environment: do you need a model that withstands humidity, water, dust or high temperatures?

Making sensor readings stable

Small fluctuations are normal with analog sensors. Taking the average or median of several readings, using hysteresis for thresholds (two separate thresholds for on and off) and updating the display only a few times per second make readings look much more stable. In battery-powered sensor projects, lengthening the measurement interval noticeably extends battery life; you can estimate it with the battery life calculator.

Frequently asked questions

What's the best temperature sensor for Arduino?

The DHT11 is enough to start. For more accurate measurements choose the DHT22 or DS18B20, and the BME280 if you also want to measure pressure.

How many sensors can I connect to one Arduino?

It depends on the pin count and sensor type. I2C sensors can share the same two wires, so dozens can be connected; for analog sensors the Uno has 6 analog inputs and the Mega 16.

Why do my sensor values keep changing?

Noise, long wires and supply fluctuations cause it. Average several readings, keep wires short and add a 100 nF capacitor to the sensor's supply.

Can I connect a 5 V sensor to an ESP32?

The sensor can be powered from 5 V, but its output signal must be brought down to 3.3 V before it reaches the ESP32. Use a voltage divider or a level shifter; some sensors also come in 3.3 V-compatible versions.

How do I convert an analog sensor value to real units?

First convert the reading to a voltage (value × 5 / 1023), then use the formula from the sensor's datasheet to turn it into a real unit such as temperature, light or gas concentration. Some sensors need calibration.

See all projects
Temperature and Humidity with DHT11
AR-55Intermediate

Temperature and Humidity with DHT11

How warm is your room, and is the air humid or dry? The DHT11 sensor measures temperature and humidity, and the Arduino writes the values on a two-line LCD screen, refreshing every couple of seconds.

4.7(47)
96
Parking Sensor with HC-SR04
AR-28Intermediate
Premium

Parking Sensor with HC-SR04

A mini version of a car's parking sensor: the closer something gets, the faster the beeps.

4.8(65)
87
Night Light with Ldr
AR-12Beginner

Night Light with Ldr

A little night light that turns on by itself when it gets dark and goes off when morning comes.

4.7(107)
248
Motion Detector with Motion Sensor
AR-24Beginner
Premium

Motion Detector with Motion Sensor

A simple guard that tells you when someone walks into the room. The motion sensor picks up the warmth given off by the human body, and the Arduino keeps the LED on as long as there is movement and…

4.6(48)
69
Using a Gas Sensor
AR-51Beginner
Premium

Using a Gas Sensor

A little guard that notices a gas leak in the kitchen before you do. The gas sensor keeps sniffing the air; while everything is fine the green LED stays on, and when the gas in the air passes a…

4.6(37)
50
Using a Flame Sensor
AR-50Intermediate
Premium

Using a Flame Sensor

A little guard that spots fire before you do, in the kitchen or the workshop. The flame sensor picks up the invisible light that fire gives off; while all is well the green LED is on, and when it…

4.6(33)
45
Smart Irrigation Station
AR-83Advanced
Premium

Smart Irrigation Station

A gardener that waters your plants on its own, so they don't dry out while you're on vacation.

5.0(42)
57
RFID Value Reading
AR-53Beginner
Premium

RFID Value Reading

Your building key fob or access card hides a secret ID number, and this project reads it. Hold the card near the RFID reader and the Arduino writes the card's number to your computer screen.

4.7(47)
61