Skip to content

Adafruit Temperature Humidity Sensor

Beau edited this page Feb 27, 2023 · 2 revisions

pip3 installs:

  • Si7021 (adafruit-circuitpython-si7021)
  • AHT20 (adafruit-circuitpython-ahtx0)
  • SHT40 (adafruit-circuitpython-sht4x)
  • HTU31-D (?)

Si7021

import board
import adafruit_si7021

sensor = adafruit_si7021.SI7021(board.I2C())

SHT40

import board
import adafruit_sht4x

sensor = adafruit_sht4x.SHT4x(board.I2C())

AHT20

import board
import adafruit_ahtx0

sensor = adafruit_ahtx0.AHTx0(board.I2C())

Example sensor Read

print('Temperature: %.2f\xb0F, Humidity: %.2f%%'\
%(sensor.temperature * 1.8 + 32, sensor.relative_humidity))

Temperature: 72.98°F, Humidity: 40.12%

Multi-sensor Test

import board
import adafruit_si7021
import adafruit_ahtx0
import adafruit_sht4x

print("Loading sensors...")

sensors = []
sensors.append(adafruit_si7021.SI7021(board.I2C()))
sensors.append(adafruit_ahtx0.AHTx0(board.I2C()))
sensors.append(adafruit_sht4x.SHT4x(board.I2C()))

def temp(s):
 print('Temperature: %.2f F, Humidity: %.2f%%'%(s.temperature * 1.8 + 32, s.relative_humidity))

def readTemps():
 for i in range(3): temp(sensors[i])

print("Reading sensors...")

readTemps()

Temperature: 72.57 F, Humidity: 37.67%

Temperature: 74.56 F, Humidity: 38.74%

Temperature: 73.58 F, Humidity: 39.41%

Clone this wiki locally