Home Code SHT40 Digital Humidity Sensor and Raspberry Pi 4 python example

SHT40 Digital Humidity Sensor and Raspberry Pi 4 python example

by shedboy71

In this example we take a look at the SHT40  Digital Humidity Sensor to a Raspberry Pi 4

This is the next generation of the SHT sensors series, we have had articles for other SHTXX sensors and now we move on to the 4th generation of these sensors.

Description

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

Various parts used in this example

Name Link
SHT40 https://www.adafruit.com/product/4885

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

Raspberry Pi P4 Raspberry Pi 4 Model B 2019 Quad Core 64 Bit WiFi Bluetooth (4GB)Official Original Raspberry Pi 4 Model B Dev Board Kit RAM 2G 4G 8G 4 Core CPU 1.5Ghz
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Schematic/Connection

I connected the SHT40 to the Raspberry Pi 4 like this, an I2C sensor so fairly straightforward

pi and sht40 layout

pi and sht40 layout

Code Example

I used Thonny for development and the library from https://github.com/GreenPonik/GreenPonik_SHT40

You install the library like

> git clone https://github.com/GreenPonik/GreenPonik_SHT40.git
cd GreenPonik_SHT40
pip3 install -r requirements.txt

or 

> pip3 install greenponik-sht40

And here is the code example for the above library

[codesyntax lang=”python”]

import time
from GreenPonik_SHT40.SHT40 import SHT40

if __name__ == "__main__":
    try:
        sht = SHT40()
        while True:
            data = sht.read_sht40()
            print("temperature: %.2f / humidity: %.2f" % (data[0], data[1]))
            time.sleep(1)
    except Exception as e:
        print('An exception occurred: {}'.format(e))

[/codesyntax]

Output

Run this example in Thonny and you will see something like this in the Shell window

%Run sht40.py
temperature: 20.84 / humidity: 41.20
temperature: 20.80 / humidity: 41.33
temperature: 20.75 / humidity: 41.38
temperature: 25.05 / humidity: 45.07
temperature: 25.65 / humidity: 50.06

Links

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

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More