Raspberry Pi Pico and SHT31 humidity sensor circuitpython example

In this article we connect a SHT31 humidity sensor to a Raspberry Pi Pico running Circuitpython

Sensor Information

The digital SHT3x humidity sensor series takes sensor technology to a new level. As the successor of the SHT2x series it sets the industry standard in humidity sensing.

The SHT3x humidity sensor series consists of a low-cost version with the SHT30 humidity sensor, a standard version with the SHT31 humidity sensor, and a high-end version with the SHT35 humidity sensor. Automotive grade versions are also available.

The SHT3x humidity sensor series combines multiple functions and various interfaces (I2C, analog voltage output) with a applications-friendly, very wide operating voltage range (2.15 to 5.5 V).

The SHT3x humidity sensor is available in both large and small volumes.

The SHT3x builds on a completely new and optimized CMOSens® chip, which allows for increased reliability and improved accuracy specifications.

The SHT3x offers a range of new features, such as enhanced signal processing, two distinctive and user-selectable I2C addresses, an alert mode with programmable humidity and temperature limits, and communication speeds of up to 1 MHz.

Features

Output :  I²C, Voltage Out
Supply voltage range : 2.15 to 5.5 V
Energy consumption : 4.8µW (at 2.4 V, low repeatability, 1 measurement / s)
RH operating range : 0 – 100% RH
T operating range : -40 to +125°C (-40 to +257°F)
RH response time : 8 sec (tau63%)

Parts Required

 

Name Link
Pico Raspberry Pi Pico Development Board
SHT31D SHT31-D digital temperature and humidity sensor module
Connecting cables Aliexpress link

Amazon.com link

Ebay link

 

Schematic/Connection

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

So color coded for ease of use, this layout shows a connection to the module

rp2040 and sht31

Code Example

I used Thonny for development

The following is based on a library , I copied the adafruit_sht31d.mpy library for this device to the lib folder on my Raspberry Pi Pico – https://circuitpython.org/libraries

This is the basic example which comes with the library

[codesyntax lang=”python”]

import time
import board
import adafruit_sht31d
import busio

i2c = busio.I2C(scl=board.GP1, sda=board.GP0) # uses board.SCL and board.SDA

sensor = adafruit_sht31d.SHT31D(i2c)

loopcount = 0
while True:
    print("\nTemperature: %0.1f C" % sensor.temperature)
    print("Humidity: %0.1f %%" % sensor.relative_humidity)
    loopcount += 1
    time.sleep(2)
    # every 10 passes turn on the heater for 1 second
    if loopcount == 10:
        loopcount = 0
        sensor.heater = True
        print("Sensor Heater status =", sensor.heater)
        time.sleep(1)
        sensor.heater = False
        print("Sensor Heater status =", sensor.heater)

[/codesyntax]

Output

Here is what I saw in Thonny REPL window

Temperature: 19.0 C
Humidity: 53.2 %

Temperature: 18.9 C
Humidity: 53.4 %

Temperature: 23.3 C
Humidity: 56.0 %

Temperature: 23.7 C
Humidity: 58.8 %

Links

 

Related posts

Raspberry Pi Pico and MMC5603 3-axis AMR magnetic sensor circuitpython example

Raspberry Pi Pico and LTR329 UV Light Sensor circuitpython example

Raspberry Pi Pico and LTR303 UV Light Sensor circuitpython example

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