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 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 that will display the temperature and humidity readings on an LCD display.
[codesyntax lang=”cpp”]
#include "DHT.h" #include <LiquidCrystal.h> #define DHTPIN 11 // modify to the pin we connected #define DHTTYPE DHT21 // AM2301 DHT dht(DHTPIN, DHTTYPE); //setup for the LCD keypad shield LiquidCrystal lcd(8, 9, 4, 5, 6, 7); void setup() { Serial.begin(9600); lcd.begin(16,2); Serial.println("DHTxx test!"); dht.begin(); //line 1 - Temperature lcd.setCursor(0,0); lcd.print("Temp: "); //line 2 - Humidity lcd.setCursor(0,1); lcd.print("Hum: "); } 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 { lcd.setCursor(7,0); lcd.print(h); lcd.setCursor(7,1); lcd.print(t); delay(2000); } }
[/codesyntax]
Links
AM2301 DHT21 Capacitance Digital Temperature&Humidity Sensor