Introduction
This experiment demonstrates how to use the MQ-4 sensor to detect methane gas in the environment.

Components Needed
- MQ-4 Methane Gas Sensor
- Arduino
- Jumper Wires
Circuit Setup
- Connect the MQ-4 sensor to the Arduino (VCC, GND, and analog output pin).
The MQ-4 sensor detects methane gas and outputs a voltage proportional to the concentration of the gas.

Code for Methane Detection
Upload the following code to your Arduino to measure methane gas levels:
const int mq4Pin = A0;
int sensorValue;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(mq4Pin);
Serial.print("Methane Concentration: ");
Serial.println(sensorValue);
delay(1000);
}
Explanation
The MQ-4 sensor reacts to methane gas, producing an analog voltage proportional to the gas concentration. The Arduino reads this value and displays it on the serial monitor.
Troubleshooting
- If no readings are shown, ensure the sensor is connected properly and is exposed to the air.
- Adjust the sensor’s warm-up time before use.