源自http://learning.grobotronics.com/arduino-humidity-sensor-dht11-tutorial.html
Arduino Humidity Sensor DHT11 Tutorial
Description
The dht11 humidity sensor is an economic way to sense the humidity of the air in arduino projects.
- Good for 20-80% humidity readings with 5% accuracy
- 3 to 5V power and I/O
- 2.5mA max current use during conversion (while requesting data)
Hardware Required:
Wiring
To wire your Humidity DHT11 Sensor to your Arduino, connect the following pins:
- DHT11 Pin 1 (Vss) --> Arduino +5V
- DHT11 Pin 2 (Signal) --> Arduino Pin 2
- DHT11 Pin 2 (Signal) --> Arduino +5V via Resistor 4.7K
- DHT11 Pin 3 --> N/C
- DHT11 Pin 4 (GND) --> Arduino Ground
Example Code
#include <dht11.h> dht11 DHT11; #define DHT11PIN 2 void setup() { Serial.begin(9600); Serial.println("DHT11 TEST PROGRAM "); Serial.print("LIBRARY VERSION: "); Serial.println(DHT11LIB_VERSION); Serial.println(); } double Fahrenheit(double celsius) { return 1.8 * celsius + 32; } void loop() { Serial.println("\n"); int chk = DHT11.read(DHT11PIN); Serial.print("Read sensor: "); switch (chk) { case 0: Serial.println("OK"); break; case -1: Serial.println("Checksum error"); break; case -2: Serial.println("Time out error"); break; default: Serial.println("Unknown error"); break; } Serial.print("Humidity (%): "); Serial.println((float)DHT11.humidity, 2); Serial.print("Temperature (oC): "); Serial.println((float)DHT11.temperature, 2); Serial.print("Temperature (oF): "); Serial.println(Fahrenheit(DHT11.temperature), 2); delay(2000); }
沒有留言:
張貼留言