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
Arduino Mega 2560
Gas Sensor
Buzzer
Bread Board
Led
Hookup wires.
Connection:
Step 1: Connection from the Gas Sensor to the Arduino Mega 2560,
Figure 1: Gas Sensor
Take the Output pin to the Analog pin of the A0 in the Arduino Mega board.
Take the Vcc pin to the +5v of the ArduinoMega board.
Take the Gnd pin to the Gnd of the ArduinoMega board.
Step 2: Connection from the LED to the Arduino Mega2560
Postive pin = 10;
Negative pin = Gnd;
Step 3: Connection from the Buzzer to the Arduino Mega2560
Programming:- const int sensorpin = A0;
- int led = 10;
- int buzzer = 5;
- int sensorValue = 0;
- void setup()
- {
- pinMode(led, OUTPUT);
- pinMode(buzzer, OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- Serial.println("Welcome to c#corner");
- sensorValue = analogRead(sensorpin);
- Serial.println(sensorValue);
- if (sensorValue < 100)
- {
- Serial.println("LPG Value");
- Serial.println("LED on");
- digitalWrite(led, HIGH);
- digitalWrite(buzzer, HIGH);
- delay(1000);
- }
- digitalWrite(led, LOW);
- digitalWrite(buzzer, LOW);
- delay(sensorValue);
- }
Explanation:
When the gas is detected the LED will be ON and the Buzzer also produced the sound.
Then we can see the reading in the serial monitor.
When the Gas is detected the LED can be HIGH.
Output:
Serial Monitor:
Figure 2: serial Monitor Display
Output:
Figure 3: Output
Read more articles on Arduino: