/*******
 
 2021.6.26

*******/

int buzzer = 2;   // Define the buzzer pin number to the second pin of Type-C Nano
int smokeA0 = A0;  //Define the MQ-2 gas sensor pin to connect to the A0 pin of the Type-C Nano analog port

//Your threshold value
int sensorThres = 400;

void setup() {
  
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  Serial.begin(9600);
}

void loop() {
  int analogSensor = analogRead(smokeA0);//The MQ-2 sensor check values are assigned to the ALOG Sensor variable

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  // Checks if it has reached the threshold value
  if (analogSensor > sensorThres)
  {
   
    tone(buzzer, 1000, 200);
  }
  else
  {   
  
    noTone(buzzer);
  }
  delay(100);
}
