ESP32 HTE501 Temperature and Humidity Sensor
Overview
The E+E HTE501 is a digital humidity and temperature sensor designed for high accuracy in demanding environments. Compactly housed in a DFN package (2.5x2.5 mm), it offers ±1.8% RH and ±0.2 °C accuracy, and features a constant current heater and proprietary coating for stability.
About HTE501 Temperature and Humidity Sensor
The HTE501 is a high-precision digital humidity and temperature sensor, designed for accurate environmental monitoring. With fast response time and long-term stability, it is ideal for industrial, HVAC, and IoT applications.
⚡ Key Features
- High Accuracy – Provides precise humidity and temperature measurements.
- Digital Output – Communicates via I²C for seamless integration.
- Fast Response & Stability – Reliable performance in dynamic environments.
- Compact & Energy-Efficient – Suitable for battery-powered applications.
The HTE501 is a great choice for climate control, smart home devices, and weather monitoring systems. 🚀
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Troubleshooting Guide
Common Issues
❌ Sensor Not Detected on I2C Bus
Issue: The HTE501 sensor is not recognized on the I2C bus, leading to communication failures.
Possible causes include incorrect wiring, improper I2C address configuration, or sensor malfunction.
Solution: Verify that the sensor's VCC and GND are properly connected to the power supply, and that SDA and SCL lines are correctly connected to the corresponding I2C pins on the microcontroller. Ensure that the I2C address matches the sensor's default or configured address. Use an I2C scanner to detect the sensor's presence on the bus. If the sensor remains undetected, consider testing with a different microcontroller or replacing the sensor.
⚠️ Incorrect or Unstable Readings
Issue: The HTE501 sensor provides temperature or humidity readings that are inaccurate or fluctuate unexpectedly.
Possible causes include environmental interference, improper sensor placement, or lack of calibration.
Solution: Place the sensor away from direct heat sources, sunlight, or areas with rapid temperature changes. Ensure that the sensor is properly initialized and calibrated in the code. If inaccuracies persist, consider implementing software-based calibration adjustments based on known reference values.
⏳ I2C Communication Timeouts
Issue: Communication with the HTE501 sensor over I2C results in timeout errors, especially during single-shot measurements.
Possible causes include the sensor's clock stretching behavior during measurements, which may not be properly handled by the microcontroller's I2C implementation.
Solution: Implement a delay (e.g., 20ms) after initiating a measurement to allow the sensor to process the data before attempting to read the results. Alternatively, monitor the sensor's status register to determine when the measurement is complete before reading the data. This approach ensures synchronization between the sensor and the microcontroller, preventing timeout errors.
💻Compilation Errors When Using HTE501 Library
Issue: Compilation errors occur when attempting to use the HTE501 sensor with a development platform.
Errors such as 'undefined reference' or 'no matching function' may appear.
Solution: Ensure that the correct library for the HTE501 sensor is installed and properly included in the project. Verify that the library version is compatible with your development environment. Check for any missing dependencies and ensure that all necessary files are present. If errors persist, consider consulting the library's documentation or seeking support from the developer community.
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 library compatible with I2C humidity/temp sensors
Adafruit_SHT31 sht31 = Adafruit_SHT31();
void setup() {
Serial.begin(115200); // Start the serial communication
Wire.begin(); // Initialize I2C
// Initialize the sensor
if (!sht31.begin(0x44)) { // The default I2C address for many SHT3x sensors is 0x44
Serial.println("Couldn't find HTE501 sensor!");
while (1) delay(1); // Stop if the sensor is not found
}
Serial.println("HTE501 Sensor initialized.");
}
void loop() {
float temperature = sht31.readTemperature(); // Read temperature in Celsius
float humidity = sht31.readHumidity(); // Read relative humidity in %
if (!isnan(temperature)) { // Check if reading is valid
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
} else {
Serial.println("Error reading temperature.");
}
if (!isnan(humidity)) { // Check if reading is valid
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
Serial.println("Error reading humidity.");
}
delay(2000); // Wait for 2 seconds before the next reading
}
setup()
function initializes serial communication, the I2C bus, and the sensor. If the sensor initialization fails, an error message is printed, and the program halts. In the loop()
function, temperature and humidity values are read using the library's methods, checked for validity, and then printed to the Serial Monitor. A 2-second delay ensures manageable update intervals.ESP-IDF Example
#include <stdio.h>
#include "driver/i2c.h"
#include "esp_log.h"
#include "sdkconfig.h"
#define I2C_MASTER_SCL_IO 22 // GPIO number for I2C SCL
#define I2C_MASTER_SDA_IO 21 // GPIO number for I2C SDA
#define I2C_MASTER_NUM I2C_NUM_0 // I2C port number for master
#define I2C_MASTER_FREQ_HZ 100000 // I2C master clock frequency
#define I2C_MASTER_TX_BUF_DISABLE 0 // I2C master doesn't need buffer
#define I2C_MASTER_RX_BUF_DISABLE 0 // I2C master doesn't need buffer
#define HTE501_SENSOR_ADDR 0x44 // I2C address for the HTE501 sensor
#define HTE501_CMD_MEASURE 0x2C06 // Command for measurement
static const char TAG = "HTE501";
void i2c_master_init() {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = I2C_MASTER_SCL_IO,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
i2c_param_config(I2C_MASTER_NUM, &conf);
i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
}
float read_humidity_temperature(float temperature, float humidity) {
uint8_t data[6];
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (HTE501_SENSOR_ADDR << 1) | I2C_MASTER_WRITE, true);
i2c_master_write_byte(cmd, HTE501_CMD_MEASURE >> 8, true);
i2c_master_write_byte(cmd, HTE501_CMD_MEASURE & 0xFF, true);
i2c_master_stop(cmd);
i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
vTaskDelay(50 / portTICK_RATE_MS); // Wait for measurement
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (HTE501_SENSOR_ADDR << 1) | I2C_MASTER_READ, true);
i2c_master_read(cmd, data, 6, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd);
i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
// Convert the data
uint16_t raw_temp = (data[0] << 8) | data[1];
uint16_t raw_hum = (data[3] << 8) | data[4];
temperature = -45 + 175 ((float)raw_temp / 65535.0);
humidity = 100 * ((float)raw_hum / 65535.0);
return ESP_OK;
}
void app_main() {
i2c_master_init();
float temperature, humidity;
while (1) {
if (read_humidity_temperature(&temperature, &humidity) == ESP_OK) {
ESP_LOGI(TAG, "Temperature: %.2f °C", temperature);
ESP_LOGI(TAG, "Humidity: %.2f %%", humidity);
} else {
ESP_LOGE(TAG, "Could not read from sensor");
}
vTaskDelay(2000 / portTICK_RATE_MS); // Delay for 2 seconds
}
}
i2c_master_init()
function configures and initializes the I2C interface. The read_humidity_temperature()
function sends measurement commands to the sensor, retrieves the raw data, and converts it to temperature and humidity values using the sensor's scaling formulas. In the app_main()
function, the temperature and humidity are read in an infinite loop and logged via ESP_LOG. A 2-second delay is added between readings.ESPHome Example
sensor:
- platform: hte501
temperature:
name: "Office Temperature"
humidity:
name: "Office Humidity"
address: 0x40
update_interval: 60s
platform
key specifies the sensor type, and the I2C address is provided under the address
key (e.g., 0x40). The temperature
and humidity
keys define the outputs with user-friendly names like 'Office Temperature' and 'Office Humidity.' The update_interval
key ensures sensor readings are updated every 60 seconds.PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = espidf
monitor_speed = 115200
lib_deps =
esp-idf-esp32
Wire
PlatformIO Example Code
#include <stdio.h>
#include "driver/i2c.h"
#include "esp_log.h"
#define I2C_MASTER_SCL_IO 22 // GPIO number for I2C SCL
#define I2C_MASTER_SDA_IO 21 // GPIO number for I2C SDA
#define I2C_MASTER_NUM I2C_NUM_0 // I2C port number for master
#define I2C_MASTER_FREQ_HZ 100000 // I2C master clock frequency
#define I2C_MASTER_TX_BUF_DISABLE 0 // I2C master doesn't need buffer
#define I2C_MASTER_RX_BUF_DISABLE 0 // I2C master doesn't need buffer
#define HTE501_SENSOR_ADDR 0x44 // I2C address for the HTE501 sensor
#define HTE501_CMD_MEASURE 0x2C06 // Command for measurement
static const char TAG = "HTE501";
void i2c_master_init() {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = I2C_MASTER_SCL_IO,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
i2c_param_config(I2C_MASTER_NUM, &conf);
i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
}
float read_humidity_temperature(float temperature, float humidity) {
uint8_t data[6];
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (HTE501_SENSOR_ADDR << 1) | I2C_MASTER_WRITE, true);
i2c_master_write_byte(cmd, HTE501_CMD_MEASURE >> 8, true);
i2c_master_write_byte(cmd, HTE501_CMD_MEASURE & 0xFF, true);
i2c_master_stop(cmd);
i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
vTaskDelay(50 / portTICK_RATE_MS); // Wait for measurement
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (HTE501_SENSOR_ADDR << 1) | I2C_MASTER_READ, true);
i2c_master_read(cmd, data, 6, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd);
i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
// Convert the data
uint16_t raw_temp = (data[0] << 8) | data[1];
uint16_t raw_hum = (data[3] << 8) | data[4];
temperature = -45 + 175 ((float)raw_temp / 65535.0);
humidity = 100 * ((float)raw_hum / 65535.0);
return ESP_OK;
}
void app_main() {
i2c_master_init();
float temperature, humidity;
while (1) {
if (read_humidity_temperature(&temperature, &humidity) == ESP_OK) {
ESP_LOGI(TAG, "Temperature: %.2f °C", temperature);
ESP_LOGI(TAG, "Humidity: %.2f %%", humidity);
} else {
ESP_LOGE(TAG, "Could not read from sensor");
}
vTaskDelay(2000 / portTICK_RATE_MS); // Delay for 2 seconds
}
}
i2c_master_init()
function configures the I2C master interface with GPIO pins 21 (SDA) and 22 (SCL). The read_humidity_temperature()
function sends measurement commands to the HTE501, retrieves the raw sensor data, and calculates temperature and humidity using the sensor's conversion formulas. The app_main()
function continuously reads and logs temperature and humidity values every 2 seconds.Conclusion
The ESP32 HTE501 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.