DIGITAL HUMIDITY AND TEMPERATURE SENSOR DHT22

All pictures are for illustrative purposes only.

PID# 7375

13,50 CA$ EACH
Rupture de stock
Variants:
DHT11
DHT20
DHT22
Quantité

Request a large quantity quote

Description

Features:

  • 3.3-6V Input
  • 1-1.5mA measuring current
  • 40-50 uA standby current
  • Humidity from 0-100% RH
  • -40 - 80 degrees C temperature range
  • +-2% RH accuracy
  • +-0.5 degrees C
  1. #include"DHT.h"
  2.  
  3. #define DHTPIN 2// what pin we're connected to
  4. #define DHTTYPE DHT22 // DHT 22 (AM2302)
  5. #define fan 4
  6.  
  7. int maxHum =60;
  8. int maxTemp =40;
  9.  
  10. DHT dht(DHTPIN, DHTTYPE);
  11.  
  12. void setup(){
  13. pinMode(fan, OUTPUT);
  14. Serial.begin(9600);
  15. dht.begin();
  16. }
  17.  
  18. void loop(){
  19. // Wait a few seconds between measurements.
  20. delay(2000);
  21.  
  22. // Reading temperature or humidity takes about 250 milliseconds!
  23. // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  24. float h = dht.readHumidity();
  25. // Read temperature as Celsius
  26. float t = dht.readTemperature();
  27. // Check if any reads failed and exit early (to try again).
  28. if(isnan(h)|| isnan(t)){
  29. Serial.println("Failed to read from DHT sensor!");
  30. return;
  31. }
  32. if(h > maxHum || t > maxTemp){
  33. digitalWrite(fan, HIGH);
  34. }else{
  35. digitalWrite(fan, LOW);
  36. }
  37. Serial.print("Humidity: ");
  38. Serial.print(h);
  39. Serial.print(" %t");
  40. Serial.print("Temperature: ");
  41. Serial.print(t);
  42. Serial.println(" *C ");
  43.  
  44. }