GAS Sensor Code

 const int gasSensorPin = A0;  // Connect gas sensor output pin to A0

const int buzzerPin = 8;      // Connect buzzer to digital pin 8

const int threshold = 300;    // Adjust this threshold based on your sensor


void setup() {

  pinMode(gasSensorPin, INPUT);

  pinMode(buzzerPin, OUTPUT);

  Serial.begin(9600);

}


void loop() {

  int gasLevel = analogRead(gasSensorPin);

  Serial.println(gasLevel);


  if (gasLevel > threshold) {

    for (int i = 0; i < 6; i++) {  // Beep 6 times

      digitalWrite(buzzerPin, HIGH);

      delay(100);                 // Buzzer on for 100ms

      digitalWrite(buzzerPin, LOW);

      delay(400);                 // Buzzer off for 400ms

    }

    delay(3000);                  // Wait 3 seconds before the next cycle

  }

}


Comments

Popular posts from this blog

ESP32 Wi-Fi Extender Code