Home Circuitpython Adafruit Feather M0 and SHT31 humidity sensor circuitpython example

Adafruit Feather M0 and SHT31 humidity sensor circuitpython example

by shedboy71

In this example we connect a SHT31 humidity sensor to an Adafruit Feather M0 running Circuitpython

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

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

This is the sensor I bought

Parts Required

 

Name Link
Adafruit Feather M0 Express Adafruit (PID 3403) Feather M0 Express – Designed for CircuitPython – ATSAMD21 Cortex M0
SHT31 SHT31-D Humidity Sensor Module Breakout
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Schematic/Connection

feather and SHT31 layout

feather and SHT31 layout

Code Example

I used Mu for development

The following is based on a library , I copied the SHT31D library to the lib folder on my Feather M0 Express – https://circuitpython.org/libraries

[codesyntax lang=”python”]

import time
import board
import busio
import adafruit_sht31d

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, 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 Mu REPL window

Temperature: 20.7 C
Humidity: 39.1 %

Temperature: 20.6 C
Humidity: 39.2 %

Temperature: 20.6 C
Humidity: 39.2 %

Temperature: 21.1 C
Humidity: 39.5 %

Links

Download center

You may also like

Leave a Comment