Ugenz Academy/IoT Tutorial

Temperature And Humidity Sensors

10 min read1,862 words

Reading progress

Keep learning

Temperature and Humidity Sensors

Temperature and humidity are two of the most commonly measured environmental parameters in electronics, IoT, weather monitoring, agriculture, smart homes, and industrial automation.

A temperature sensor measures how hot or cold something is, while a humidity sensor measures the amount of water vapor present in the air.

Some sensors measure only temperature, while others measure both temperature and humidity.


1. Temperature

Temperature indicates the degree of hotness or coldness of an object or environment.

Common units are:

  • Celsius — °C
  • Fahrenheit — °F
  • Kelvin — K

For electronics and IoT projects, Celsius (°C) is commonly used.

Example:

Room Temperature = 28°C

2. Humidity

Humidity describes the amount of water vapor present in the air.

The most commonly used measurement is Relative Humidity (RH).

It is expressed as a percentage:

0% RH → Very dry air 50% RH → Moderate humidity 100% RH → Air is fully saturated

For example:

Temperature = 27°C Humidity = 65% RH

This means the air has a relative humidity of 65%.


3. Why Measure Temperature and Humidity?

Temperature and humidity affect many systems.

They are used for:

  • Weather monitoring
  • Smart homes
  • Agriculture
  • Greenhouses
  • Server rooms
  • HVAC systems
  • Industrial automation
  • Food storage
  • Warehouses
  • IoT devices
  • Weather stations
  • Electronics monitoring

For example, a smart greenhouse can monitor:

Temperature + Humidity ↓ ESP32 ↓ Control Fan / Pump / Ventilation

4. Types of Temperature Sensors

Temperature sensors can be broadly classified into:

A. Thermistors

Resistance changes with temperature.

Examples:

  • NTC thermistor
  • PTC thermistor

B. Analog IC Temperature Sensors

Produce an analog voltage related to temperature.

Example:

  • LM35

C. Digital Temperature Sensors

Provide temperature as digital data.

Examples:

  • DS18B20
  • TMP102

D. Environmental Sensors

Measure temperature along with other parameters.

Examples:

  • BME280
  • BMP280
  • SHT30

5. Thermistor

A thermistor is a temperature-sensitive resistor.

Its resistance changes as temperature changes.

There are two common types.

NTC

NTC = Negative Temperature Coefficient

When temperature increases:

Temperature ↑ ↓ Resistance ↓

NTC thermistors are widely used for temperature measurement and protection circuits.


PTC

PTC = Positive Temperature Coefficient

When temperature increases:

Temperature ↑ ↓ Resistance ↑

PTC devices are often used for protection and current-limiting applications.


6. LM35 Temperature Sensor

The LM35 is a popular analog temperature sensor.

Its output voltage changes approximately linearly with temperature.

A common specification is approximately:

10 mV / °C

So conceptually:

0°C → 0.00 V 25°C → 0.25 V 50°C → 0.50 V

The actual usable measurement depends on the circuit, supply, ADC, and device conditions.


7. LM35 with Arduino

A typical connection is:

LM35 Arduino VCC ─────────── 5V GND ─────────── GND OUT ─────────── A0

The Arduino reads the analog voltage:

int value = analogRead(A0);

Then the program converts the ADC reading into a voltage and temperature.

For a typical Arduino Uno using its default 5 V ADC reference:

ADC value ↓ Voltage ↓ Temperature

The exact conversion should account for the actual ADC reference voltage rather than assuming it is exactly 5.00 V.


8. DS18B20 Temperature Sensor

The DS18B20 is a popular digital temperature sensor.

Important features include:

  • Digital output
  • 1-Wire communication
  • Multiple sensors can share one data bus
  • Suitable for embedded and IoT projects
  • Commonly available in waterproof versions

Typical waterproof form:

┌───────────────┐ │ Stainless Tube│ └───────┬───────┘ │ Cable

It is useful for:

  • Water temperature
  • Aquarium monitoring
  • Weather stations
  • Industrial monitoring
  • Soil temperature
  • IoT projects

9. DS18B20 Wiring

Typical three-wire connection:

DS18B20 ESP32 VCC ─────────── 3.3V GND ─────────── GND DATA ─────────── GPIO

A pull-up resistor, commonly around 4.7 kΩ, is normally connected between the DATA line and VCC.

3.3V │ [4.7kΩ] │ ├──────── DATA ───── ESP32 GPIO │ DS18B20

10. DHT11

The DHT11 is a low-cost digital sensor that measures:

  • Temperature
  • Relative humidity

Typical characteristics:

  • Low cost
  • Simple interface
  • Easy to use
  • Suitable for basic educational projects

It is useful for beginners.

Example applications:

Smart Home Weather Station Room Monitor IoT Project

11. DHT22

The DHT22, also known as AM2302, is another digital temperature and humidity sensor.

Compared with DHT11, it generally provides:

  • Wider measurement range
  • Better resolution
  • Better accuracy
  • Higher cost

Therefore:

DHT11 ↓ Basic / Low-cost DHT22 ↓ Better measurement capability

For serious projects, always check the manufacturer's datasheet for the exact specifications of the particular sensor/module.


12. DHT11/DHT22 Working

The basic process is:

Temperature ↓ Internal sensing element ↓ Internal processing ↓ Digital data ↓ Microcontroller

The humidity measurement is similarly processed internally before the sensor sends the result digitally.

The microcontroller does not simply read an analog voltage like it does from an LDR or LM35.


13. DHT Sensor Connection

For a typical module:

DHT22 ESP32 VCC ───────── 3.3V DATA ───────── GPIO GND ───────── GND

Depending on the sensor/module, a pull-up resistor may be required on the DATA line.

Many breakout modules already include the necessary resistor.


14. BME280

The BME280 is a more advanced environmental sensor.

It can measure:

  • Temperature
  • Humidity
  • Atmospheric pressure

Therefore:

BME280 ├── Temperature ├── Humidity └── Pressure

It commonly communicates using:

  • I²C
  • SPI

This makes it very useful for:

  • Weather stations
  • IoT
  • Environmental monitoring
  • Altitude-related applications
  • Smart agriculture

15. BMP280

The BMP280 is similar to the BME280 but is primarily used for:

  • Temperature
  • Atmospheric pressure

It does not provide humidity measurement.

Therefore:

BMP280 → Temperature + Pressure BME280 → Temperature + Humidity + Pressure

This is an important difference.


16. SHT Sensors

The SHT family includes sensors designed for accurate temperature and humidity measurement.

Examples include:

  • SHT30
  • SHT31
  • SHT35

These sensors are commonly used in:

  • Environmental monitoring
  • IoT
  • HVAC
  • Industrial applications
  • Weather monitoring

They typically communicate digitally, often using I²C.


17. Comparison of Common Sensors

SensorTemperatureHumidityPressureOutput/Interface
LM35✅❌❌Analog
NTC Thermistor✅❌❌Resistance/Analog circuit
DS18B20✅❌❌1-Wire
DHT11✅✅❌Digital
DHT22✅✅❌Digital
BMP280✅❌✅I²C/SPI
BME280✅✅✅I²C/SPI
SHT30✅✅❌I²C

18. Temperature and Humidity with ESP32

A common IoT architecture is:

DHT22 ↓ ESP32 ↓ Wi-Fi ↓ Cloud / Web Server ↓ Mobile / Computer

For example, an ESP32 can display:

Temperature: 29.4°C Humidity: 62.5%

on a web dashboard.


19. Example ESP32 + DHT22

A basic Arduino-style example:

#include <DHT.h> #define DHTPIN 4 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); dht.begin(); } void loop() { float temperature = dht.readTemperature(); float humidity = dht.readHumidity(); if (isnan(temperature) || isnan(humidity)) { Serial.println("Sensor reading failed!"); delay(2000); return; } Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °C"); Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %"); delay(2000); }

The isnan() check is important because sensor communication can occasionally fail.


20. Temperature Control System

Temperature sensors can be used to automatically control a fan.

Temperature Sensor ↓ ESP32 ↓ Temperature Check ↓ ┌──────┴──────┐ ↓ ↓ High Normal ↓ ↓ Fan ON Fan OFF

Example logic:

If temperature > 30°C ↓ Fan ON If temperature ≤ 30°C ↓ Fan OFF

21. Humidity Control System

Similarly, humidity can control a humidifier or ventilation system.

Humidity Sensor ↓ ESP32 ↓ Humidity Check ↓ Control Device

For example:

Humidity < 40% ↓ Humidifier ON

or:

Humidity > 70% ↓ Ventilation ON

The threshold depends on the application.


22. Applications

Smart Home

  • Automatic fan control
  • Air-quality/environment monitoring
  • Room monitoring
  • HVAC automation

Agriculture

  • Greenhouse monitoring
  • Crop environment monitoring
  • Irrigation decisions
  • Storage monitoring

Weather Station

Temperature Humidity Pressure ↓ Weather Station

Server Room

Temperature sensors can detect overheating.

Temperature ↑ ↓ Warning ↓ Cooling System

Food Storage

Temperature and humidity can be monitored to help maintain suitable storage conditions.


23. Important Sensor Characteristics

When selecting a temperature/humidity sensor, consider:

Accuracy

How close the measurement is to the actual value.

Resolution

The smallest change that can be represented.

Measurement Range

Example:

-40°C to +80°C

Response Time

How quickly the sensor responds to environmental changes.

Stability

How well the sensor maintains reliable measurements over time.

Communication Interface

Examples:

Analog 1-Wire I²C SPI Digital single-wire interface

24. Common Mistakes

Mistake 1: Confusing BME280 and BMP280

Remember:

BMP280 → Temperature + Pressure BME280 → Temperature + Humidity + Pressure

Mistake 2: Wrong DHT type in code

If you have DHT22:

#define DHTTYPE DHT22

Don't configure it as DHT11.

Mistake 3: Incorrect power voltage

Always check the specific sensor/module datasheet.

This is particularly important with ESP32, because ESP32 GPIOs are generally 3.3 V logic and should not be exposed to inappropriate voltages.

Mistake 4: No pull-up resistor where required

Some digital sensors require an appropriate pull-up on their data line.

Mistake 5: Reading DHT sensors too quickly

DHT sensors have relatively slow measurement/update rates. Don't continuously request readings at very short intervals.


25. Practical IoT Example

Let's build a simple Smart Room Environment Monitor:

SMART ROOM │ ┌──────┴──────┐ ↓ ↓ DHT22 LDR │ │ └──────┬──────┘ ↓ ESP32 │ ┌──────┼───────┐ ↓ ↓ ↓ LCD Wi-Fi Relay │ │ │ Display App Fan

The system can display:

-------------------- SMART ROOM -------------------- Temp : 28.5°C Hum : 63% Light: Bright Fan : OFF --------------------

If temperature rises:

Temp > 30°C ↓ ESP32 ↓ Relay ON ↓ Fan ON

This is the basic foundation of an IoT environmental monitoring system.


Key Points to Remember

Temperature sensors measure thermal conditions, while humidity sensors measure moisture in the air.

Important sensors:

LM35 → Analog temperature NTC → Resistance-based temperature DS18B20 → Digital temperature DHT11 → Temperature + humidity DHT22 → Temperature + humidity BMP280 → Temperature + pressure BME280 → Temperature + humidity + pressure SHT30 → Temperature + humidity

And the basic IoT flow is:

Environment ↓ Temperature / Humidity Sensor ↓ Arduino / ESP32 ↓ Processing ↓ Display / Wi-Fi / Cloud ↓ Monitoring or Automatic Control

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy