Home / Wiki / Sensor / Environment
AM2301(temperature+humidity)

Introduction

Temperature and humidity sensor is also named DHT21, compared to the DHT11, this sensor is more accurate and more safety for it was covered with a plastic shell. The sensor measures humidity of the surrounding air by the capacitance and measures the temperature based on the use of a NTC (Negative Temperature Coefficient).

Note: every data sent to the Microcontroller is the last data.

There are three wires out of the sensor, the red one is connected to VCC, the black one is connected to the ground and the rest is the single-wire used to transfer data. Being different from the DS18B20, it doesn’t have the serial number, can’t work together with just a port. If you wanna combine multiple sensors, each one must have its own data pin!


 

Technical data

Typical working voltage: 3.3 to 5V DC

Typical measuring current: 1.5mA

Typical current in sleeping mode: 1.1mA

Sampling period: twice a second

 

Features

The measure range of temperature is -40 to +80℃

The measure range of humidity is 0 to 99.9%RH

Precision: ±3%RH  ±0.5℃

Self calibration

Steady


 

Usage

[code]

Connect data pin to Arduino’s pin 2

Power AM2301 sensor module

 

#include "DHT.h"

#define DHTPIN 2    // modify to the pin we connected

// Uncomment whatever type you're using!

//#define DHTTYPE DHT11   // DHT 11

//#define DHTTYPE DHT22   // DHT 22  (AM2302)

#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V

// Connect pin 2 of the sensor to whatever your DHTPIN is

// Connect pin 4 (on the right) of the sensor to GROUND

// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {

 Serial.begin(9600);

 Serial.println("DHTxx test!");

 dht.begin();

}

void loop() {

 // Reading temperature or humidity takes about 250 milliseconds!

 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

 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");

 }

}

[code]

 

Resource

Program

Datasheet

 


Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0