safwan092

Untitled

Dec 14th, 2018
273
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Your threshold value. You might need to change it.
  3. int th0 = 300;
  4. int th1 = 300;
  5. int th5 = 90;
  6. int blinkTimes = 10;
  7.  
  8.  
  9. int motor = 4;
  10. int leds = 3;//10
  11. int gasA0 = A2;//A0;
  12. int gasA1 = A3;//A1;
  13. int micA5 = A1;//A5;
  14.  
  15.  
  16. void setup() {
  17. pinMode(motor, OUTPUT);
  18. pinMode(leds, OUTPUT);
  19. pinMode(gasA0, INPUT);
  20. pinMode(gasA1, INPUT);
  21. pinMode(micA5, INPUT);
  22. digitalWrite(motor, LOW);
  23. digitalWrite(leds, LOW);
  24. Serial.begin(9600);
  25. }
  26.  
  27. void loop() {
  28. int analogSensor0 = analogRead(gasA0);
  29. int analogSensor1 = analogRead(gasA1);
  30. int analogSensor5 = analogRead(micA5);
  31. digitalWrite(motor, LOW);
  32. digitalWrite(leds, LOW);
  33. Serial.print("S+CO: ");
  34. Serial.print(analogSensor0);
  35. Serial.print("/");
  36. Serial.print(th0);
  37. Serial.print("\t");
  38. Serial.print("S+CO2: ");
  39. Serial.print(analogSensor1);
  40. Serial.print("/");
  41. Serial.print(th1);
  42. Serial.print("\t");
  43. Serial.print("Sound: ");
  44. Serial.print(analogSensor5);
  45. Serial.print("/");
  46. Serial.println(th5);
  47.  
  48. // Checks if it has reached the threshold values
  49. if (analogSensor0 > th0 || analogSensor1 > th1 || analogSensor5 > th5)
  50. {
  51. outputsON();
  52. }
  53. else
  54. {
  55. outputsOFF();
  56. }
  57. delay(100);
  58. }
  59.  
  60.  
  61.  
  62.  
  63. void outputsOFF() {
  64. digitalWrite(leds, LOW);
  65. digitalWrite(motor, LOW);
  66. }
  67.  
  68.  
  69.  
  70. void outputsON() {
  71. digitalWrite(motor, HIGH);
  72. for (int i = 0; i < blinkTimes; i++) {
  73. digitalWrite(leds, HIGH);
  74. delay(100);
  75. digitalWrite(leds, LOW);
  76. delay(100);
  77. }
  78. digitalWrite(motor, LOW);
  79. }
RAW Paste Data