Introduction

In this article I will explain how to detect gas using Arduino Mega. The gas sensor can easily find gas leaking at a place. When the gas is detected it can measure the range of the gas sensor.
Parts
Connection:
Step 1:
Connection from the Gas Sensor to the Arduino Mega 2560,
Figure 1: Gas Sensor
Step 2: Connection from the LED to the Arduino Mega2560
Step 3: Connection from the Buzzer to the Arduino Mega2560
Programming:
  1. const int sensorpin = A0; // sensor output pin to Arduino analog A0 pin
  2. int led = 10;
  3. int buzzer = 5;
  4. int sensorValue = 0;
  5. void setup()
  6. {
  7. pinMode(led, OUTPUT);
  8. pinMode(buzzer, OUTPUT);
  9. Serial.begin(9600); //Initialize serial port - 9600 bps
  10. }
  11. void loop()
  12. {
  13. Serial.println("Welcome to c#corner");
  14. sensorValue = analogRead(sensorpin);
  15. Serial.println(sensorValue);
  16. if (sensorValue < 100)
  17. {
  18. Serial.println("LPG Value");
  19. Serial.println("LED on");
  20. digitalWrite(led, HIGH);
  21. digitalWrite(buzzer, HIGH);
  22. delay(1000);
  23. }
  24. digitalWrite(led, LOW);
  25. digitalWrite(buzzer, LOW);
  26. delay(sensorValue);
  27. }
Explanation:
Output:
Serial Monitor:
Figure 2: serial Monitor Display
Output:
Figure 3: Output
Read more articles on Arduino: