Advertisement
zoro-10

Gas Sensor

Apr 1st, 2024 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. https://imgur.com/a/4NgJyUG
  2.  
  3.  
  4.  
  5. int LED = A1;
  6. const int gas = 0;
  7. int MQ2pin = A0;
  8. void setup()
  9. {
  10.   Serial.begin(9600);
  11. }
  12. void loop()
  13. {
  14.   float sensorValue, MQ2pin;
  15.   sensorValue = analogRead(MQ2pin); // read analog input pin 0
  16.   if (sensorValue >= 470)
  17.   {
  18.     digitalWrite(LED, LOW);
  19.     Serial.print(sensorValue);
  20.     Serial.println(" |SMOKE DETECTED");
  21.   }
  22.   else
  23.   {
  24.     digitalWrite(LED, HIGH);
  25.     Serial.println("Sensor Value: ");
  26.     Serial.println(sensorValue);
  27.   }
  28.   delay(1000);
  29. }
  30. float getsensorValue(int pin)
  31. {
  32.   return (analogRead(pin));
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement