How To Push Button With DHT11

Required Hardware

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

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

Circuit

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

Schematic

Code

                    

1. /*
2. Push Button with DHT11
3.
4. This example shows how to use Push Button with DHT11
5.
6. The circuit:
7. – DHT11
8. connected to digital pin of Arduino
9. – Push Button
10. Anode connected to VCC.
11. Cathode connected to digital pin 2.
12. Cathode connected to GND through 220 resistor.
13.
14. http://hackerspacekarachi.org/
15. */
16. #include <dht11.h>
17. #define DHT11PIN 7 //connected to digital pin 7
18.
19. dht11 DHT11; //define type
20.
21. void setup()
22. {
23.
24. Serial.begin(9600);// initializing serial
25. pinMode(2, INPUT); // declaration of input
26. }
27.
28. void loop()
29. {
30. int chk = DHT11.read(DHT11PIN); //reading from the sensor
31. int d = digitalRead(2); // read and store input
32.
33. if (d == 1)
34. {
35. Serial.print(“Humidity (%): “); //printing results
36. Serial.print((float)DHT11.humidity, 2);
37. Serial.print(“Temperature (C): “);
38. Serial.println((float)DHT11.temperature, 2);
39.
40. delay(2000);
41. }
42. }

1. /*