Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. int redLed = 12;
  2. int greenLed = 11;
  3. int buzzer = 10;
  4. int smokeA0 = A5;
  5. // threshold value
  6. int sensorThres = 400;
  7.  
  8. void setup() {
  9. pinMode(redLed, OUTPUT);
  10. pinMode(greenLed, OUTPUT);
  11. pinMode(buzzer, OUTPUT);
  12. pinMode(smokeA0, INPUT);
  13. Serial.begin(9600);
  14. }
  15.  
  16. void loop() {
  17. int analogSensor = analogRead(smokeA0);
  18.  
  19. Serial.print("Concentration: ppm ");
  20. Serial.println(analogSensor);
  21. // Checks if it has reached the threshold value
  22. if (analogSensor > sensorThres)
  23. {
  24. digitalWrite(redLed, HIGH);
  25. digitalWrite(greenLed, LOW);
  26. tone(buzzer, 1000, 200);
  27. }
  28. else
  29. {
  30. digitalWrite(redLed, LOW);
  31. digitalWrite(greenLed, HIGH);
  32. noTone(buzzer);
  33. }
  34. delay(100);
  35.  
  36. #include <SimpleDHT.h>
  37.  
  38. int pinDHT11 = 7;
  39. SimpleDHT11 dht11(pinDHT11);
  40.  
  41. void setup() {
  42. // start working...
  43. Serial.begin(9600);
  44. Serial.println("Temperature and Humidity Data");
  45. }
  46.  
  47. void loop() {
  48.  
  49. delay (250);
  50. // read without samples.
  51. byte temperature = 0;
  52. byte humidity = 0;
  53. int err = SimpleDHTErrSuccess;
  54. if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
  55. Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
  56. return;
  57. }
  58. Serial.print((int)temperature); Serial.print(" *C, ");
  59. Serial.print((int)humidity); Serial.println(" H");
  60.  
  61. // DHT11 sampling rate is 1HZ.
  62. delay(1500);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement