ESP32 SHT30 Temperature and Humidity Sensor
Overview
The SHT30 sensor is a high-precision digital temperature and humidity sensor that utilizes Sensirion's CMOSens® technology. It provides fully calibrated, linearized, and temperature-compensated digital output, making it ideal for applications requiring precise and reliable environmental measurements.
About SHT30 Temperature and Humidity Sensor
The SHT30, developed by Sensirion, is a high-precision digital sensor designed for temperature and humidity measurement. With excellent long-term stability and reliability, it is ideal for HVAC systems, data loggers, and weather stations.
⚡ Key Features
- High Accuracy – ±2% RH (humidity) and ±0.3°C (temperature).
- I²C Communication – Easy integration with ESP32, Arduino, and other microcontrollers.
- Long-Term Stability – Ensures consistent performance over time.
- Versatile Applications – Used in climate control, industrial monitoring, and smart home systems.
With its reliability and precision, the SHT30 is a great choice for environmental sensing applications. 🚀
For enhanced performance and additional features, consider the SHT31 sensor, which offers improved accuracy and response time.
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
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 SHT30 pinout is as follows:
- VDD: Power supply voltage (2.4V to 5.5V).
- GND: Ground.
- SDA: Serial Data Line for I2C communication.
- SCL: Serial Clock Line for I2C communication.
Wiring with ESP32
- Connect VDD 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 VDD, and SCL and VDD, to ensure reliable communication.
Troubleshooting Guide
Common Issues
❌ Sensor Not Detected After Arduino Reset
Issue: The SHT30 sensor functions correctly upon initial power-up but fails to be detected on the I2C bus after pressing the Arduino reset button or uploading new code. The serial monitor displays: Couldn't find SHT31
.
Possible causes include the sensor not resetting properly when the Arduino is reset, leading to communication issues.
Solution: Implement a power cycle for the sensor by briefly disconnecting and reconnecting its power supply after resetting the Arduino. This ensures both the Arduino and the sensor initialize correctly. Alternatively, consider adding a manual reset mechanism for the sensor or using a microcontroller that can control the sensor's power line programmatically. (forums.adafruit.com)
🚫 Communication Failure with SHT30 Shield
Issue: When using the LOLIN Wemos SHT30 Shield with ESPHome, the following error message is encountered: Communication with SHT3xD failed!
.
Possible causes include incorrect I2C pin configuration, insufficient pull-up resistors, or improper initialization in the software.
Solution: Verify that the correct I2C pins are configured in the ESPHome YAML file, matching the hardware connections. Ensure that appropriate pull-up resistors (typically 4.7kΩ) are present on the SDA and SCL lines. Confirm that the sensor is properly initialized in the code, and consider testing with different I2C frequencies if issues persist. (community.home-assistant.io)
🐍 Bus Error in MicroPython
Issue: When interfacing the SHT30 sensor with ESP32 Pico using MicroPython, the following error occurs: SHT30Error: Bus error
.
Possible causes include incorrect I2C address configuration, improper pin assignments, or missing initialization parameters in the I2C setup.
Solution: Ensure that the correct I2C address (typically 0x44
) is specified in the code. Verify that the SDA and SCL pins are correctly assigned and correspond to the physical connections. Modify the I2C initialization to include the bus ID parameter, for example: self.i2c = I2C(0, scl=Pin(scl_pin), sda=Pin(sda_pin))
. Adding appropriate pull-up resistors on the I2C lines may also help resolve the issue. (github.com)
🛡️ Sensor Not Generating Readings Outside Faraday Cage
Issue: The SHT30 sensor fails to generate readings when placed outside a Faraday cage, but functions correctly inside it. The serial monitor may display: Failed to read temperature
and Failed to read humidity
.
Possible causes include electromagnetic interference (EMI) affecting sensor performance when not shielded.
Solution: To mitigate EMI, consider enclosing the sensor in a grounded metal enclosure or Faraday cage during operation. Ensure that the sensor's wiring is properly shielded and kept away from sources of electromagnetic noise, such as high-frequency circuits or wireless transmitters. Additionally, verify that the sensor's power supply is stable and free from noise. (forum.arduino.cc)
Debugging Tips
🔍 Serial Monitor
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.
⚡ Voltage Checks
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
Code Examples
Arduino Example
#include <Wire.h>
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
if (!sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
Serial.println("Couldn't find SHT31");
while (1) delay(1);
}
}
void loop() {
float t = sht31.readTemperature();
float h = sht31.readHumidity();
if (!isnan(t) && !isnan(h)) { // check if 'is not a number'
Serial.print("Temp *C = "); Serial.print(t); Serial.print(" ");
Serial.print("Hum. % = "); Serial.println(h);
} else {
Serial.println("Failed to read from SHT31 sensor");
}
delay(1000);
}
ESP-IDF Example
#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 SHT30_SENSOR_ADDR 0x44 /!< SHT30 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_sht30_sensor() {
uint8_t data[6];
i2c_master_write_read_device(I2C_MASTER_NUM, SHT30_SENSOR_ADDR, NULL, 0, data, sizeof(data), pdMS_TO_TICKS(1000));
uint16_t temp_raw = (data[0] << 8) | data[1];
uint16_t hum_raw = (data[3] << 8) | data[4];
float temperature = -45 + 175 ((float)temp_raw / 65535.0);
float humidity = 100 ((float)hum_raw / 65535.0);
printf("Temperature: %.2f °C, Humidity: %.2f %%\n", temperature, humidity);
}
void app_main() {
ESP_ERROR_CHECK(i2c_master_init());
while (1) {
read_sht30_sensor();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
ESPHome Example
i2c:
sda: GPIO21
scl: GPIO22
scan: true
sensor:
- platform: sht3x
address: 0x44
temperature:
name: "Room Temperature"
humidity:
name: "Room Humidity"
update_interval: 60s
sht3x
platform for interfacing with the SHT30 sensor. The i2c
section specifies the SDA (GPIO21) and SCL (GPIO22) pins, enabling communication with the sensor. The address
key indicates the I2C address of the SHT30 sensor (default 0x44
). Two sensor entities are defined: one for temperature and one for humidity, with user-friendly names such as 'Room Temperature' and 'Room Humidity.' The readings are updated every 60 seconds.PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit SHT31 Library @ ^1.1.0
monitor_speed = 115200
PlatformIO Example Code
#include <Wire.h>
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup() {
Serial.begin(115200);
if (!sht31.begin(0x44)) {
Serial.println("Couldn't find SHT30 sensor. Check wiring!");
while (1);
}
Serial.println("SHT30 initialized.");
}
void loop() {
float temperature = sht31.readTemperature();
float humidity = sht31.readHumidity();
if (!isnan(temperature) && !isnan(humidity)) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
Serial.println("Failed to read from SHT30 sensor!");
}
delay(2000);
}
0x44
. If successful, the loop continuously reads temperature and humidity values, printing them to the Serial Monitor every 2 seconds. Any errors in reading are reported in the console.MicroPython Example
from machine import Pin, I2C
from time import sleep
import sht31
# Initialize I2C (SDA=21, SCL=22)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
sensor = sht31.SHT31(i2c)
print("SHT30 Sensor Example")
while True:
temperature, humidity = sensor.measure()
print("Temperature: {:.2f} °C".format(temperature))
print("Humidity: {:.2f} %".format(humidity))
sleep(2)
sht31
library to interface with the SHT30 sensor. The I2C bus is initialized on GPIO21 (SDA) and GPIO22 (SCL). The sensor.measure()
function retrieves temperature and humidity readings, which are formatted and printed to the console every 2 seconds. The code is lightweight and ideal for microcontroller projects.Conclusion
The ESP32 SHT30 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.