#define AO_PIN 32  // ESP32's pin GP34 connected to the MQ2 sensor's analog output

const int led_merah = 4;  // Pin for red LED
const int led_hijau = 2;  // Pin for green LED

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Set the ADC attenuation to 11 dB (up to ~3.3V input)
  analogSetAttenuation(ADC_11db);

  Serial.println("Warming up the MQ2 sensor");

  // Initialize LED pins as outputs
  pinMode(led_hijau, OUTPUT);
  pinMode(led_merah, OUTPUT);

  // Wait for the MQ2 sensor to warm up (20 seconds)
  delay(20000); 
}

void loop() {
  // Read the gas value from the MQ2 sensor
  int gasValue = analogRead(AO_PIN);

  // Print the gas value to the Serial Monitor
  Serial.print("MQ2 sensor AB value: ");
  Serial.println(gasValue);

  // Check if the gas value exceeds the threshold
  if (gasValue > 300) {
    digitalWrite(led_hijau, HIGH);  // Turn on the green LED
    digitalWrite(led_merah, LOW);   // Turn off the red LED
    delay(500);  // Delay for half a second

    digitalWrite(led_hijau, LOW);   // Turn off the green LED
    digitalWrite(led_merah, HIGH);  // Turn on the red LED
    delay(500);  // Delay for half a second
  } else {
    digitalWrite(led_hijau, LOW);   // Turn off the green LED
    digitalWrite(led_merah, LOW);   // Turn off the red LED
  }
}
$abcdeabcde151015202530354045505560fghijfghij
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
pot1:GND
pot1:SIG
pot1:VCC
led1:A
led1:C
led2:A
led2:C
r1:1
r1:2
r2:1
r2:2