ESP32 SHT35 Temperature and Humidity Sensor
Overview
The SHT35 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 SHT35 Temperature and Humidity Sensor
The SHT35, developed by Sensirion, is the premium model in the SHT3x series, offering superior accuracy and reliability. It is designed for demanding applications such as industrial monitoring, HVAC systems, and environmental data logging.
⚡ Key Features
- Highest Accuracy in the SHT3x Series – Superior precision for critical applications.
- I²C Communication – Easy integration with ESP32, Arduino, and other microcontrollers.
- Long-Term Stability – Ensures consistent and reliable environmental measurements.
- Ideal for Professional Use – Used in scientific monitoring, industrial automation, and smart HVAC systems.
🔗 Looking for cost-effective alternatives? Consider:
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 SHT35 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
💻 Compilation Error: 'yield' was not declared in this scope
Issue: When compiling code for the SHT35 sensor using the Seeed Studio library, the following error occurs: 'yield' was not declared in this scope
.
Possible causes include outdated or incorrect library versions that are incompatible with the current Arduino IDE.
Solution: Update the Arduino IDE to the latest version and ensure that the Seeed Studio SHT35 library is also up to date. If the issue persists, manually edit the library files to include the appropriate declarations or consider using an alternative library compatible with the SHT35 sensor. (forum.arduino.cc)
⚠️ Runtime Error: Errno 121 Remote I/O Error
Issue: When running a Python script on a Raspberry Pi to read data from the SHT35 sensor, the following error is encountered after a period of successful readings: Errno 121 Remote I/O Error
.
Possible causes include intermittent I2C communication issues, loose connections, or power supply instability.
Solution: Check all physical connections between the Raspberry Pi and the SHT35 sensor to ensure they are secure. Verify that the I2C bus is properly configured and that pull-up resistors are correctly implemented. Additionally, monitor the power supply to ensure it remains stable during operation. (forum.seeedstudio.com)
❌ Sensor Not Detected on I2C Bus
Issue: The SHT35 sensor is not detected on the I2C bus, resulting in failed communication attempts.
Possible causes include incorrect wiring, improper I2C address configuration, or sensor malfunction.
Solution: Verify that the SDA and SCL lines are correctly connected to the appropriate pins on the microcontroller. Ensure that the sensor's I2C address matches the address specified in the code (default is 0x44
). If using multiple I2C devices, confirm that there are no address conflicts. Test the sensor with an I2C scanner to detect its presence on the bus. (arduinolearning.com)
🔄 Data Retrieval Issues with Multiple Clients
Issue: When accessing the SHT35 sensor data from multiple clients simultaneously, the sensor becomes unresponsive, requiring a system reboot to restore functionality.
Possible causes include concurrent access to the I2C bus leading to communication conflicts.
Solution: Implement a data caching mechanism where a single process reads data from the sensor at regular intervals and stores it. Clients can then access the cached data instead of querying the sensor directly. This approach prevents simultaneous I2C access and reduces the risk of communication issues. (forums.raspberrypi.com)
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 address
Serial.println("Couldn't find SHT35");
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 SHT35 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 SHT35_SENSOR_ADDR 0x44 /!< SHT35 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_sht35_sensor() {
uint8_t data[6];
i2c_master_write_read_device(I2C_MASTER_NUM, SHT35_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_sht35_sensor();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
read_sht35_sensor()
function reads raw temperature and humidity data from the SHT35 sensor and converts it into human-readable values. These values are printed to the console every 2 seconds.ESPHome Example
sensor:
- platform: sht3x
address: 0x44
temperature:
name: "Living Room Temperature"
humidity:
name: "Living Room Humidity"
update_interval: 60s
sht3x
platform. The I2C address is set to 0x44 (default for the sensor). Two entities are configured: one for temperature and one for humidity, with descriptive names like 'Living Room Temperature' and 'Living Room Humidity.' The update_interval
is set to 60 seconds, meaning the data will be updated every minute.PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit SHT31 Library @ ^1.2.0
monitor_speed = 115200
PlatformIO Example Code
#include <Wire.h>
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht35 = Adafruit_SHT31();
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
if (!sht35.begin(0x44)) { // Default I2C address for SHT35
Serial.println("Couldn't find SHT35 sensor!");
while (1) delay(1);
}
}
void loop() {
float temperature = sht35.readTemperature();
float humidity = sht35.readHumidity();
if (!isnan(temperature) && !isnan(humidity)) { // Check if readings are valid
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
Serial.println("Failed to read from SHT35 sensor!");
}
delay(2000); // Wait 2 seconds between readings
}
MicroPython Example
from machine import I2C, Pin
import time
# SHT35 default I2C address
SHT35_I2C_ADDRESS = 0x44
# Initialize I2C communication (SDA=21, SCL=22)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
def read_sht35():
# Send measurement command (high repeatability, no clock stretching)
i2c.writeto(SHT35_I2C_ADDRESS, b'\x24\x00')
time.sleep(0.015) # Wait for measurement to complete
# Read 6 bytes of data
data = i2c.readfrom(SHT35_I2C_ADDRESS, 6)
# Convert the data
temp_raw = (data[0] << 8) | data[1]
humidity_raw = (data[3] << 8) | data[4]
# Calculate temperature and humidity
temperature = -45 + (175 temp_raw / 65535.0)
humidity = 100 humidity_raw / 65535.0
return temperature, humidity
while True:
try:
temperature, humidity = read_sht35()
print("Temperature: {:.2f} °C".format(temperature))
print("Humidity: {:.2f} %".format(humidity))
except Exception as e:
print("Failed to read from SHT35 sensor:", e)
time.sleep(2)
read_sht35
function sends a command to the sensor to initiate a measurement, waits for the response, and then reads 6 bytes of data. The raw data is processed into human-readable temperature (°C) and humidity (%) values. The script continuously reads and prints these values every 2 seconds. Error handling is included to manage failed readings.Conclusion
The ESP32 SHT35 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.