Advertisement
computermuseo

sensore fumo

Jun 4th, 2017
1,890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. int redLed = 12;
  2. int greenLed = 11;
  3. int buzzer = 10;
  4. int smokeA0 = A5;
  5. // Your 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("Pin A0: ");
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement