#define MQ2_ANA A1
#define BUZZER_PIN 3
void setup() {
Serial.begin(9600);
pinMode(MQ2_ANA, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
int sensorValue = analogRead(MQ2_ANA);
Serial.print("Analog: ");
Serial.println(sensorValue);
if(sensorValue > 500) { // Adjust this threshold value according to your sensor's sensitivity
for(int i = 0; i < 1000; i++) { // Buzz the buzzer for 1 second
digitalWrite(BUZZER_PIN, HIGH);
delayMicroseconds(500); // Adjust this delay to change the sound frequency
digitalWrite(BUZZER_PIN, LOW);
delayMicroseconds(500); // Adjust this delay to change the sound frequency
}
Serial.println("Smoke detected!");
}
delay(1000);
}