Raqeeb_Alnakib

Full code for LESSON #7: DHT22 Sensor With Arduino

Mar 8th, 2020
4,665
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Please Support Us On:
  4.  
  5. https://global-prog.com
  6.  
  7. */
  8.  
  9. #include <DHT.h>  // Include DHT library.
  10.  
  11. #define DHT_TYPE DHT22   // DHT22 SENSOR TYPE
  12.  
  13. #define DHT_PIN 3   // IN THIS LINE WE DEFINE THE DHT PIN = 3
  14.  
  15. DHT DHT_SENSOR (DHT_PIN,DHT_TYPE);
  16.  
  17. float Humidity = 0;  // Initial the humidity container variable
  18.  
  19. float Temp_C = 0;  // Initial the Temperature Celsius
  20.  
  21. float Temp_F = 0;  // Initial the Temperature Fahrenheit
  22.  
  23. void setup() {
  24.  
  25. Serial.begin(9600);   // Begin the serial monitor with baud rate of 9600
  26.  
  27. DHT_SENSOR.begin();   // Prepare the DHT sensor to measure the temperature and humidity
  28.  
  29. delay(1000);  // Wait for 1 Second
  30. }
  31.  
  32. void loop() {
  33.  
  34. Humidity = DHT_SENSOR.readHumidity();  //  Read the Humidity from the sensor
  35.  
  36. delay(1000); // Wait for 1 Second
  37.  
  38. Temp_C = DHT_SENSOR.readTemperature();  // Read Temperature in Celsius
  39.  
  40. Temp_F = DHT_SENSOR.readTemperature(true);  // Read Temperature in Fahrenheit
  41.  
  42. Serial.println("Temerature In ℃ = ");
  43.  
  44. Serial.println(Temp_C);
  45.  
  46. Serial.println("\nTemerature In ℉ = ");
  47.  
  48. Serial.println(Temp_F);
  49.    
  50. Serial.println("\nHumidity = ");
  51.  
  52. Serial.println(Humidity);
  53.  
  54. Serial.println("\n");
  55.  
  56. }
RAW Paste Data