How To DHT11 With Buzzer

Required Hardware

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

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

Circuit

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

Schematic

Code

                    

1. /*
2. DHT11 with Buzzer
3. This example shows how to use DHT11 with Buzzer
4. The circuit:
5. – DHT11
6. connected to digital pin of Arduino
7. – BUZZER
8. Anode connected to analog pin Ao.
9. Cathode connected to Ground.
10.
11. http://hackerspacekarachi.org/
12. */
13. #include <dht11.h>
14. #define DHT11PIN 7 //connected to digital pin 7
15.
16. dht11 DHT11; //define type
17.
18. void setup()
19. {
20. pinMode(A0, OUTPUT); //Declare pins to be used as ouput
21. Serial.begin(9600);// initializing serial
22.
23. }
24.
25. void loop()
26. {
27. int chk = DHT11.read(DHT11PIN); //reading from the sensor
28. Serial.print(“Humidity (%): “); //printing results
29. Serial.print((float)DHT11.humidity, 2);
30. Serial.print(“Temperature (C): “);
31. Serial.println((float)DHT11.temperature, 2);
32. if (DHT11.temperature > 25)
33. {
34.
35. tone ( A0, 450); //setting frequency
36. delay (500);
37. noTone (A0);
38. delay (500);
39. }
40.
41. delay(2000);
42.
43. }

1. /*