cactus.io logo

How to Hookup Arduino to the AM2302 Temperature - Humidity Sensor

Overview

The AM2302 is the DHT22 sensor mounted inside a protective plastic case. It has three wires (PWR, GND and Data) ready for connecting to the Arduino. There is a pull up resistor included in the sensor so we do not need to install one when connecting to the Arduino.

Images

AM2302 Humidty Temperature Sensor
Note: Images shown on this page are not to scale.

Hardware and Software Parts List

  • Arduino Board
  • AM2302 Sensor. We used the Adafruit PN 393 AM2302 Sensor
  • 10K Pullup Resistor
  • Breadboard hookup wires
  • USB Cable to suite Arduino

Data Sheets


Wiring diagram for connecting AM2302 Sensor to Arduino Board

No pullup resistor is required as it is already installed between the PWR and Data wires inside the sensor.

Connect Arduino to AM2302 Temperature Sensor Hookup

Software

To test this sensor we can use sample sketch shown below. You can download the sketch file and the cactus.io AM2302 library to communicate with the sensor. It reads the AM2302 every 3 seconds and prints the results to the console on the computer connected to the USB port on the Arduino.

We are using digital pin 2 to connect to the data pin on the sensor. If you are using a different digital pin then you will need to change the pin number defined on line 6 in the sketch code.

Software Limitations
  • Supports only one sensor on the data pin.
  • Blocking Code - Nothing else is done until a sensor read is complete
AM2302 Sample Sketch
Download as (Arduino Sketch) (Text File)
1
// Example sketch for AM2302 humidity - temperature sensor
2
// Written by cactus.io, with thanks to Adafruit for bits of their library. public domain
3
4
#include <cactus_io_AM2302.h>
5
6
#define AM2302_PIN 2 // what pin on the arduino is the AM2302 data line connected to
7
8
// For details on how to hookup the AM2302 sensor to the Arduino then checkout this page
9
// http://cactus.io/hookups/sensors/temperature-humidity/am2302/hookup-arduino-to-am2302-temp-humidity-sensor
10
11
// Initialize AM2302 sensor for normal 16mhz Arduino.
12
AM2302 dht(AM2302_PIN);
13
// Note: If you are using a board with a faster processor than 16MHz then you need
14
// to declare an instance of the AM2302 using
15
// AM2302 dht(AM2302_DATA_PIN, 30);
16
// The additional parameter, in this case here is 30 is used to increase the number of
17
// cycles transitioning between bits on the data and clock lines. For the
18
// Arduino boards that run at 84MHz the value of 30 should be about right.
18
19
void setup(){
20
Serial.begin(9600);
21
Serial.println("AM2302 Humidity - Temperature Sensor");
22
Serial.println("RH\tTemp (C)\tTemp (F)\tHeat Index (C)\tHeat Index (F)");
23
24
dht.begin();
25
}
26
27
void loop(){
28
// Reading temperature or humidity takes about 250 milliseconds!
29
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
30
dht.readHumidity();
31
dht.readTemperature();
32
33
// Check if any reads failed and exit early (to try again).
34
if (isnan(dht.humidity) || isnan(dht.temperature_C)) {
35
Serial.println("AM2302 sensor read failure!");
36
return;
37
}
38
39
Serial.print(dht.humidity); Serial.print(" %\t\t");
40
Serial.print(dht.temperature_C); Serial.print(" *C\t");
41
Serial.print(dht.temperature_F); Serial.print(" *F\t");
42
Serial.print(dht.computeHeatIndex_C()); Serial.print(" *C\t");
43
Serial.print(dht.computeHeatIndex_F()); Serial.println(" *F");
44
45
// Wait a few seconds between measurements. The AM2302 should not be read at a higher frequency of
46
// about once every 2 seconds. So we add a 3 second delay to cover this.
47
delay(3000);
48
}

Sketch Console Output

Connect Arduino to AM2302 Humidity - Temperature Sensor

License