This project uses sensors to monitor indoor natural gas on the basis of Arduino, and will make alarm if the natural gas leak exceeds the limit.
Material:
1.MQ-4 Natural Gas Sensor
2.Arduino Uno with Network Screening
3.Bread board
Note: you can redeem these in PCBWay, please support me by register this invited PCBWay link.
As a natural gas sensor,the MQ-4 Natural Gas Sensor is a fast and reliable sensor with a high sensitivity to natural gas and methane, also good sensitivity to propane and butane. This natural gas sensor has a long life and low cost and is widely used for gas leak detection. At the same time, two LED lights are used in the project to display the gas concentration:
Green light: it means the natural gas concentration is below the critical value.
Red light: alert! The natural gas concentration has exceeded the critical value.
The MQ-4 Arduino sensor has four pins:
1. Positive Vcc (+5V)
2. Ground GND
3. Digital output
4. Analog output
Here is the wiring diagram:

In the schematic, there are two resistors connected to the Arduino digital pins and LEDs. The resistance is 220 Ohm
Here is the code:
int pinRedLed = 11;
int pinGreenLed = 8;
int pinSensor = A5;
int THRESHOLD = 250;
void setup() {
pinMode(pinRedLed, OUTPUT);
pinMode(pinGreenLed, OUTPUT);
pinMode(pinSensor, INPUT);
Serial.begin(9600);
}
void loop() {
int analogValue = analogRead(pinSensor);
Serial.println("Val: " + analogValue);
digitalWrite(pinGreenLed, HIGH);
if (analogValue >= THRESHOLD) {
digitalWrite(pinGreenLed, LOW);
digitalWrite(pinRedLed, HIGH);
}
else {
digitalWrite(pinRedLed, LOW);
}
delay(5000);
}
The green LED remains light up unless the natural gas concentration exceeds the threshold, the red LED will lights up.