1.
/* DHT11/ DHT22 Sensor Temperature and Humidity Tutorial
2. * Program made by Dejan Nedelkovski,
3. * www.HowToMechatronics.com
4. */
5. /*
6. * You can find the DHT Library from Arduino official website
7. * https://playground.arduino.cc/Main/DHTLib
8. */
9.
10. #include <dht.h>
11.
12. #define dataPin 8 // Defines pin number to which the sensor is connected
13. dht DHT; // Creats a DHT object
14.
15. void setup() {
16. Serial.begin(9600);
17. }
18. void loop() {
19. int readData = DHT.read22(dataPin); // Reads the data from the sensor
20. float t = DHT.temperature; // Gets the values of the temperature
21. float h = DHT.humidity; // Gets the values of the humidity
22.
23. // Printing the results on the serial monitor
24. Serial.print("Temperature = ");
25. Serial.print(t);
26. Serial.print(" *C ");
27. Serial.print(" Humidity = ");
28. Serial.print(h);
29. Serial.println(" % ");
30.
31. delay(2000); // Delays 2 secods, as the DHT22 sampling rate is 0.5Hz
32. }
LCD
1. /* DHT11/ DHT22 Sensor Temperature and Humidity Tutorial
2. * Program made by Dejan Nedelkovski,
3. * www.HowToMechatronics.com
4. */
5. /*
6. * You can find the DHT Library from Arduino official website
7. * https://playground.arduino.cc/Main/DHTLib
8. */
9.
10. #include <LiquidCrystal.h> // includes the LiquidCrystal Library
11. #include <dht.h>
12.
13.
14. #define dataPin 8
15. LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5,
d6, d7)
16. dht DHT;
17.
18. void setup() {
19. lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the
dimensions (width and height) of the display
20. }
21.
22. void loop() {
23. int readData = DHT.read22(dataPin);
24. float t = DHT.temperature;
25. float h = DHT.humidity;
26. lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will
be displayed
27. lcd.print("Temp.: "); // Prints string "Temp." on the LCD
28. lcd.print(t); // Prints the temperature value from the sensor
29. lcd.print(" C");
30. lcd.setCursor(0,1);
31. lcd.print("Humi.: ");
32. lcd.print(h);
33. lcd.print(" %");
34. delay(2000);
35. }