#define GAS_SENSOR_PIN 34 // Analog pin where MQ2 sensor is connected
void setup() {
Serial.begin(115200);
analogReadResolution(12); // Set resolution to 12 bits (0-4095)
}
void loop() {
int gasValue = analogRead(GAS_SENSOR_PIN); // Read analog value
Serial.print("Gas Sensor Value: ");
Serial.println(gasValue);
// Example: trigger alert if gas level is too high
if (gasValue > 2000) {
Serial.println("⚠️ Gas Level HIGH! Take Action!");
}
delay(1000); // Read every 1 second
}