Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- LIB: https://github.com/ringerc/Arduino-DHT22
- DHT22: http://dx.com/p/dht22-2302-digital-temperature-and-humidity-sensor-module-184847
- http://learn.adafruit.com/dht
- ZAPOJENI: http://www.manuel-esteban.com/wp-content/uploads/2013/03/Arduino-et-DHT22_bb.jpg
- DHT22
- Low cost
- 3 to 5V power and I/O
- 2.5mA max current use during conversion (while requesting data)
- Good for 0-100% humidity readings with 2-5% accuracy
- Good for -40 to 125°C temperature readings ±0.5°C accuracy
- No more than 0.5 Hz sampling rate (once every 2 seconds)
- Body size 15.1mm x 25mm x 7.7mm
- 4 pins with 0.1" spacing
- */
- #include <DHT22.h>
- // Connect a 4.7K resistor between VCC and the data pin (strong pullup)
- #define DHT22_PIN 8
- // Setup a DHT22 instance
- DHT22 myDHT22(DHT22_PIN);
- void setup(void)
- {
- Serial.begin(9600);
- }
- void loop(void)
- {
- DHT22_ERROR_t errorCode;
- // The sensor can only be read from every 1-2s, and requires a minimum
- // 2s warm-up after power-on.
- delay(5000);
- //Serial.print("Requesting data...");
- errorCode = myDHT22.readData();
- switch(errorCode)
- {
- case DHT_ERROR_NONE:
- //Serial.print("Got Data ");
- Serial.print(myDHT22.getTemperatureC());
- Serial.print("C ");
- Serial.print(myDHT22.getHumidity());
- Serial.println("%");
- break;
- case DHT_ERROR_CHECKSUM:
- Serial.print("check_sum_error ");
- Serial.print(myDHT22.getTemperatureC());
- Serial.print("C ");
- Serial.print(myDHT22.getHumidity());
- Serial.println("%");
- break;
- case DHT_BUS_HUNG:
- Serial.println("BUS_Hung");
- break;
- case DHT_ERROR_NOT_PRESENT:
- Serial.println("Not_Present");
- break;
- case DHT_ERROR_ACK_TOO_LONG:
- Serial.println("ACK_time_out");
- break;
- case DHT_ERROR_SYNC_TIMEOUT:
- Serial.println("Sync_Timeout");
- break;
- case DHT_ERROR_DATA_TIMEOUT:
- Serial.println("Data_Timeout");
- break;
- case DHT_ERROR_TOOQUICK:
- Serial.println("Polled_to_quick");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment