Advertisement
Raqeeb_Alnakib

Full code for LESSON #6: DHTxx Sensor With Arduino

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