Natural Gas Detector using Arduino, MQ4 Gas Sensor and LED

Description:

In this project we are building a Natural Gas Detector using Arduino and MQ4 Gas Sensor. These detectors are used in rocky mountain and caves to detect natural gas which is used for commercial purposes. Here we have used MQ4 Gas Sensor is used to detect Natural Gas. When the gas is detected the LED glows and everything is controlled using Arduino UNO.

Circuit Diagram:

Natural Gas Detector using Arduino, MQ4 Gas Sensor and LED
Circuit Diagram: Natural Gas Detector using Arduino, MQ4 Gas Sensor and LED

Components:

SR. NO.COMPONENTPINOUT DIAGRAMBUY
1Arduino UNO (Other Arduinos can be used too)Arduino UNO Pinout Diagram⇗
2Red LED
3Green LED
4MQ4 Gas SensorMQ4 Gas Sensor Pinout Diagram
Arduino UNO
Arduino UNO

Arduino UNO

The Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. The board is equipped with sets of digital and analog input/output (I/O) pins that may be interfaced to various expansion boards and other circuits. The design is open-source and is intended for use in the hobby and educational markets. In this project, the Arduino UNO acts as the brain of the system, it reads the gas level from the MQ4 gas sensor and turn on the Red LED as an alarm when gas level exceeds the set threshold.

MQ4 Gas Sensor
MQ4 Gas Sensor

MQ4 Gas Sensor

The MQ4 gas sensor is a device that is used to detect the presence of methane (CH4) gas. It is a type of metal oxide semiconductor (MOS) sensor that utilizes a heated catalytic bead to detect the presence of methane in the air. The MQ4 sensor is highly sensitive and can detect methane concentrations as low as 200ppm. In this projects, the MQ4 sensor is used to detect the presence of natural gas in the air. The sensor is connected to the Arduino UNO microcontroller, which reads the gas level from the sensor and activates an LED as an alarm when the gas level exceeds a set threshold. The MQ4 sensor is a cost-effective and reliable way to detect the presence of natural gas, making it a popular choice for home safety and industrial applications.

Red LED
Red LED

Red LED

A Light-Emitting Diode (LED) is a semiconductor light source that emits light when an electrical current passes through it. A red LED is a specific type of LED that emits red light. In this project, the Red LED serves as an alarm indicator. The red LED is connected to the Arduino UNO microcontroller and is activated when the gas level detected by the MQ4 gas sensor exceeds a set threshold. The red LED serves as a visual warning of the presence of natural gas, alerting the users to take necessary precautions. The use of a red LED for this purpose is beneficial as red color is easily noticeable and can grab attention immediately which is important in case of gas leakage, where every second matters. The use of a red LED in this project is a simple yet effective way to ensure the safety of people in the vicinity of the gas leak.

Green LED
Green LED

Green LED

A Light-Emitting Diode (LED) is a semiconductor light source that emits light when an electrical current passes through it. A green LED is a specific type of LED that emits green light. In this project, the Green LED serves as a visual indication of normal or safe gas level. The green LED is connected to the Arduino UNO microcontroller and is activated when the gas level detected by the MQ4 gas sensor is below the set threshold. The green LED is an indication that the environment is safe and no gas leakage is detected. The use of a green LED in this project is a simple yet effective way to ensure the safety of people in the vicinity of the gas leak by providing a clear visual indication of normal gas level. Additionally, the green LED could also be used as a power indicator to confirm the device is turned on and working properly.

Steps and Info:

1. Get correct components as given. You can buy online or offline. I buy electronics components mostly from Amazon.

2. Start connecting the components. If you are new to connecting components in an electronic circuit, then use a Breadboard or you can straight up make connections using Jumper wires but it will create problem when there will be two or more connections needed at one pin (for example two or more different sensors 5V connection to Arduino’s 5V pin). But before soldering components on a PCB or printing a PCB for your circuit, better try using breadboard so that any errors and mistakes can be observed on breadboard and not after soldering. Or do connections in your way.

3. Now after building the circuit, download the Arduino IDE from https://www.arduino.cc/ website.

4. If you are new to Arduino IDE software, then watch this video we made specially for beginners about Arduino IDE.

5. If you know Arduino IDE then straight up copy the code we given and paste it into the Arduino IDE sketch.

6. Connect the Arduino to your Computer/device. Select a proper port, proper Arduino type and whatever other settings are. Here it is Arduino UNO. (If you don’t know what this all is then watch our video: ).

7. Compile the code and Upload it.

8. If any error occurs then try to troubleshoot it by finding/copy-pasting it into our Solve Errors page https://electronicsprojects.in/solve-errors/, or you can straight up paste the error on Internet and you know the rest. Also check if there are no spelling/syntax errors in the code. Compile the code again once to check if errors are fixed. I have given proper connections and code but still nothing is perfect.

9. Once code compiles and uploads smoothly, you can start testing the working of your circuit/project.

10. Now for this project, take your device to a place where there is a source of natural gas and check if the MQ4 gas sensor detects the gas. If it detects, then the red LED will turn ON, otherwise green LED will stay ON always. If it doesn’t then find what’s wrong. Check connections, code and whatever it is.

11. If you don’t have any Natural gas source near you, then you can use a simple smoke.

Program Code:

/* https://www.electronicsprojects.in Natural Gas Detector using Arduino, MQ4 Gas Sensor and LED */

int RedLED = 11;
int GreenLED = 10;
int MQ4 = A5;
int SENSORTHRESHOLD = 250;
void setup()
{
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
pinMode(MQ4, INPUT);
Serial.begin(9600);
}
void loop()
{
int analogValue = analogRead(MQ4);
Serial.println("Val: " +analogValue);
digitalWrite(GreenLED, HIGH);
if (analogValue >= SENSORTHRESHOLD)
{
digitalWrite(GreenLED, LOW);
digitalWrite(RedLED, HIGH);
}
else
{
digitalWrite(RedLED , LOW);
}
delay(5000);
}

Download:

Links:

More: