Arduino Gas Concentration Sensor

    For this project we need an MQ2 Gas Sensor, an Arduino Uno r3 board, and jumper wires. This project will detect gas concentration and output a value of low, medium, or high.


Code:


const int mq2Analog = A0;  // Connect OUT to A0


void setup() {

  Serial.begin(9600);

}


void loop() {

  int sensorValue = analogRead(mq2Analog);

  float voltage = sensorValue * (5.0 / 1023.0);


  Serial.print("Analog Value: ");

  Serial.print(sensorValue);

  Serial.print(" | Voltage: ");

  Serial.print(voltage);

  Serial.print(" V | Gas Level: ");


  // Simple thresholds for gas concentration

  if (sensorValue < 200) {

    Serial.println("Low");

  } else if (sensorValue < 600) {

    Serial.println("Medium");

  } else {

    Serial.println("High");

  }


  delay(1000);

}