Home » ESP32 and AM2301 sensor example

ESP32 and AM2301 sensor example

by shedboy71

AM2301 output calibrated digital signal. It applys exclusive digital-signal-collecting-technique and humidity sensing technology, assuring its reliability and stability. Its sensing elements is connected with 8-bit single-chip computer. Every sensor of this model is temperature compensated and calibrated in accurate calibration chamber and the calibration-coefficient is saved in type of programme in OTP memory, when the sensor is detecting, it will cite
coefficient from memory. Small size & low consumption & long transmission distance(100m) enable AM2301 to be suited in all kinds of harsh application occasions.

The AM2301  is a wired version of the DHT21, in a large plastic body.

Specifications:

  • Type: AM2301
  • Accuracy resolution: 0.1
  • Measurement range: 0-100%RH
  • Temperature measurement range: -40℃ ~ +80℃
  • Humidity measurement precision: ±3%RH
  • Temperature measurement precision: ±0.5℃

This Sensor has 3 wires, connect these wires to your ESP32 module like this

Sensor LOLIN32
Red +3v3
Black GND
Yellow Pin15

 

Code

This example uses 2 adafruit libraries

https://github.com/adafruit/DHT-sensor-library

and

https://github.com/adafruit/Adafruit_Sensor

[cpp]

#include "DHT.h"
#define DHTPIN 15    // modify to the pin we connected

#define DHTTYPE DHT21   // AM2301 

DHT dht(DHTPIN, DHTTYPE);

void setup() 
{
 Serial.begin(9600); 
 Serial.println("DHTxx test!");
 dht.begin();
}

void loop() 
{
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 // check if returns are valid, if they are NaN (not a number) then something went wrong!
 if (isnan(t) || isnan(h)) 
 {
   Serial.println("Failed to read from DHT");
 } 
 else 
 {
   Serial.print("Humidity: "); 
   Serial.print(h);
   Serial.print(" %\t");
   Serial.print("Temperature: "); 
   Serial.print(t);
   Serial.println(" *C");
   delay(2000);
 }
}

[/cpp]

Output

Open the serial monitor

Humidity: 51.10 % Temperature: 20.70 *C
Humidity: 57.20 % Temperature: 20.70 *C
Humidity: 62.40 % Temperature: 20.70 *C
Humidity: 67.20 % Temperature: 20.90 *C
Humidity: 71.20 % Temperature: 21.00 *C
Humidity: 74.50 % Temperature: 21.20 *C
Humidity: 72.80 % Temperature: 21.30 *C

Links

AM2301 100% New Digital-output Relative Humidity & Temperature Sensor/Module

You may also like

2 comments

ESP32 กับ AM2301 (DHT21) | Samong IOT 11th August 2019 - 11:05 am

[…] เวบไซต์อ้างอิง  : http://www.esp32learning.com/code/esp32-and-am2301-sensor-example.php […]

ESP32 กับ AM2301 (DHT21) | SMT20 IOT 18th February 2020 - 4:44 pm

[…] (อ้างอิงตามเวบไซต์ http://www.esp32learning.com/code/esp32-and-am2301-sensor-example.php) […]

Leave a Comment

Adblock Detected

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