In this video lesson we show you how to wire up the most excellent DHT11 Temperature and Humidity Sensor. The video above takes you through the build and coding. Below, for your convenience is the code developed in the video
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT11 float tempF; float tempC; float humidity; int setTime=500; int dt=1000; DHT TH(DHTPIN,DHTTYPE); void setup() { // put your setup code here, to run once: Serial.begin(115200); TH.begin(); delay(setTime); } void loop() { // put your main code here, to run repeatedly: tempC=TH.readTemperature(); tempF=TH.readTemperature(true); humidity=TH.readHumidity(); Serial.print(tempF); Serial.print(" Degrees F, "); Serial.print(tempC); Serial.print(" Degrees C, "); Serial.print(humidity); Serial.println("% Humidity"); delay(dt); } |