/*
Wokwi | general
Alexia - Thursday, May 28, 2026 11:56 PM
Hii, i really need help please https://wokwi.com/projects/465324356872092673
*/
const int LED_PINS[] = {7, 6, 5, 4, 3};
const int BUZZ_PIN = 2;
const int MQ2_PIN = A0;
void setup() {
int sensorVal = 0;
Serial.begin(9600);
for (int i = 0; i < 5; i++) {
pinMode(LED_PINS[i], OUTPUT);
}
pinMode(BUZZ_PIN, OUTPUT);
while (sensorVal == 0) {
sensorVal = analogRead(MQ2_PIN);
Serial.println("Waiting for sensor to stabilize");
Serial.println(sensorVal);
delay(1000);
}
}
void loop() {
int sensorMQ2 = map(analogRead(A0), 210, 1010, 0, 100);
Serial.print("MQ2 sensor value: ");
Serial.println(sensorMQ2);
// reset output indicators
for (int i = 0; i < 5; i++) {
digitalWrite(LED_PINS[i], LOW);
}
noTone(BUZZ_PIN);
// set output indicators
if (sensorMQ2 <= 20) {
digitalWrite(LED_PINS[0], HIGH);
} else if (sensorMQ2 <= 40) {
digitalWrite(LED_PINS[1], HIGH);
} else if (sensorMQ2 <= 60) {
digitalWrite(LED_PINS[2], HIGH);
} else if (sensorMQ2 <= 80) {
digitalWrite(LED_PINS[3], HIGH);
} else if (sensorMQ2 <= 100) {
digitalWrite(LED_PINS[4], HIGH);
tone(BUZZ_PIN, 440, 500);
}
delay(1000);
}MQ-2
Buzzer
Power
Gas levels