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
Gas Moisture Sensor
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:
  • Gas Leakage Detection
Programming:
  1. const int analog=A0;
  2. const int led=13;
  3. int sensor=0;
  4. void setup()
  5. {
  6. Serial.begin(9600); //Baud Rate
  7. pinMode(led,OUTPUT);
  8. }
  9. void loop()
  10. {
  11. sensor=analogRead(analog);
  12. if(sensor>=350)
  13. {
  14. digitalWrite(led,HIGH);
  15. }
  16. else
  17. {
  18. digitalWrite(led,LOW);
  19. }
  20. Serial.print("SensorValue = ");
  21. Serial.println(sensor);
  22. delay(10);
  23. }
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 the LED.