Learning how to use a temperature sensor with Arduino opens the door to countless electronics projects, from simple weather stations to automated climate control systems. Whether you are a beginner exploring embedded systems or a hobbyist building a smart home device, integrating a temperature sensor with an Arduino board allows you to measure ambient conditions and trigger actions based on real-time data. This guide walks you through the types of sensors available, the wiring process, the code you need, and the science behind temperature measurement, giving you everything required to build your first temperature monitoring project.
What Is a Temperature Sensor and Why Use It with Arduino?
A temperature sensor is an electronic component that detects heat or cold in its environment and converts that physical quantity into an electrical signal. When paired with an Arduino microcontroller, that signal can be read, processed, and displayed on a computer screen, an LCD, or used to control other components like fans, heaters, or LEDs And that's really what it comes down to..
Using a temperature sensor with Arduino is one of the best ways to learn about analog and digital input, sensor calibration, and real-world data acquisition. Because Arduino boards are open-source, affordable, and supported by a massive community, they are ideal for students and makers who want to prototype environmental monitoring devices without investing in expensive industrial equipment.
Common Temperature Sensors Compatible with Arduino
Not all temperature sensors work the same way. Some provide analog voltage output, while others communicate digitally using protocols like One-Wire or I2C. Below are the most popular options for Arduino projects That's the part that actually makes a difference..
LM35 Analog Temperature Sensor
The LM35 is a precision integrated-circuit temperature sensor that outputs an analog voltage proportional to the Celsius temperature. It is inexpensive, easy to wire, and does not require external calibration. For every degree Celsius, the LM35 outputs 10 millivolts, making the math straightforward for beginners.
People argue about this. Here's where I land on it And that's really what it comes down to..
DHT11 and DHT22 Humidity and Temperature Sensors
The DHT11 and its more accurate sibling, the DHT22, measure both temperature and relative humidity. Which means these sensors use a digital signal and require a specific Arduino library to interpret the data. They are excellent for weather stations and indoor climate monitoring projects.
DS18B20 Digital Temperature Sensor
The DS18B20 is a waterproof digital temperature sensor that communicates over a One-Wire interface. It is highly accurate and can be used in harsh environments, such as liquid temperature monitoring. Multiple DS18B20 sensors can share the same data line, each with a unique address Practical, not theoretical..
Components You Will Need
To get started, gather the following parts:
- Arduino Uno or compatible board
- Breadboard and jumper wires
- Temperature sensor (LM35, DHT11, or DS18B20)
- 10k ohm resistor (required as a pull-up for DHT11 and DS18B20)
- USB cable for programming
- Computer with Arduino IDE installed
Step-by-Step Guide: Using an LM35 Temperature Sensor with Arduino
The LM35 is the best starting point for anyone new to Arduino temperature sensing because it requires no special libraries and works with the board’s built-in analog-to-digital converter.
Wiring the Circuit
Connect the LM
Connect the LM35’s VCC pin to the Arduino’s 5V output, its GND pin to ground, and the output (OUT) pin to analog input A0. On a breadboard, place each leg in a separate row and use jumper wires to bridge the connections to the Arduino headers. Once the circuit is assembled, upload the following sketch:
const int sensorPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int rawValue = analogRead(sensorPin);
// Convert ADC reading to voltage (0–5 V)
float voltage = rawValue * (5.0 / 1023.Plus, 0);
// LM35 outputs 10 mV per °C, so multiply by 100
float temperatureC = voltage * 100. 0;
Serial.Consider this: print("Temperature: ");
Serial. print(temperatureC);
Serial.
After uploading, open the Serial Monitor (Tools > Serial Monitor) and set the baud rate to 9600. You should see temperature readings update every second. If the values seem off, check your wiring and ensure the sensor is not touching metal surfaces that could conduct external heat or cold.
### Working with Digital Sensors
If you prefer the DHT11 or DHT22, connect VCC to 5V, GND to ground, and the data pin to a digital input such as D2, placing a 10k ohm pull-up resistor
between the data pin and VCC. You will also need to install the **DHT sensor library** by Adafruit (and its dependency, the Adafruit Unified Sensor library) via the Library Manager (Sketch > Include Library > Manage Libraries). Once installed, use this sketch:
```cpp
#include
#define DHTPIN 2
#define DHTTYPE DHT11 // Change to DHT22 if using that model
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000); // DHT sensors require at least 1-2 seconds between reads
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature();
if (isnan(humidity) || isnan(temperatureC)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.And print("Humidity: ");
Serial. print(humidity);
Serial.Consider this: print(" %\t");
Serial. print("Temperature: ");
Serial.print(temperatureC);
Serial.
For the **DS18B20**, wire VDD to 5V (or 3.3V), GND to ground, and the DQ pin to a digital pin (e.g.And , D2) with a 4. 7k ohm pull-up resistor to VCC. Install the **OneWire** and **DallasTemperature** libraries via the Library Manager.
```cpp
#include
#include
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
}
void loop() {
sensors.Because of that, requestTemperatures();
int deviceCount = sensors. getDeviceCount();
for (int i = 0; i < deviceCount; i++) {
float tempC = sensors.getTempCByIndex(i);
Serial.print("Sensor ");
Serial.print(i);
Serial.print(": ");
Serial.print(tempC);
Serial.println(" °C");
}
Serial.
## Troubleshooting Common Issues
* **Erratic LM35 readings:** Ensure your power supply is stable. USB power can be noisy; adding a 0.1 µF ceramic capacitor between the LM35’s VCC and GND pins often smooths the output.
* **DHT "NaN" errors:** This almost always indicates a wiring issue, a missing pull-up resistor, or attempting to read too quickly. Verify the resistor is connected between Data and VCC, not Data and GND.
* **DS18B20 not found:** Check the pull-up resistor value (4.7k is standard) and ensure the data line isn't too long for parasitic power mode. If using "parasite power" (connecting VDD to GND), the library requires `sensors.setWaitForConversion(true)`.
## Conclusion
You now have the foundational knowledge to integrate temperature sensing into your Arduino projects, whether you chose the simplicity of the analog LM35, the dual humidity data of the DHT series, or the solid, addressable precision of the DS18B20. As you grow comfortable with these basics, consider exploring data logging to an SD card, transmitting readings via Bluetooth or Wi-Fi (ESP32/ESP8266), or designing a custom PCB to make your prototype permanent. Because of that, each sensor offers a distinct balance of cost, complexity, and capability, making one of them the right fit for almost any beginner application—from a basic room thermostat to a multi-zone hydroponic monitoring system. The world of environmental sensing is wide open; your first reading is just the beginning.