ESP32 SHT85 Temperature and Humidity Sensor
Overview
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.
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 and a unique package design that enhances thermal coupling while minimizing heat interference from the main board.
⚡ Key Features
- Superior Accuracy & Stability – Ensures high-precision temperature and humidity readings.
- Pin-Type Connector – Enables easy installation and replacement.
- IP67 Protection – A PTFE membrane shields the sensor from liquids and dust, making it ideal for harsh environments.
- Optimized for Industrial Use – Designed for climate monitoring, industrial testing, and scientific applications.
🔗 Looking for alternatives? Consider:
With its rugged design and precise measurements, the SHT85 is a top choice for industrial and environmental monitoring. 🚀
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 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.
Wiring with ESP32
- Connect VDD to the 3.3V pin on the ESP32.
- Connect VSS 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
❌ Initialization Failure with Arduino Uno
Issue: The SHT85 sensor fails to initialize when connected to an Arduino Uno, displaying the error message: Begin: failed
.
Possible causes include incorrect wiring, improper power supply, or incompatible library versions.
Solution: Verify that the sensor's SCL and SDA lines are correctly connected to the Arduino's A5 and A4 pins, respectively. Ensure the sensor is powered with the appropriate voltage (3.3V or 5V, as per the sensor's specifications). Additionally, confirm that the latest version of the SHT sensor library is installed and compatible with your Arduino IDE.
⚠️ Inconsistent Data Readings Due to I2C Communication Issues
Issue: The SHT85 sensor provides inconsistent temperature and humidity readings, or fails to communicate over the I2C bus.
Possible causes include improper pull-up resistor values on the I2C lines, leading to unreliable communication.
Solution: Ensure that 2.2kΩ pull-up resistors are connected between the SDA and SCL lines and the VCC to maintain proper I2C communication. Verify that the wiring matches the sensor's datasheet recommendations and that the Arduino's power supply is stable.
🔧 Challenges Implementing Multiple SHT85 Sensors on Arduino Mega
Issue: Difficulty arises when attempting to read data from two SHT85 sensors connected to the two I2C buses on an Arduino Mega 2560. The sensors return errors when the Arduino tries to read samples.
Possible causes include both sensors having the same I2C address, leading to address conflicts on the I2C bus.
Solution: Since the SHT85 sensors have fixed I2C addresses, consider using an I2C multiplexer to manage multiple sensors on the same bus. Alternatively, explore the possibility of using software I2C libraries to create additional I2C buses on different pins.
⚡ Communication Errors with SHT85 and USB-8451 Interface
Issue: When interfacing the SHT85 sensor with a USB-8451 module using LabVIEW, communication errors occur, preventing successful data retrieval.
Possible causes include incorrect I2C command sequences or improper configuration of the USB-8451 module.
Solution: Review the SHT85 sensor's datasheet to understand the correct I2C command sequences required for data acquisition. Utilize LabVIEW's built-in examples for I2C communication to ensure proper configuration of the USB-8451 module. Adjusting the timing parameters and ensuring correct pull-up resistors on the I2C lines may also resolve communication issues.
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 "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);
}
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 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));
}
}
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.ESPHome Example
sensor:
- platform: sht3x
address: 0x44
temperature:
name: "Living Room Temperature"
humidity:
name: "Living Room Humidity"
update_interval: 60s
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.PlatformIO Example
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
sensirion/SHTSensor @ ^1.0.0
monitor_speed = 115200
PlatformIO Example Code
#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);
}
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.MicroPython Example
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)
machine.I2C
module is used to handle communication with the sensor.Conclusion
The ESP32 SHT85 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.