0% found this document useful (0 votes)
23 views

#Include #Define Datapin 8 // Defines Pin Number To Which The Sensor Is Connected

This Arduino code tutorial teaches how to read temperature and humidity values from a DHT11/DHT22 sensor using a library. It includes code to define the data pin connected to the sensor, read the sensor values, and print the temperature and humidity to the serial monitor every 2 seconds.

Uploaded by

Dwi Prayoga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

#Include #Define Datapin 8 // Defines Pin Number To Which The Sensor Is Connected

This Arduino code tutorial teaches how to read temperature and humidity values from a DHT11/DHT22 sensor using a library. It includes code to define the data pin connected to the sensor, read the sensor values, and print the temperature and humidity to the serial monitor every 2 seconds.

Uploaded by

Dwi Prayoga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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. }
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. }

You might also like