SHT20 Temperature and Humidity Sensor

View on Amazon
Overview
About SHT20 Temperature and Humidity Sensor
The SHT20, developed by Sensirion, is a cost-effective digital sensor designed for accurate temperature and humidity measurements. Known for its reliability, it is widely used in HVAC systems, data loggers, and consumer electronics.
⚡ Key Features
- High Accuracy & Stability – Delivers precise temperature and humidity readings.
- Digital Output – Communicates via I²C for seamless integration.
- Compact & Energy-Efficient – Ideal for battery-powered applications.
- Cost-Effective Solution – Affordable without compromising performance.
🔗 Looking for enhanced accuracy? Consider the SHT21 or SHT30 for improved features.
Get Your SHT20
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
SHT20 Specifications
Complete technical specification details for SHT20 Temperature and Humidity Sensor
📊 Technical Parameters
SHT20 Pinout
The SHT20 uses standard I²C communication with 4 pins for power and data transfer.
Visual Pinout Diagram

Pin Types
Quick Tips
Standard I²C interface for easy integration,📡 Default I²C address is 0x40
High accuracy: ±0.3°C temperature, ±3% humidity,⚡ Pull-up resistors (10kΩ) recommended on SDA/SCL
Low voltage operation (2.1V-3.6V) for battery use
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VCC | Power | Power supply input (2.1V to 3.6V) | Low voltage sensor for battery applications |
2 GND | Power | Ground connection | Connect to ESP32 ground |
3 SDA | Communication | I²C data line | Bidirectional data communication |
4 SCL | Communication | I²C clock line | Clock signal from master device |
Wiring SHT20 to ESP32
Connect the SHT20 using standard I²C interface for reliable environmental measurements.
Pin Connections
| SHT20 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply (2.1V to 3.6V) | |
2 GND Required | GND | Ground connection | |
3 SDA Required | GPIO21 | I²C data line (default SDA) | |
4 SCL Required | GPIO22 | I²C clock line (default SCL) |
GPIO21/22 are default I²C pins on ESP32
I²C address is 0x40 (default)
Add 10kΩ pull-up resistors on SDA/SCL if needed
Can share I²C bus with other devices
SHT20 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The SHT20 sensor returns incorrect temperature and humidity values, such as 988 instead of the expected readings.
Possible causes include improper wiring, incorrect I2C address configuration, or sensor initialization issues.
Solution: Verify that the sensor is correctly wired to the microcontroller, ensuring proper connections for power, ground, and I2C data lines. Confirm that the correct I2C address (typically 0x40) is specified in your code. Ensure that the sensor is properly initialized in the software, and consider using a reliable library compatible with the SHT20 sensor.
Issue: The serial monitor displays initial messages (e.g., SHT20 example) but does not show subsequent temperature or humidity readings.
Possible causes include issues with sensor communication, missing pull-up resistors on the I2C lines, or incorrect sensor initialization.
Solution: Ensure that the I2C communication lines (SDA and SCL) have appropriate pull-up resistors (typically 4.7kΩ). Verify that the sensor is properly connected and initialized in the code. Check for any loose connections or wiring errors that might impede communication between the sensor and the microcontroller.
Issue: Compilation errors occur when using the SHT20 library with the Arduino IDE.
Possible causes include missing library files, incorrect library installation, or conflicts with other installed libraries.
Solution: Ensure that the SHT20 library is correctly installed in the Arduino IDE. Verify that there are no conflicting libraries that might interfere with the SHT20 library. If necessary, reinstall the library or try using an alternative library compatible with the SHT20 sensor.
Issue: Connecting the SHT20 sensor alongside other I2C devices causes communication issues or device malfunctions.
Possible causes include I2C address conflicts or improper bus configuration.
Solution: Ensure that each device on the I2C bus has a unique address. The SHT20 sensor typically uses the address 0x40. Verify that no other devices share this address. If address conflicts exist, consider using an I2C multiplexer or modifying the setup to resolve the conflicts.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
SHT20 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Wire.h>
#include "DFRobot_SHT20.h"
DFRobot_SHT20 sht20;
void setup() {
Serial.begin(115200);
Wire.begin();
sht20.initSHT20();
delay(100);
sht20.checkSHT20();
}
void loop() {
float humidity = sht20.readHumidity();
float temperature = sht20.readTemperature();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(2000);
}#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2c.h"
#define I2C_MASTER_SCL_IO 22 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 21 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C master I2C port number */
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */
#define SHT20_SENSOR_ADDR 0x40 /*!< SHT20 I2C address */
static esp_err_t i2c_master_init(void) {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
esp_err_t err = i2c_param_config(I2C_MASTER_NUM, &conf);
if (err != ESP_OK) {
return err;
}
return i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0);
}
void read_sht20_sensor() {
uint8_t data[3];
uint8_t cmd = 0xF5; // Command for humidity measurement
i2c_master_write_to_device(I2C_MASTER_NUM, SHT20_SENSOR_ADDR, &cmd, 1, pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(50));
i2c_master_read_from_device(I2C_MASTER_NUM, SHT20_SENSOR_ADDR, data, 3, pdMS_TO_TICKS(1000));
uint16_t raw_humidity = (data[0] << 8) | (data[1] & 0xFC);
float humidity = -6.0 + 125.0 * (raw_humidity / 65536.0);
cmd = 0xF3; // Command for temperature measurement
i2c_master_write_to_device(I2C_MASTER_NUM, SHT20_SENSOR_ADDR, &cmd, 1, pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(50));
i2c_master_read_from_device(I2C_MASTER_NUM, SHT20_SENSOR_ADDR, data, 3, pdMS_TO_TICKS(1000));
uint16_t raw_temperature = (data[0] << 8) | (data[1] & 0xFC);
float temperature = -46.85 + 175.72 * (raw_temperature / 65536.0);
printf("Temperature: %.2f °C, Humidity: %.2f %%\n", temperature, humidity);
}
void app_main() {
ESP_ERROR_CHECK(i2c_master_init());
while (1) {
read_sht20_sensor();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}sensor:
- platform: sht3x
address: 0x40
temperature:
name: "Room Temperature"
humidity:
name: "Room Humidity"
update_interval: 60splatformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
DFRobot/DFRobot_SHT20 @ ^1.0.0
monitor_speed = 115200main.cpp
#include <Wire.h>
#include "DFRobot_SHT20.h"
DFRobot_SHT20 sht20;
void setup() {
Serial.begin(115200);
Wire.begin();
sht20.initSHT20();
delay(100);
sht20.checkSHT20();
}
void loop() {
float humidity = sht20.readHumidity();
float temperature = sht20.readTemperature();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000);
}from machine import Pin, I2C
from time import sleep
# Initialize I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
SHT20_ADDR = 0x40
# Function to read data from the SHT20
def read_sht20(cmd):
i2c.writeto(SHT20_ADDR, bytearray([cmd]))
sleep(0.05)
data = i2c.readfrom(SHT20_ADDR, 3)
raw = (data[0] << 8) | (data[1] & 0xFC)
return raw
while True:
# Read humidity
raw_humidity = read_sht20(0xF5)
humidity = -6.0 + 125.0 * (raw_humidity / 65536.0)
# Read temperature
raw_temperature = read_sht20(0xF3)
temperature = -46.85 + 175.72 * (raw_temperature / 65536.0)
print(f"Temperature: {temperature:.2f} °C, Humidity: {humidity:.2f} %")
sleep(2)Wrapping Up SHT20
The ESP32 SHT20 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.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the SHT20 into your ESP32 project and bring your ideas to life!







