ESP32 SHT85 Temperature and Humidity Sensor
The SHT85 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.
Jump to Code Examples
Quick Links
SHT85 Price
About SHT85 Temperature and Humidity Sensor
The SHT85, developed by Sensirion, is a high-accuracy digital temperature and humidity sensor designed for demanding measurement and test applications. It features a pin-type connector for easy integration and replacement, along with a unique package design that ensures optimal thermal coupling to the environment and decoupling from potential heat sources on the main board. The sensor includes a PTFE membrane that protects the sensor opening from liquids and dust according to IP67 standards, making it suitable for use in harsh environmental conditions. For alternative options, consider the [SHT21](/blog/sht21/) or [SHT30](/blog/sht30/) sensors, which offer different levels of performance and features.SHT85 Sensor Technical Specifications
Below you can see the SHT85 Temperature and Humidity Sensor Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.
- Protocol: I2C
- Operating Voltage: 2.15V to 5.5V
- Temperature Range: -40°C to 105°C
- Humidity Range: 0% to 100% RH
- Temperature Accuracy: ±0.1°C
- Humidity Accuracy: ±1.5% RH
- Interface: I2C
- Dimensions: 19mm x 5.6mm x 3.5mm
SHT85 Sensor Pinout
Below you can see the pinout for the SHT85 Temperature and Humidity Sensor. 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 SHT85 pinout is as follows:
- Pin 1 (SCL): Serial Clock Line for I2C communication.
- Pin 2 (VDD): Power supply voltage (2.15V to 5.5V).
- Pin 3 (VSS): Ground.
- Pin 4 (SDA): Serial Data Line for I2C communication.
Code Examples
Below you can find code examples of SHT85 Temperature and Humidity Sensor with ESP32 in several frameworks:
ESP32 SHT85 Arduino IDE Code Example
Fill in your main
Arduino IDE sketch file with the following code to use the SHT85 Temperature and Humidity Sensor:
#include <Wire.h>
#include "SHTSensor.h"
SHTSensor sht;
void setup() {
Wire.begin();
Serial.begin(9600);
if (sht.init()) {
Serial.println("SHT85 sensor initialized successfully.");
} else {
Serial.println("Failed to initialize SHT85 sensor.");
}
}
void loop() {
if (sht.readSample()) {
Serial.print("Temperature: ");
Serial.print(sht.getTemperature(), 2);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(sht.getHumidity(), 2);
Serial.println(" %");
} else {
Serial.println("Failed to read data from SHT85 sensor.");
}
delay(2000);
}
This Arduino sketch demonstrates how to interface with the SHT85 sensor using the SHTSensor library. It initializes the sensor and reads temperature and humidity data every 2 seconds, printing the results to the Serial Monitor. Ensure that the SHTSensor library is installed in your Arduino IDE.
Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.
ESP32 SHT85 ESP-IDF Code ExampleExample in Espressif IoT Framework (ESP-IDF)
If you're using ESP-IDF to work with the SHT85 Temperature and Humidity Sensor, here's how you can set it up and read data from the sensor. Fill in this code in the main
ESP-IDF file:
#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 SHT85_SENSOR_ADDR 0x44 /*!< SHT85 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_sht85_sensor() {
uint8_t data[6];
uint8_t cmd[] = {0x24, 0x00}; // Command to trigger measurement
i2c_master_write_to_device(I2C_MASTER_NUM, SHT85_SENSOR_ADDR, cmd, 2, pdMS_TO_TICKS(1000));
vTaskDelay(pdMS_TO_TICKS(15));
i2c_master_read_from_device(I2C_MASTER_NUM, SHT85_SENSOR_ADDR, data, 6, pdMS_TO_TICKS(1000));
uint16_t raw_temp = (data[0] << 8) | data[1];
uint16_t raw_humidity = (data[3] << 8) | data[4];
float temperature = -45 + 175 * ((float)raw_temp / 65535.0);
float humidity = 100 * ((float)raw_humidity / 65535.0);
printf("Temperature: %.2f °C, Humidity: %.2f %%\n", temperature, humidity);
}
void app_main() {
ESP_ERROR_CHECK(i2c_master_init());
while (1) {
read_sht85_sensor();
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
This ESP-IDF code demonstrates how to interface with the SHT85 sensor using the I2C protocol. The function `read_sht85_sensor()` sends a command to the sensor to trigger a measurement, reads the raw temperature and humidity data, and converts it into human-readable values. These values are then printed to the console every 2 seconds.
Update the I2C pins (I2C_MASTER_SDA_IO
and I2C_MASTER_SCL_IO
) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.
ESP32 SHT85 ESPHome Code Example
Fill in this configuration in your ESPHome YAML configuration file (example.yml
) to integrate the SHT85 Temperature and Humidity Sensor
sensor:
- platform: sht3x
address: 0x44
temperature:
name: "Living Room Temperature"
humidity:
name: "Living Room Humidity"
update_interval: 60s
This ESPHome configuration defines the SHT85 sensor using the `sht3x` platform. The `address` field specifies the I2C address of the sensor (default: 0x44). Two sensor entities are defined: one for temperature and one for humidity, with user-friendly names like 'Living Room Temperature' and 'Living Room Humidity.' The `update_interval` is set to 60 seconds, ensuring regular updates.
Upload this code to your ESP32 using the ESPHome dashboard or the esphome run
command.
ESP32 SHT85 PlatformIO Code Example
For PlatformIO, make sure to configure the platformio.ini
file with the appropriate environment and libraries, and then proceed with the code.
Configure platformio.ini
First, your platformio.ini
should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
sensirion/SHTSensor @ ^1.0.0
monitor_speed = 115200
ESP32 SHT85 PlatformIO Example Code
Write this code in your PlatformIO project under the src/main.cpp
file to use the SHT85 Temperature and Humidity Sensor:
#include <Wire.h>
#include "SHTSensor.h"
SHTSensor sht(SHTSensor::SHT3X);
void setup() {
Serial.begin(115200);
Wire.begin();
if (sht.init()) {
Serial.println("SHT85 initialized successfully.");
} else {
Serial.println("SHT85 initialization failed.");
}
}
void loop() {
if (sht.readSample()) {
Serial.print("Temperature: ");
Serial.print(sht.getTemperature(), 2);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(sht.getHumidity(), 2);
Serial.println(" %");
} else {
Serial.println("Failed to read SHT85 sensor data.");
}
delay(2000);
}
This PlatformIO code uses the `SHTSensor` library to interact with the SHT85 sensor. The code initializes the sensor, reads temperature and humidity data every 2 seconds, and outputs the results to the Serial Monitor. The library simplifies the communication process and ensures accurate data handling.
Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload
command.
ESP32 SHT85 MicroPython Code Example
Fill in this script in your MicroPython main.py file (main.py
) to integrate the SHT85 Temperature and Humidity Sensor with your ESP32.
from machine import I2C, Pin
from time import sleep
# Initialize I2C communication
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# SHT85 I2C address
SHT85_ADDR = 0x44
# Function to trigger measurement and read data
def read_sht85():
i2c.writeto(SHT85_ADDR, b'\x24\x00') # Trigger measurement
sleep(0.015) # Wait for measurement
data = i2c.readfrom(SHT85_ADDR, 6) # Read 6 bytes of data
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)
return temperature, humidity
while True:
try:
temp, hum = read_sht85()
print("Temperature: {:.2f} °C".format(temp))
print("Humidity: {:.2f} %".format(hum))
except Exception as e:
print("Error reading SHT85:", e)
sleep(2)
This MicroPython script uses the I2C protocol to interface with the SHT85 sensor. It triggers a measurement, reads the raw data, converts it to temperature and humidity, and prints the results to the console every 2 seconds. The `machine.I2C` module is used to handle communication with the sensor.
Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy
.
Conclusion
We went through technical specifications of SHT85 Temperature and Humidity Sensor, its pinout, connection with ESP32 and SHT85 Temperature and Humidity Sensor code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.