ESP32 SHT21 / HTU21 / GY-21 / SI7021 Temperature and Humidity Sensor

SHT21 / HTU21 / GY-21 / SI7021 Temperature and Humidity Sensor image

SHT21 / HTU21 / GY-21 / SI7021

Protocol: I2C

Overview

The SHT21, HTU21, GY-21, and SI7021 sensors utilize I2C for reliable communication and provide calibrated, linearized temperature and humidity readings. Their compact form factor and low power consumption make them ideal for precise environmental monitoring.

About SHT21 / HTU21 / GY-21 / SI7021 Temperature and Humidity Sensor

The SHT21, HTU21, GY-21, and SI7021 are compact digital temperature and humidity sensors that provide high-precision measurements. Using the I²C communication protocol, they are ideal for HVAC systems, data loggers, weather stations, and consumer electronics.

Key Features

  • High Accuracy & Stability – Reliable temperature and humidity sensing.
  • I²C Communication – Easy integration with ESP32, Arduino, and other microcontrollers.
  • Compact & Energy-Efficient – Ideal for low-power and battery-powered applications.
  • Versatile Applications – Used in climate control, weather monitoring, and industrial automation.

🔗 Looking for alternatives in the SHT series? Check out:

  • SHT20 – Cost-effective option.
  • SHT25 – Improved accuracy.
  • SHT30 – Enhanced performance and additional features.

Where to Buy

SHT21 / HTU21 / GY-21 / SI7021 Temperature and Humidity Sensor

Starting from

$5 per unit

Amazon com
Amazon.com Ships worldwide
View Price
Amazon de
Amazon.de Ships to EU
View Price
Aliexpress
AliExpress Best value
View Price

Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.

Technical Specifications

Operating Voltage 2.1V to 3.6V
Temperature Range -40°C to 125°C
Humidity Range 0% to 100% RH
Temperature Accuracy ±0.3°C
Humidity Accuracy ±2% RH
Interface I2C
Dimensions 3mm x 3mm x 1.1mm

Pinout Configuration

The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32.

The Pinout for these sensors is as follows:

  • VCC: Power supply voltage (2.1V to 3.6V).
  • GND: Ground.
  • SDA: Serial Data Line for I2C communication.
  • SCL: Serial Clock Line for I2C communication.

Wiring with ESP32

To interface with an ESP32:
  • Connect VCC to the 3.3V pin on the ESP32.
  • Connect GND to the ground (GND) of the ESP32.
  • Connect SDA to the ESP32's GPIO21 (default I2C data pin).
  • Connect SCL to the ESP32's GPIO22 (default I2C clock pin).
  • Place pull-up resistors (10kΩ) between SDA and VCC, and SCL and VCC, to ensure reliable communication.

Troubleshooting Guide

Common Issues

💻 Compilation Errors with SHT21 Library

🔒 Permission Denied Error on Raspberry Pi

⚠️ Incorrect Temperature and Humidity Readings

🔌 Interfacing Issues with SHT21 Sensor

Debugging Tips

🔍 Serial Monitor

⚡ Voltage Checks

Code Examples

Arduino Example

C++
🔧

ESP-IDF Example

C++
🏠

ESPHome Example

YAML
🛠️

PlatformIO Example

C++
🐍

MicroPython Example

Python

Conclusion

The ESP32 SHT21 / HTU21 / GY-21 / SI7021 Temperature and Humidity Sensor is a powerful environment sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.

For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.

Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.