// I tested this 5/14/25, it works irl!!!!
#define MQ2pin 25 // or 26, either is fine
#define Buzzer 13 // can be any
float sensorValue; //variable to store sensor value
int dangerValue = 800; // arbitrary
void setup() {
Serial.begin(9600); // sets the serial port to 9600
Serial.println("MQ2 warming up!");
pinMode(Buzzer, OUTPUT);
delay(20000); // allow the MQ2 to warm up
}
void loop() {
sensorValue = analogRead(MQ2pin); // read analog input pin 0
Serial.print("Sensor Value: ");
Serial.println(sensorValue);
if (sensorValue >= dangerValue ) {
digitalWrite(Buzzer, HIGH); // buzzer on
delay(20000); // buzzer on for 20 s to allow the miner to react
digitalWrite(Buzzer, LOW); // buzzer off
}
delay(2000); // wait 2s for next reading
}