const int mq2Pin = A0;
const int ledRed = 2;
const int ledGreen = 7;
const int threshold = 400;
void setup() {
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(mq2Pin);
Serial.print("Sensor Value: ");
Serial.println(sensorValue);
if (sensorValue > threshold) {
digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, LOW);
delay(100);
digitalWrite(ledRed, LOW); // turn off green led for flash
} else {
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, HIGH);
delay(100);
digitalWrite(ledGreen, LOW); // turn off green led for flash
}
delay(1000);
}