ESP32 SHT25 Temperature and Humidity Sensor
Overview
The SHT25 sensor is a high-accuracy digital temperature and humidity sensor that utilizes Sensirion's CMOSens® technology. It provides calibrated, linearized sensor signals in digital I2C format, making it ideal for applications requiring precise and reliable environmental measurements.
About SHT25 Temperature and Humidity Sensor
The SHT25, developed by Sensirion, is a high-accuracy digital sensor designed for precise temperature and humidity measurement. With superior stability and reliability, it is ideal for industrial monitoring, HVAC systems, and environmental data logging.
⚡ Key Features
- Superior Accuracy – Higher precision than standard SHT sensors.
- I²C Communication – Seamless integration with ESP32, Arduino, and other microcontrollers.
- Long-Term Stability – Reliable performance for demanding environments.
- Versatile Applications – Used in climate control, industrial automation, and data logging.
🔗 Looking for alternatives? Check out:
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 SHT25 pinout is as follows:
- VDD: 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
- 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
❌ Incorrect I2C Address Detection
Issue: The SHT25 sensor is expected to have an I2C address of 0x40
, but an I2C scanner detects it at 0x38
. Attempting to communicate using the standard address results in no response or incorrect data.
Possible causes include counterfeit or mislabeled sensors that do not conform to standard specifications.
Solution: Use the detected I2C address (0x38
) in your code instead of the expected 0x40
. If communication issues persist, consider verifying the authenticity of the sensor or replacing it with a genuine SHT25 sensor.
🚫 Communication Failure with I2C Interface
Issue: Attempts to read data from the SHT25 sensor over I2C result in receiving 0xF0
or 0x00
, indicating unsuccessful communication.
Possible causes include incorrect I2C implementation, timing issues, or improper sensor initialization.
Solution: Ensure that the I2C communication is correctly implemented with appropriate timing delays as specified in the SHT25 datasheet. Verify that the sensor is properly initialized and that the correct commands are being sent. Reviewing and following the sensor's datasheet can provide guidance on proper communication protocols.
🌡️ Higher Than Expected Temperature Readings
Issue: The SHT25 sensor reports temperatures higher than the actual ambient temperature, leading to inaccurate measurements.
Possible causes include heat generated by nearby components affecting the sensor or inadequate ventilation around the sensor.
Solution: Ensure that the sensor is placed away from heat sources and has proper ventilation. Consider implementing software calibration to offset any consistent discrepancies. If the issue persists, consult the sensor's datasheet for recommended operating conditions and verify that the sensor is being used within those parameters.
💻 Compilation Errors with SHT25 Library
Issue: When compiling code that interfaces with the SHT25 sensor using the LibHumidity
library, errors such as 'class TwoWire' has no member named 'send'
and 'class TwoWire' has no member named 'receive'
are encountered.
Possible causes include the use of outdated functions in the library that are incompatible with the current Wire library, which now uses write()
and read()
methods instead of send()
and receive()
.
Solution: Update the LibHumidity
library by replacing instances of send()
with write()
and receive()
with read()
. Alternatively, consider using a more recent library that supports the SHT25 sensor and is compatible with the current Wire library implementation.
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 "SHT2x.h"
SHT2x sht;
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
float temperature = sht.GetTemperature();
float humidity = sht.GetHumidity();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000);
}
ESP-IDF Example
uint16_t raw_humidity = (data[0] << 8) | data[1];
uint8_t cmd_temp = 0xF3; // Command for temperature measurement
i2c_master_write_to_device(I2C_MASTER_NUM, SHT25_SENSOR_ADDR, &cmd_temp, 1, pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(50));
i2c_master_read_from_device(I2C_MASTER_NUM, SHT25_SENSOR_ADDR, data, 3, pdMS_TO_TICKS(1000));
uint16_t raw_temperature = (data[0] << 8) | data[1];
float humidity = -6.0 + 125.0 ((float)raw_humidity / 65536.0);
float temperature = -46.85 + 175.72 ((float)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_sht25_sensor();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
ESPHome Example
sensor:
- platform: sht3x
address: 0x40
temperature:
name: "Indoor Temperature"
humidity:
name: "Indoor Humidity"
update_interval: 60s
sht3x
platform (compatible for earlier SHT2x series as well). The I2C address is set to 0x40. Two entities are created for temperature and humidity, labeled with user-friendly names like 'Indoor Temperature' and 'Indoor Humidity.' The update_interval
is set to 60 seconds, meaning data is refreshed every minute.PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
"Sensirion/SHT2x"
monitor_speed = 115200
PlatformIO Example Code
#include <Wire.h>
#include "SHT2x.h"
SHT2x sht;
void setup() {
Wire.begin();
Serial.begin(115200);
}
void loop() {
float temperature = sht.GetTemperature();
float humidity = sht.GetHumidity();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000);
}
Sensirion/SHT2x
library is included in the project dependencies.MicroPython Example
from machine import I2C, Pin
from time import sleep
import sht21
# Initialize I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Initialize the SHT25 sensor
sensor = sht21.SHT21(i2c)
while True:
try:
temperature = sensor.read_temperature()
humidity = sensor.read_humidity()
print(f"Temperature: {temperature:.2f} °C")
print(f"Humidity: {humidity:.2f} %")
except Exception as e:
print(f"Error reading sensor: {e}")
sleep(2)
sht21
library to communicate with the SHT25 sensor over I2C. It reads temperature and humidity data in a loop, prints the readings to the console, and handles any errors that occur during communication. The data is updated every 2 seconds.Conclusion
The ESP32 SHT25 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.