Experiment 6_Gas sensor
Experiment 6_Gas sensor
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.
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
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);