0% found this document useful (0 votes)
82 views6 pages

Gas Sensor

This document describes an experiment to detect smoke using an MQ-2 gas sensor connected to an Arduino board. The experiment will read the sensor value and trigger a buzzer and LED if smoke is detected above a threshold. It lists the components needed, including an Arduino, gas sensor, buzzer, LEDs, resistors. It provides connection diagrams and code samples to read the sensor value and activate the outputs when smoke is detected.

Uploaded by

Shabbir Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views6 pages

Gas Sensor

This document describes an experiment to detect smoke using an MQ-2 gas sensor connected to an Arduino board. The experiment will read the sensor value and trigger a buzzer and LED if smoke is detected above a threshold. It lists the components needed, including an Arduino, gas sensor, buzzer, LEDs, resistors. It provides connection diagrams and code samples to read the sensor value and activate the outputs when smoke is detected.

Uploaded by

Shabbir Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

22SC1209 IOT WORKSHOP

Exp No.: 4 Date:

Smoke Detection Using MQ-2 GAS Sensor


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.

SOFTWARES USED
Arduino UNO (Arduino IDE)
APPARATUS/ COMPONENTS REQUIRED

Name of the Component No of Units


Arduino Uno development board 1
USB cable 1
Buzzer ,LED 1 /2

Resistor (220Ω, 1KΩ) 2


Smoke Sensor(MQ2) 1
Bread board 1
Jumper wires 6

CONNECTION DIAGRAM For Tinkercad

1
Koneru Lakshmaiah Education Foundation
22SC1209 IOT WORKSHOP

PRE-LAB

1.Draw the Circuit Diagram for the Connection Diagram

2.Draw the Pin diagram for LDR sensor Module

THEORY:

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 voltage is 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 the gas.
The smoke sensor has a built-in potentiometer that allows you to adjust the sensor sensitivity
according to how accurate you want to detect gas.

2
Koneru Lakshmaiah Education Foundation
22SC1209 IOT WORKSHOP

MQ2 Sensor 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 greaterthe gas concentration,the greater the output voltage


• The lowerthe gas concentration,the lower the output voltage

Working Mechanism

The output can be an analog signal (A0) that can be read with an analog input of the Arduino
or a digital output (D0) that can be read with a digital input of the Arduino.

3
Koneru Lakshmaiah Education Foundation
22SC1209 IOT WORKSHOP

Pin Wiring
The MQ-2 sensor has 4 pins.
Pin-------------------------------------Wiring to Arduino Uno
A0-------------------------------------Analog pins
D0-------------------------------------Digital pins
GND-----------------------------------GND
VCC------------------------------------5V
So, before jumping into the coding part, let's check whether we've assembled all the
necessary hardware components.
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 “300” and according to that LED glove.

PROGRAM for Tinkercad


int redled=3;
int greenled=2;
int buz=4;
int sensor = A0;
int sensThre = 400;
void setup()
{
pinMode(redled, OUTPUT);
pinMode(greenled, OUTPUT);

4
Koneru Lakshmaiah Education Foundation
22SC1209 IOT WORKSHOP

pinMode(buz, OUTPUT);
pinMode(sensor, INPUT);
Serial.begin(9600);
}
void loop()
{
int sensValue=analogRead(sensor);
Serial.println(sensValue);
if (sensValue > 300)
{
digitalWrite(redled, HIGH);
tone(buz,10000,10);
digitalWrite(greenled, LOW);
}
else
{
digitalWrite(greenled, HIGH);
noTone(buz);
digitalWrite(redled, LOW);
}
}

Program for Interface MQ2 Sensor With Arduino:

// Sensor pins pin D6 LED output, pin A0 analog Input

#define ledPin 6
#define sensorPin A0
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
Serial.print("Analog output: ");
Serial.println(readSensor());
delay(500);
}
// This function returns the analog data to
calling function
int readSensor() {
unsigned int sensorValue = analogRead(sensorPin); // Read the analog value from sensor
unsigned int outputValue = map(sensorValue, 0, 1023, 0, 255); // map the 10-bit data to 8-bit data
if (outputValue > 65)
analogWrite(ledPin, outputValue); // generate PWM signal

5
Koneru Lakshmaiah Education Foundation
22SC1209 IOT WORKSHOP

else
digitalWrite(ledPin, LOW);
return outputValue; // Return analog moisture value

INFERENCES/ANALYSIS

POST-LAB

1.What is the Principle of MQ2 Gas sensor?

2.List out the pin in MQ2 Sensor module?

4.Why that MQ2 Gas Sensor is Analog Sensor?

Results

6
Koneru Lakshmaiah Education Foundation

You might also like