ESP32 SHTC3 Temperature and Humidity Sensor
Overview
The SHTC3 sensor offers precise temperature and humidity measurements in a compact and energy-efficient package. It is designed for low-power IoT applications and features Sensirion's CMOSens® technology for high accuracy and long-term stability.
About SHTC3 Temperature and Humidity Sensor
The SHTC3, developed by Sensirion, is a high-accuracy digital temperature and humidity sensor optimized for battery-powered applications. With its low power consumption and compact design, it is ideal for IoT devices, consumer electronics, and portable applications.
⚡ Key Features
- Energy-Efficient – Designed for low-power operation, perfect for battery-driven devices.
- High Accuracy & Stability – Delivers precise temperature and humidity readings.
- I²C Communication – Seamless integration with ESP32, Arduino, and embedded systems.
- Compact & Lightweight – Ideal for wearables, smart home devices, and portable monitoring systems.
With its low power consumption and high precision, the SHTC3 is an excellent choice for energy-efficient climate sensing applications. 🚀
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 SHTC3 pinout is as follows:
- VDD: Power supply voltage (1.62V 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
🚫 Communication Failure with ESPHome
Issue: When using the SHTC3 sensor with ESPHome, the following error message appears in the logs: [E][shtcx:059]: Communication with SHTCx failed!
. This issue leads to the sensor failing to provide temperature and humidity data on the dashboard.
Possible causes include the sensor not handling restarts properly, resulting in communication failures.
Solution: The SHTC3 sensor may require a power cycle to re-establish communication. Disconnecting and reconnecting the sensor's power supply can help. Additionally, ensure that the sensor's connections are secure and that the I2C bus is properly configured.
❓ Sensor Misidentified as SHTC1 in ESPHome
Issue: The SHTC3 sensor is incorrectly detected as an SHTC1, leading to improper initialization and data retrieval.
Possible causes include the sensor's identification register returning a value that is not correctly interpreted by the ESPHome integration.
Solution: Update ESPHome to the latest version, as recent updates may have addressed this identification issue. If the problem persists, consider manually specifying the sensor type in the configuration or reaching out to the ESPHome community for further assistance.
🔄 Intermittent I2C Communication with Multiple Device
s
Issue: When the SHTC3 sensor shares the I2C bus with other devices, communication may hang, causing the microcontroller to become unresponsive.
Possible causes include bus contention or insufficient handling of I2C communication timeouts.
Solution: Implement a timeout mechanism in the I2C read operations to prevent indefinite blocking. Additionally, ensure that each device on the I2C bus has a unique address and that proper pull-up resistors are in place.
❌ Initialization Failure After Microcontroller Reset
Issue: Following a microcontroller reset, the SHTC3 sensor fails to initialize, resulting in errors during sensor setup.
Possible causes include the sensor remaining in sleep mode and not responding to initialization commands.
Solution: Modify the initialization sequence to include a wake-up command before any further communication with the sensor. This adjustment ensures that the sensor is active and ready to receive commands after a reset.
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_SHTC3.h"
Adafruit_SHTC3 shtc3;
void setup() {
Serial.begin(115200);
if (!shtc3.begin()) {
Serial.println("Couldn't find SHTC3 sensor!");
while (1) delay(10);
}
Serial.println("SHTC3 initialized");
}
void loop() {
sensors_event_t humidity, temp;
if (!shtc3.getEvent(&humidity, &temp)) {
Serial.println("Failed to read sensor data");
return;
}
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" °C");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println(" %");
delay(2000);
}
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 for I2C master clock /
#define I2C_MASTER_SDA_IO 21 /!< GPIO number for I2C master data /
#define I2C_MASTER_NUM I2C_NUM_0 /!< I2C master port /
#define I2C_MASTER_FREQ_HZ 100000 /!< I2C master clock frequency /
#define SHTC3_SENSOR_ADDR 0x70 /!< SHTC3 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_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf));
return i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0);
}
void read_shtc3_sensor() {
uint8_t data[6];
uint8_t cmd[] = {0x7C, 0xA2}; // Measurement command
i2c_master_write_to_device(I2C_MASTER_NUM, SHTC3_SENSOR_ADDR, cmd, 2, pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(20));
i2c_master_read_from_device(I2C_MASTER_NUM, SHTC3_SENSOR_ADDR, data, 6, 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_shtc3_sensor();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
ESPHome Example
sensor:
- platform: shtc3
temperature:
name: "Room Temperature"
humidity:
name: "Room Humidity"
update_interval: 60s
PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit SHTC3 Library @ ^1.0.0
monitor_speed = 115200
PlatformIO Example Code
#include <Wire.h>
#include "Adafruit_SHTC3.h"
Adafruit_SHTC3 shtc3;
void setup() {
Serial.begin(115200);
if (!shtc3.begin()) {
Serial.println("Couldn't find SHTC3 sensor!");
while (1) delay(10);
}
Serial.println("SHTC3 initialized.");
}
void loop() {
sensors_event_t temp, humidity;
if (!shtc3.getEvent(&humidity, &temp)) {
Serial.println("Failed to read sensor data");
return;
}
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println(" %");
delay(2000);
}
MicroPython Example
from machine import I2C, Pin
from time import sleep
# Initialize I2C interface
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# SHTC3 I2C address
SHTC3_ADDR = 0x70
# Command for measurement
MEASURE_CMD = b'\x7C\xA2'
while True:
try:
i2c.writeto(SHTC3_ADDR, MEASURE_CMD)
sleep(0.02) # Wait for measurement to complete
data = i2c.readfrom(SHTC3_ADDR, 6)
raw_temp = (data[0] << 8) | data[1]
raw_hum = (data[3] << 8) | data[4]
temperature = -45 + 175 (raw_temp / 65535.0)
humidity = 100 (raw_hum / 65535.0)
print("Temperature: {:.2f} °C".format(temperature))
print("Humidity: {:.2f} %".format(humidity))
except Exception as e:
print("Error reading SHTC3: ", e)
sleep(2)
Conclusion
The ESP32 SHTC3 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.