Temperature sensor
A temperature sensor turns heat into an electrical signal: a resistance, a voltage or a digital number. The LM35, a common analog one, gives 10 mV for every degree Celsius, so 250 mV means 25 °C.
T = Vout ÷ 10 mV
where T is in °C and Vout in millivolts, so 250 mV means 25 °C.
Others include thermistors, thermocouples, the digital DS18B20 and the DHT11, a humidity sensor that reports temperature too.
What is a temperature sensor?
A temperature sensor is a part whose resistance, voltage or digital output changes with temperature, so a circuit can measure heat and act on it.
They are in thermostats, ovens, fridges, phones, cars and 3D printers. Each kind suits a different range and accuracy, from a thermocouple in a kiln to a DHT11 in a bedroom, as Figure 1 compares.
LM35, −55 °C to 150 °C: a chip whose output rises 10 mV per degree; reads straight into an analog pin.
How does a temperature sensor work?
A temperature sensor works by an effect that changes with heat: thermistors and RTDs change resistance, thermocouples make a voltage, and IC sensors use a transistor junction’s voltage, which falls about 2 mV per degree.
A resistance sensor goes in a voltage divider or a Wheatstone bridge to turn its change into a voltage. A thermocouple’s two metals make only microvolts per degree, so it needs an amplifier chip that also corrects for the temperature of its cold end. IC sensors build that circuitry in, giving a clean voltage or a number.
How does an LM35 temperature sensor work?
The LM35 is a three-pin chip whose output rises 10 mV for every degree Celsius, from 0 mV at 0 °C, so its output in millivolts divided by ten is the temperature.
Power it from 4 to 30 V and read the middle pin with an analog input. On a single supply it reads from about 2 °C upward; the similar TMP36 adds a 500 mV offset so it reads down to −40 °C. Figure 2 compares the two.
LM35 at 25 °C: Vout = 10 mV × 25 = 250 mV, so the reading in millivolts, divided by ten, is the temperature.
What is a DS18B20 temperature sensor?
The DS18B20 is a digital temperature sensor that sends its reading as a number over a single data wire, accurate to ±0.5 °C from −10 to 85 °C.
It uses the 1-Wire bus: each sensor has its own 64-bit address, so many can share one pin, with a 4.7 kΩ pull-up resistor on the data line. Its resolution can be set from 9 to 12 bits, trading finer steps for slower readings. Waterproof probe versions suit liquids and outdoors.
What is a humidity sensor?
A humidity sensor measures how much water vapor the air holds, usually as relative humidity: the share of the most it could hold at its temperature.
Most use a thin polymer film between two electrodes that absorbs water, changing its capacitance. The DHT22 pairs one with a thermistor and a chip, reporting both over one wire; the cheaper DHT11 uses a film whose resistance changes instead. Warm air can hold more water, so the same air’s relative humidity falls as it warms, as Figure 3 shows; that is why these sensors measure temperature too.
20 °C: the same water, but warmer air could hold 1.9 times as much, so the relative humidity is 53%.
Which temperature sensor should you use?
The temperature sensor to use depends on range, accuracy and how you read it: a DS18B20 for accurate digital readings, an LM35 or TMP36 for an analog pin, and a thermistor for the cheapest fast response.
Use a thermocouple and amplifier above about 150 °C, an RTD where precision matters most, and a DHT22 or similar when you need humidity as well. Mount any of them away from warm parts such as regulators, or they will read the board instead of the air. An Arduino reads all of these.
How do you read a temperature sensor with an Arduino?
To read a temperature sensor with an Arduino, turn an LM35’s analogRead number back into millivolts and divide by ten, so 250 mV is 25 °C; a DS18B20’s library reads the number for you.
Example 1: an LM35 reading on an Arduino
An LM35 feeds a 5 V Arduino Uno’s analog pin, and analogRead gives 62. What is the temperature?
- Given
- an LM35 on a 5 V Arduino Uno’s analog pin, reading 62
- Find
- the temperature
- Solution
- V = 62 × 5 V ÷ 1,024 = 303 mVT = 303 mV ÷ 10 mV per °C = 30.3 °C
- Answer
- 30.3 °C
Example 2: a DS18B20’s resolution
A DS18B20 is set to 12-bit resolution. How fine are its steps, and how long can each reading take?
- Given
- a DS18B20 set to 12-bit resolution
- Find
- its smallest step and its longest time per reading
- Solution
- Step = 1 °C ÷ 212 − 8 = 1 °C ÷ 16 = 0.0625 °CTime = 750 ms ÷ 212 − 12 = 750 ms ÷ 1 = 750 ms
- Answer
- 0.0625 °C steps, up to 750 ms a reading
Summary
Key equations
- T = Vout ÷ 10 mV an LM35
- T = (Vout − 500 mV) ÷ 10 mV a TMP36
- V = reading × 5 V ÷ 1,024 a 5 V Arduino
Key terms
- RTD
- A platinum resistance sensor.
- Thermocouple
- Two metals making a voltage.
- 1-Wire
- Data on one shared wire.
- RH
- Relative humidity.
Practice problems
-
An LM35 outputs 320 mV. What is the temperature?
T = 320 mV ÷ 10 mV per °C = 32 °C.
-
A TMP36 outputs 750 mV. What is the temperature?
T = (750 mV − 500 mV) ÷ 10 mV per °C = 25 °C.
-
Which sensor suits a 1,000 °C kiln?
Type K thermocouples reach about 1,250 °C; the LM35 stops at 150 °C and the DHT11 at 50 °C.
-
What does a DHT11 measure?
It reports both over one data wire, ±2 °C and ±5% relative humidity.
-
Why can many DS18B20s share one data pin?
The microcontroller calls each sensor by its factory-set address on the shared 1-Wire bus.
FAQ
What is the most accurate temperature sensor?
A platinum RTD: a class A PT100 is within ±0.15 °C at 0 °C. Among hobby parts, the DS18B20’s ±0.5 °C is hard to beat.
What is the difference between the DHT11 and the DHT22?
The DHT22 reads −40 to 80 °C to ±0.5 °C and 0 to 100% humidity; the DHT11 reads 0 to 50 °C to ±2 °C and 20 to 80% humidity.
How does a humidity sensor work?
Most use a thin polymer film that absorbs water vapor, changing the capacitance between two electrodes; a chip turns that into relative humidity.
Can an LM35 measure negative temperatures?
Only with a negative supply and a resistor down to it. On a single supply it reads from about 2 °C up; a TMP36 reads down to −40 °C.
Does a DS18B20 need a pull-up resistor?
Yes, usually 4.7 kΩ from the data line to the supply, since 1-Wire devices only ever pull the line low.
What is a thermostat?
A temperature sensor plus a switch: it turns heating or cooling on and off to hold a set temperature, with a gap between its on and off points so it doesn’t chatter.
Why does my temperature sensor read too high?
Usually heat from nearby parts or a warm board. Mount it away from regulators and processors, and give it time to settle.
What is a temperature and humidity sensor?
One module that measures both, such as the DHT11 or DHT22, which pairs a humidity sensor with a thermistor and sends both readings over one digital pin.
What is a DHT11?
A low-cost temperature and humidity sensor that sends both readings over one data pin: 0 to 50 °C to within about 2 °C, and 20 to 80% humidity to within about 5%.