Home Code AM2301 example

AM2301 example

by shedboy71
[lebox id="1"]

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

AM2301

AM2301

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 Arduino like this

Sensor Arduino
Red +5V
Black GND
Yellow Digital I/O

 

Code

Since this is basically a packaged up DHT21, you use DHT libraries and here is a code example

[codesyntax lang=”cpp”]

#include "DHT.h"
#define DHTPIN 2    // 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);
 }
}

[/codesyntax]

Links
AM2301 DHT21 Capacitance Digital Temperature&Humidity Sensor

Share
[lebox id="2"]

You may also like