Home » SHT31 humidity sensor and Raspberry Pi Pico example

SHT31 humidity sensor and Raspberry Pi Pico example

by 2b4a3pico71

In this article we connect a SHT31 humidity sensor to a Raspberry Pi Pico and we will use Circuitpython for development

First of all lets take a look at our sensor

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 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

 

 

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

We use Thonny for development

The following is based on a library from Adafruit , 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

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)

 

Output

Here is what I saw in Thonny REPL window – your results will likely be different

Temperature: 18.9 C
Humidity: 53.4 %

Temperature: 23.3 C
Humidity: 56.0 %

Temperature: 23.7 C
Humidity: 58.8 %

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.