Arduino Nano +DHT22
#include “DHT.h”
#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE, 6);
void setup() {
Serial.begin(9600);
Serial.println(“DHTxx test!”);
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// 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();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t”);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t”);
Serial.print(“Heat index: “);
Serial.print(hi);
Serial.println(” *F”);
}
output
DHTxx test!
Humidity: 93.10 % Temperature: 29.90 *C 85.82 *F Heat index: 106.62 *F
Humidity: 93.20 % Temperature: 29.90 *C 85.82 *F Heat index: 106.68 *F
Humidity: 93.30 % Temperature: 29.90 *C 85.82 *F Heat index: 106.74 *F
Humidity: 93.30 % Temperature: 29.90 *C 85.82 *F Heat index: 106.74 *F
Humidity: 93.20 % Temperature: 29.90 *C 85.82 *F Heat index: 106.68 *F
remark ตัว DHT22 ที่ทดสอบ ไม่ค่อยดีนัก
credit:http://arduino-er.blogspot.com/2015/05/arduino-nano-dht11-temperature-humidity.html