0% found this document useful (0 votes)
2 views

Experiment 6_Gas sensor

Uploaded by

harshap3712
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Experiment 6_Gas sensor

Uploaded by

harshap3712
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment No 6 Student ID

Date Student Name

Gas detection using MQ2 sensor and Arduino Genuino UNO


Aim:
The main objective of this experiment is to read the MQ-2 sensor value and turn on
Buzzer and LED if analogue sensor value exceeds its threshold value.
Components required:

Software Hardware
Arduino UNO Board
Arduino UNO Cable
Tinkercad MQ-2 Gas Sensor
Arduino IDE (To be installed in Laptop) LED (Red-1, Green-1)
Buzzer - 1
Resistors – 4 (220Ω each)
Jumper wires
Description:
In this Experiment, you will read the sensor analog output voltage and when the smoke
reaches a certain level, it will make sound a buzzer and a RED LED will turn on. When
the output voltageis below that level, a GREEN LED will be on.
MQ-2 Smoke Sensor
The MQ-2 smoke sensor is sensitive to smoke and to the following flammable gases:
 LPG
 Butane
 Propane
 Methane
 Alcohol
 Hydrogen
The resistance of the sensor is different depending on the type of gas. The smoke sensor has a
built-in potentiometer that allows you to adjust the sensor sensitivity according to how
accurately you want to detect gas.

MQ2Sensor Pin-out details


The voltage that the sensor outputs changes accordingly to the smoke/gas level that exists in
the atmosphere. The sensor outputs a voltage that is proportional to the concentration of
smoke/gas.
In other words, the relationship between voltage and gas concentration is the following:
 The greater the gas concentration, the greater the output voltage
 The lower the gas concentration, the lower the output voltage

PIN Description
A0 Analog pin
D0 Digital pin
GND GND
VCC 5V
In lab:

Controlling the LED and Buzzer based on the Gas sensor Value

Connection diagram: MQ2 gas sensor

Program:
int gasval = 0;
void setup()
{
pinMode (9,OUTPUT);
pinMode (10,OUTPUT);
pinMode (A0,INPUT);
Serial.begin(9600);
}
void loop()
{
gasval = analogRead (A0);
Serial.print("Gas Value::");
Serial.println(gasval);

if (gasval <500 )
{
digitalWrite (9, LOW);
digitalWrite (10, LOW);

}
else
{
digitalWrite(9, HIGH);
digitalWrite (10, HIGH);
}
}
PROCEDURE:
1. Give the connections to the Arduino board as shown in the connection diagram.
2. Open Arduino IDE in the computer
3. Create new file File_--→ New
4. Type your program and Save it in appropriate location in your computer.
5. Compile your program by clicking Verify option in the menu.
6. Once the program compiled successfully, connect the Arduino board to the computer using
USB cable.
7. After connecting, go to Tools ----→Board ---→ Select Arduino/Genuino Uno option.
8. After selecting board, go to Tools ----→Port ---→ Select Arduino Uno COM port 3
(name may appear differently for other computers).
**Note that this port option will be displayed only when board is connected to computer.
9. Now upload the program to the Arduino board by clicking Upload option.
10. Once the program uploaded successfully, open serial monitor window in Arduino IDE to
see the value of Gas Sensor. When you change the Smoke content of MQ2, observe the
buzzer beeps when Sensor values reaches threshold “500” and according to that LED
glove.

Circuit/Schematic Diagram:

Results:

Inferences/Analysis:
POST-LAB
Control Multiple LED’s based on the Gas sensor value and sound the buzzer

Connection diagram:

Program:
#define BUZZER_PIN 13
#define PIN_LED_1 6
#define PIN_LED_2 5
#define PIN_LED_3 4
#define PIN_LED_4 3
#define PIN_LED_5 2
#define PIN_GAS A3

void setup()
{
pinMode(PIN_LED_1, OUTPUT);
pinMode(PIN_LED_2, OUTPUT);
pinMode(PIN_LED_3, OUTPUT);
pinMode(PIN_LED_4, OUTPUT);
pinMode(PIN_LED_5, OUTPUT);
Serial.begin(9600);
}
void loop()
{
long frequency;
int value = map(analogRead(PIN_GAS), 300, 750, 0, 100);
digitalWrite(PIN_LED_1, HIGH);
digitalWrite(PIN_LED_2, value >= 20 ? HIGH : LOW);
digitalWrite(PIN_LED_3, value >= 40 ? HIGH : LOW);
digitalWrite(PIN_LED_4, value >= 60 ? HIGH : LOW);
digitalWrite(PIN_LED_5, value >= 80 ? HIGH : LOW);

frequency = map(value, 0, 1023, 1500, 2500);


if (value>=50)
{
tone(BUZZER_PIN, frequency, 250);
}
Serial.println(value);
delay(250);
}
Results:

Evaluator Remark (if Any):


Marks Secured: out of 50

Signature of the Evaluator with Date

You might also like