Home Circuitpython Adafruit Feather M0 and AM2302 humidity & temperature sensor circuitpython example

Adafruit Feather M0 and AM2302 humidity & temperature sensor circuitpython example

by shedboy71

In this example we connect a AM2302 (DHT12) humidity & temperature sensor to an Adafruit Feather M0 running Circuitpython

Sensor Information

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

The AM2302 is a wired version of the DHT22, compared to the DHT11, the sensor is more precise, accurate and has a bigger range of temperature/humidity.

AM2302 capacitive humidity sensing digital temperature and humidity module is one that contains the compound has been calibrated digital signal output of the temperature and humidity sensors.

Application of a dedicated digital modules collection technology and the temperature and humidity sensing technology, to ensure that the product has high reliability and excellent long-term stability.

The sensor includes a capacitive sensor wet components and a high-precision temperature measurement devices, and connected with a high-performance 8-bit microcontroller. The product has excellent quality, fast response, strong anti-jamming capability, and high cost.

Each sensor is extremely accurate humidity calibration chamber calibration. The form of procedures, the calibration coefficients stored in the microcontroller, the sensor within the processing of the heartbeat to call these calibration coefficients. Standard single-bus interface, system integration quick and easy.

Small size, low power consumption, signal transmission distance up to 20 meters, making it the best choice of all kinds of applications and even the most demanding applications

Applications

HVAC, dehumidifier, testing and inspection equipment, consumer goods, automotive, automatic control, data loggers, home appliances, humidity regulator, medical, weather stations, and other humidity measurement and control and so on.

Features

Ultra-low power, the transmission distance, fully automated calibration, the use of capacitive humidity sensor, completely interchangeable, standard digital single-bus output, excellent long-term stability, high accuracy temperature measurement devices.

Special instructions of the single-bus communication:

1.Typical application circuit recommended in the short cable length of 30 meters on the 5.1K pull-up resistor pullup resistor according to the actual situation of lower than 30 m.
2.With 3.3V supply voltage, cable length shall not be greater than 100cm. Otherwise, theline voltage drop will lead to the sensor power supply, resulting in measurement error.
3.Read the sensor minimum time interval for the 2S; read interval is less than 2S, may cause the temperature and humidity are not allowed or communication is unsuccessful, etc..
4.Temperature and humidity values are each read out the results of the last measurement For real-time data that need continuous read twice, we recommend repeatedly to read sensors, and each read sensor interval is greater than 2 seconds to obtain accurate the data.

This is an example of the sensor/module, there are many different options.

Parts Required

 

Name Link
Adafruit Feather M0 Express Amazon link

Ebay link

AM2302 Humidity Sensor Module Aliexpress link

Amazon link

Connecting cables Aliexpress product link

Amazon.com link

Ebay link

 

Schematic/Connection

This is not the exact same module but the wiring is the same

Code Example

I used Mu for development

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

This is the basic example which comes with the library

[codesyntax lang=”python”]

import time
 
import adafruit_dht
import board
 
dht = adafruit_dht.DHT22(board.D6)
 
while True:
    try:
        temperature = dht.temperature
        humidity = dht.humidity
        # Print what we got to the REPL
        print("Temp: {:.1f} *C \t Humidity: {}%".format(temperature, humidity))
    except RuntimeError as e:
        # Reading doesn't always work! Just print error and we'll try again
        print("Reading from DHT failure: ", e.args)
 
    time.sleep(1)

[/codesyntax]

Output

Here is what I saw in Mu REPL window

Temp: 27.2 *C Humidity: 42.6%
Temp: 27.2 *C Humidity: 42.6%
Temp: 27.3 *C Humidity: 51.0%
Temp: 27.3 *C Humidity: 51.0%
Temp: 28.6 *C Humidity: 67.4%
Temp: 28.6 *C Humidity: 67.4%

Links

 

You may also like

Leave a Comment