I'm playing with a little gas detector..
How can I stay indefinitely in an if statement or until an external button or reset button is pressed? So, once it detects gas, I'd like to sound the buzzer continuously until a button or reset button is pressed.
Right now it is only buzzing so long as it's detecting gas, MQ135.
int buzzer = 8;
int smokeA0 = A0;
// Your threshold value
int sensorThres = 100;
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(gasA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(gasA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
Serial.print("Gas Level:");
Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
tone(buzzer, 494, 400);
}
else
{
noTone(buzzer);
}
delay(500);
}