Introduction
In my previous articles I explained some sensors and its functions and in this article I'll show you working with the MQ5 Gas Sensor to sense the Natural Gas, Coal Gas and LPG
Requirements
- Arduino Uno
- MQ5 Gas Sensor
- Bread Board
- Led
Connection
- Vcc to 5v
- Gnd to Gnd
- Signal (Middle Pin)---->Arduino
- led analog pin to 13
- Cathode to Gnd
Figure 1: MQ5 Gas Sensor
MQ5 Gas Sensor Specifications
Items | Parameter | Min |
Vcc | Working Voltage | 4.9 |
PH | Heating Consumption | 0.5 |
RL | Load Resistance | - |
RS | Sensing Resistance | 3 |
Application:
Programming:
- const int analog=A0;
- const int led=13;
- int sensor=0;
-
- void setup()
- {
- Serial.begin(9600); //Baud Rate
- pinMode(led,OUTPUT);
- }
-
- void loop()
- {
- sensor=analogRead(analog);
- if(sensor>=350)
- {
- digitalWrite(led,HIGH);
- }
- else
- {
- digitalWrite(led,LOW);
- }
- Serial.print("SensorValue = ");
- Serial.println(sensor);
- delay(10);
- }
Output
Explanation
const int analog and const int led constants won't change. They are used to give the name to the pin. Sensor value ='0', it reads the value from the sensor.
In the Setup() function set the baud rate and PinMode led as OUTPUT and in the loop() function we want to set the working conditions to the MQ5 Gas Sensor.
Sensor = analogRead(analog)
//Reads the analog value if(sensor>=300)
//Condition to the sensor base up on this if conditions it will act if(sensor>=300).
The LED for Gas is leaking will ON as shown in the above figure else the LED is in the off condition.
Serial.print // Print the result in the serial monitor
Conclusion
And finally we made the Gas Sensor to sense the Gas and alert it through LED.