SHT40 Digital Humidity Sensor and ESP32 board example

ESP32 and sht40
ESP32 and sht40

In this example we connect a SHT40 Digital Humidity Sensor to an ESP32

This is the next generation of the SHT sensors series, we have had artilces for sensors such as the SHT31 and now we move on to the 4th generation of these sensors.

First lets look at some information about the sensor from the manufacturer

The SHT40 builds on a completely new and optimized CMOSens® chip that offers reduced power consumption and improved accuracy specifications. With the extended supply voltage range from 1.08 V to 3.6 V, it’s the perfect fit for mobile and battery-driven applications.

Size 1.5 x 1.5 x 0.5 mm3
Output I²C
Supply voltage range 1.08 to 3.6 V
Energy consumption 0.4µA (at meas. rate 1 Hz)
RH operating range 0 – 100% RH
T operating range -40 to +125°C (-40 to +257°F)
RH response time 6 sec (tau63%)

 

Here is the sensor I purchased from the good folks at Adafruit (via Pimoroni in the UK)

adafruit SHT40

Unlike earlier SHT sensors, this sensor has a true I2C interface for easy interfacing with only two wires (plus power and ground!).

Thanks to the voltage regulator and level shifting circuitry that Adafruit have included on the breakout it is also 3V or 5V compliant.

Parts Required

Here are the parts I used

The sensor you can pick up in the $6 price range – you can connect to the sensor using a standard header the classic dupont style jumper wire.

Name Link
ESP32 WeMos Mini D1 LOLIN32 ESP32
SHT40 https://www.adafruit.com/product/4885

https://shop.pimoroni.com/products/adafruit-sensirion-sht40-temperature-humidity-sensor-stemma-qt-qwiic

Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Schematic/Connection

 

The layout below shows an Adafruit Huzzah ESP32, I tried a couple of other ESP32 boards like the Lolin32 as well and they worked just fine

If you have an ESP32 board with a STEMMA QT cables, you can use these:

Black for GND
Red for V+
Blue for SDA
Yellow for SCL

I actually just extended and use this but in the layout I have shown that you can solder a header and just this as well – so you have a choice

ESP32 and sht40
ESP32 and sht40

Code Example

This example uses a couple of libraries, both of which can be installed using the library manager. if you search for the SHT40 one first and you are using a newer version of the Arduino IDE it will install the other one as well – which is useful.

You need the Adafruit library for the SHT40 – https://github.com/adafruit/Adafruit_SHT4X

You also need an I2C support library from the same folks for the library above to work and that is available from – https://github.com/adafruit/Adafruit_BusIO

This is mainly the default example – with a couple of sections of code that were not required removed. I just used the defaults

#include "Adafruit_SHT4x.h"
 
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
 
void setup() 
{
  Serial.begin(115200);
 
  while (!Serial)
    delay(10);     // will pause Zero, Leonardo, etc until serial console opens
 
  Serial.println("Adafruit SHT4x test");
  if (! sht4.begin()) 
  {
    Serial.println("Couldn't find SHT4x");
    while (1) delay(1);
  }
  Serial.println("Found SHT4x sensor");
  Serial.print("Serial number 0x");
  Serial.println(sht4.readSerial(), HEX);
 
  // You can have 3 different precisions, higher precision takes longer
  sht4.setPrecision(SHT4X_HIGH_PRECISION);
 
  // You can have 6 different heater settings
  sht4.setHeater(SHT4X_NO_HEATER);
 
}
 
 
void loop() 
{
  sensors_event_t humidity, temp;
 
  uint32_t timestamp = millis();
  sht4.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
  timestamp = millis() - timestamp;
 
  Serial.print("Temperature: "); 
  Serial.print(temp.temperature); 
  Serial.println(" degrees C");
  Serial.print("Humidity: "); 
  Serial.print(humidity.relative_humidity); 
  Serial.println("% rH");
 
  Serial.print("Read duration (ms): ");
  Serial.println(timestamp);
 
  delay(1000);
}

Output

Here is what I saw in Serial monitor

Temperature: 19.54 degrees C
Humidity: 44.79% rH

Temperature: 19.52 degrees C
Humidity: 44.79% rH

Temperature: 19.54 degrees C
Humidity: 44.82% rH

Temperature: 19.52 degrees C
Humidity: 44.82% rH

Links

https://www.sensirion.com/en/download-center/humidity-sensors/humidity-sensor-sht4x/

 

 

 

SHARE
Previous articleDPS310 barometric pressure sensor and ESP32 board example
Next articleAHT20 Integrated temperature and humidity Sensor and ESP32 board example