Thisproject uses sensors to monitor indoor natural gas on the basis of Arduino, andwill make alarm if the natural gas leak exceeds the limit.
Material:- MQ-4Natural Gas Sensor
- ArduinoUno with Network Screening
- Breadboard
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 belowthe critical value.
- Red light: alert! The natural gas concentration has exceeded the critical value.
The MQ-4Arduino sensor has four pins:
- Positive Vcc (+5V)
- Ground GND
- Digital output
- 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 isthe code:
intpinRedLed = 11;
intpinGreenLed = 8;
intpinSensor = A5;
intTHRESHOLD = 250;
voidsetup() {
pinMode(pinRedLed, OUTPUT);
pinMode(pinGreenLed, OUTPUT);
pinMode(pinSensor, INPUT);
Serial.begin(9600);
}
voidloop() {
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.
Comments
Please log in or sign up to comment.