Raqeeb_Alnakib

Full code for LESSON #6: DHT11 Sensor With Arduino

Mar 8th, 2020
4,729
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Please Support Us On:
  3.  
  4. https://global-prog.com
  5.  
  6. */
  7.  
  8. #include <DHT.h>  // Include DHT library.
  9.  
  10. #define DHT_TYPE DHT11   // DHT11 SENSOR TYPE
  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. }
RAW Paste Data