How To DHT11 With LED

Required Hardware

For users who do not have Hackerspace Karachi Arduino Kit v1.0

  • Arduino Board
  • Breadboard
  • Resistor 220 ohm
  • LED
  • DHT11
  • Hook-up Wires

Circuit

For users who do not have Hackerspace Karachi Arduino Kit v1.0

Schematic

Code

                    

1. /*
2. DHT11 with LED
3.
4. This example shows how to use DHT11 with LED.
5.
6. The circuit:
7. – LED
8. Anode connected to digital pin 4.
9. Cathode connected to Ground.
10. – DHT11
11. connected to digital pin of Arduino
12.
13. http://hackerspacekarachi.org/
14. */
15. #include <dht11.h>
16. #define DHT11PIN 7 //connected to digital pin 7
17.
18. dht11 DHT11; //define type
19.
20. void setup() {
21. // initialize digital pin as an output.
22. pinMode(4, OUTPUT);
23. Serial.begin(9600);// initializing serial
24. }
25.
26. // the loop function runs over and over again forever
27. void loop() {
28. int chk = DHT11.read(DHT11PIN); //reading from the sensor
29. Serial.print(“Humidity (%): “); //printing results
30. Serial.print((float)DHT11.humidity, 2);
31. Serial.print(“Temperature (C): “);
32. Serial.println((float)DHT11.temperature, 2);
33.
34. delay(2000);
35. if (DHT11.temperature > 31)
36. {
37. digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
38. delay(1000); // wait for a second
39. digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
40. delay(1000); // wait for a second
41.
}
42.
}

1. /*