SHT40 Temperature and Humidity Sensor
The SHT40 is a high-accuracy digital temperature and humidity sensor with a compact design and low power consumption. Its I²C interface and wide operating voltage range make it ideal for various environmental monitoring applications.

On this page
SHT40 pinout
The SHT40 uses standard I²C communication with 4 pins, optimized for ultra-low power applications.
| Pin | Type | Description | Notes |
|---|---|---|---|
| VDD | Power | Power supply input (1.08V to 3.6V) | Ultra-low voltage for battery-powered devices |
| GND | Power | Ground connection | Connect to ESP32 ground |
| SDA | Communication | I²C data line | Bidirectional data communication |
| SCL | Communication | I²C clock line | Clock signal from master device |
Standard I²C interface for easy integration
Default I²C address is 0x44
Excellent accuracy: ±0.2°C temp, ±1.8% humidity
Ultra-low voltage (1.08V-3.6V) for battery applications
Low power consumption ideal for IoT devices
Wiring the SHT40 to ESP32
Connect the SHT40 using standard I²C interface for low-power environmental monitoring.
| SHT40 pin | ESP32 pin | Purpose |
|---|---|---|
| VDD | 3.3V | Power supply (1.08V to 3.6V supported) |
| GND | GND | Ground connection |
| SDA | GPIO21 | I²C data line (default SDA) |
| SCL | GPIO22 | I²C clock line (default SCL) |
GPIO21/22 are default I²C pins on ESP32
I²C address is 0x44 (fixed)
Add 10kΩ pull-up resistors on SDA/SCL if needed
Optimized for ultra-low power consumption
SHT40 code examples
SHT40 Arduino example
Copy#include <Wire.h>
#include "Adafruit_SHT4x.h"
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
void setup() {
Serial.begin(115200);
if (!sht4.begin()) {
Serial.println("Couldn't find SHT4x");
while (1) delay(10);
}
Serial.println("Found SHT4x sensor");
}
void loop() {
sensors_event_t humidity, temp;
sht4.getEvent(&humidity, &temp);
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println(" %");
delay(2000);
}This Arduino code initializes the SHT40 sensor using the Adafruit SHT4x library. In the setup() function, it sets up serial communication and attempts to initialize the sensor. If the sensor is not found, it prints an error message and halts execution. In the loop() function, it reads temperature and humidity data from the sensor and prints the values to the Serial Monitor every two seconds.
SHT40 ESP-IDF example
Copy// Requires the esp-idf-lib SHT4x driver from the ESP Component Registry:
// idf.py add-dependency "esp-idf-lib/sht4x^1.0.7"
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sht4x.h"
#define SDA_GPIO GPIO_NUM_21
#define SCL_GPIO GPIO_NUM_22
void app_main(void)
{
ESP_ERROR_CHECK(i2cdev_init());
sht4x_t dev;
memset(&dev, 0, sizeof(sht4x_t));
ESP_ERROR_CHECK(sht4x_init_desc(&dev, 0, SDA_GPIO, SCL_GPIO));
ESP_ERROR_CHECK(sht4x_init(&dev));
while (1) {
float temperature, humidity;
if (sht4x_measure(&dev, &temperature, &humidity) == ESP_OK)
printf("Temp %.2f C, Hum %.2f%%\n", temperature, humidity);
else
printf("Could not read data from sensor\n");
vTaskDelay(pdMS_TO_TICKS(2000));
}
}ESP-IDF ships no SHT40 driver of its own, so this example uses the maintained esp-idf-lib SHT4x driver from the ESP Component Registry. Install it into your project first with idf.py add-dependency "esp-idf-lib/sht4x^1.0.7", then build as usual.
sht4x_measure() performs one high-repeatability measurement (the driver handles the command, timing and CRC check) and returns temperature in Celsius and relative humidity in percent. i2cdev_init() sets up the shared I2C layer used by all esp-idf-lib drivers. The same code works for every SHT4x family member, including the SHT41 and SHT45.
SHT40 ESPHome example
Copyi2c:
sda: GPIO21
scl: GPIO22
sensor:
- platform: sht4x
temperature:
name: "SHT40 Temperature"
humidity:
name: "SHT40 Humidity"
address: 0x44
update_interval: 2sThis ESPHome configuration sets up the SHT40 sensor to measure temperature and humidity over I²C. The sensor readings update every two seconds, and the default I²C address is 0x44.
SHT40 PlatformIO example
Copy[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit SHT4x Library
wire
monitor_speed = 115200#include <Wire.h>
#include "Adafruit_SHT4x.h"
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
void setup() {
Serial.begin(115200);
if (!sht4.begin()) {
Serial.println("Couldn't find SHT4x");
while (1) delay(10);
}
Serial.println("Found SHT4x sensor");
}
void loop() {
sensors_event_t humidity, temp;
sht4.getEvent(&humidity, &temp);
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println(" %");
delay(2000);
}This PlatformIO code initializes the SHT40 sensor using the Adafruit SHT4x library. The sensor communicates over I²C, and the program continuously reads and prints temperature and humidity values to the Serial Monitor every two seconds.
SHT40 MicroPython example
Copyfrom machine import I2C, Pin
from time import sleep, sleep_ms
# The SHT40 speaks plain I2C - no driver needed (SDA=GPIO21, SCL=GPIO22)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
SHT4X_ADDR = 0x44
while True:
i2c.writeto(SHT4X_ADDR, b'\xfd') # high-precision measurement command
sleep_ms(10) # wait for the measurement
data = i2c.readfrom(SHT4X_ADDR, 6) # T MSB, T LSB, CRC, RH MSB, RH LSB, CRC
temp_raw = (data[0] << 8) | data[1]
hum_raw = (data[3] << 8) | data[4]
temperature = -45 + 175 * temp_raw / 65535
humidity = -6 + 125 * hum_raw / 65535
humidity = min(max(humidity, 0), 100) # clamp per the datasheet
print("Temperature: {:.2f} C".format(temperature))
print("Humidity: {:.2f} %".format(humidity))
sleep(2)The SHT40 needs no driver - the example sends the SHT4x high-precision measurement command (0xFD), waits 10 ms, reads six bytes and applies the datasheet conversions (the humidity formula is -6 + 125 x raw / 65535, clamped to 0-100%). The sensor sits at the family's fixed address 0x44 on the default I2C pins.
SHT40 specifications
About the SHT40
The SHT40 is Sensirion’s 4th-generation digital temperature and humidity sensor, the successor to the hugely popular SHT3x line. It measures both values with a single factory-calibrated chip and reports them over plain I2C at address 0x44 - no analog reading, no calibration step, no external components beyond the bus pull-ups most boards already have.
Two numbers explain why it shows up in so many battery-powered builds: it runs from as little as 1.08 V, and it draws about 0.4 uA at one measurement per second. In practice that means it can sit directly on a coin cell or LiFePO4 supply without a regulator and log for months. Accuracy of ±0.2 degC and ±1.8 %RH is more than enough for HVAC, weather stations and room monitoring; just note the response time (2 s for temperature, 4 s for humidity), so it is not the right pick for fast-changing airflows.
A few practical details: the I2C address is fixed, so running two SHT40s on one bus needs a multiplexer; the on-chip heater can dry out the humidity element after long exposure to condensation; and the same code drives the whole SHT4x family, so upgrading to an SHT45 for ±0.1 degC accuracy later is a drop-in change.
SHT40 troubleshooting
Sensor Initialization Failure
›
Issue: The sensor fails to initialize, and no data is received.
Solution: Ensure that the SDA and SCL lines are correctly connected to the corresponding GPIO pins on the microcontroller. Verify that the power supply voltage is within the specified range (1.08V to 3.6V). Check for proper pull-up resistors on the SDA and SCL lines if required by your specific setup. Confirm that the I²C address used in your code matches the sensor's default address (0x44).
Incorrect Temperature or Humidity Readings
›
Issue: The sensor provides inaccurate temperature or humidity readings.
Solution: Avoid placing the sensor near heat sources or in direct sunlight. Ensure that the sensor is not exposed to condensation or water droplets. Allow the sensor to stabilize after power-up, as recommended by the manufacturer. Calibration may be necessary for precise measurements.
Intermittent I²C Communication
›
Issue: Communication with the sensor is intermittent or fails.
Solution: Verify that the correct I²C address (0x44) is used in your code. Ensure that the timing requirements for the I²C signals are met. Check the integrity of the SDA and SCL connections and ensure that appropriate pull-up resistors are in place if not already included on the sensor module.
Resources
Similar sensors





