Home Code Arduino Uno and SHT40 Digital Humidity Sensor

Arduino Uno and SHT40 Digital Humidity Sensor

by shedboy71

In this example we connect a SHT40 Digital Humidity Sensor from Sensirion to an Arduino Uno

This is the next generation of SHT sensor, in the past we have had examples for sensors such as the SHt31 and now we move on to the 4th generation of these

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, so you can plug it into the 5v of your Arduino without worrying about blowing the thing up – which is always handy.

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.

I used a Qwiic cable – since a few sensors seem to use these but this is optional

Name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
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
sensor shield Expansion IO Board Sensor Shield

 

Schematic/Connection

I used the Adafruit SHT40 sensor and in this case used the Stemma connection

For the STEMMA QT cables, it uses the Qwiic convention:

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

So color coded for ease of use

arduino and sht40

arduino and sht40

Code Example

This example uses a couple of libraries, both of which can be installed using the library manager

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

[codesyntax lang=”cpp”]

#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);
}

[/codesyntax]

Output

Here is what I saw in Serial monitor

Adafruit SHT4x test
Found SHT4x sensor
Serial number 0x1044FA2B
Temperature: 18.84 degrees C
Humidity: 39.21% rH
Read duration (ms): 11
Temperature: 18.84 degrees C
Humidity: 39.13% rH
Read duration (ms): 11

Links

https://learn.adafruit.com/introducing-adafruit-stemma-qt/technical-specs

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

Share

You may also like

Leave a Comment