Interfacing of smoke sensor (MQ2) with an Arduino in tinkercad.
[Gas leakage
detector]
In this project, we will see how to interface the smoke
sensor with Arduino in tinkercad and we will make the gas leakage detector. and
also, we will learn about gas Sensors, how a gas sensor works and simulate the
circuit in tinkercad. Here
we are using MQ2 Gas Sensor Module. This gas sensor module is basically
suitable for detecting LPG, Smoke, Alcohol, Propane, Hydrogen, Methane and Carbon Monoxide concentrations in the
air. This gas sensor can be used make projects like indoor air quality
monitoring, alcohol checker or LPG leakage detecting.
Circuit Diagram:
Components Required:
§ Arduino UNO
§ Gas sensor
§ Resistor-04
§ LED-02
§ Connecting
wires
§ Buzzer
Connection:
The
hardware a part of this project is quite simple and easy to place together.
First of all, make the connections for the gas sensor with the Arduino. The
connections for the gas sensor with the Arduino given in the above circuit
diagram.
Gas sensor
has six pins here we used the MQ2 sensor alone.MQ2 gas sensor module has 4 pins
power, ground, analog out, digital out. will see how to do the connection for
MQ2 sensor.
A basic gas
sensor has 6 terminals in which 4 terminals (A, A, B, B) acts as input or
output and the other 2 pins (H, H) are for heating the coil.
Connect the
A1, H1, A2 to the power pin of an Arduino.
Connect the
B1 to the analog pin A5 of an Arduino.
Connect the
h1 to the GND pin of an Arduino.
Connect the
B1 to the GND through resistor.
Connect the
buzzer positive pin to digital pin 10 of an Arduino.
Connect the
LED with resistor to digital pin 11 of an Arduino.
Connect the
LED with resistor to digital pin 12 of an Arduino.
Connect the
negative of the buzzer and cathode of LED to the GND pin of an Arduino.
What is MQ2 Gas Sensor?
MQ2 gas sensor is one of most used in MQ
sensor list. It is a Metal Oxide Semiconductor (MOS). Gas sensor is
one which use to detect the variation in the concentration of toxic gases in
environment, industries in various places.
How does it
work?
Sensor gives
the analog output that is changing voltage output based on smoke/gas level that
exists in the atmosphere. The sensor outputs a voltage that is proportional to
the amount of concentration of smoke/gas in the environment.
In simple
words, I can put the relationship between voltage and gas concentration is the
following:
§ If there is more the gas
concentration, the more the output voltage
§ lesser the gas concentration, the lesser the output voltage
Pinout:-
List of Gas Sensors and What Gases They
Sense
Arduino Code Explanation:
Define the LED and buzzer pins, led1 is connected to the pin 12 and led2 is connected to the pin 11 and last buzzer is connected to the pin 10.
Ø int
led1=12;
Ø int
led2=11;
Ø int
buzzer=10;
Ø int
gas_sensor=A5;
declared variable named sensorthreshold to store the
threshold value of gas sensor
Ø int
sensorthreshold=600;
Inside the void
setup we will define the pin which are input and which are output pin, this set
of code runs only once.
Initialize the
serial monitor for displaying the value at baud rate of 9600.
void setup()
{
pinMode(led1,OUTPUT);
pinMode(led1,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(gas_sensor=A5,INPUT);
Serial.begin(9600);
}
the
code inside the void loop runs over and over as long as the Arduino Board is
turned on.
Here
inside the loop defined one variable called analog sensor to store the gas
sensor value
void loop()
{
int
analogsensor=analogRead(gas_sensor);
Serial.println("sensor
");
Serial.println(analogsensor);
The if() conditional statement
basic coding control structures. One can make something happen or not,
it depend whether the condition is true or not. It looks like this:
If the value stored in analogsensor variable is greater than threshold
value then led1 will tun on and buzzer start producing sound
if
(analogsensor>sensorthreshold)
{
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
tone(buzzer,1000,350);
}
If the exact opposite happens then led2 will turn on and
buzzer turned off.
else
{
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
noTone(buzzer);
}
}
Watch Working Video part 1:
Watch Working Video part 2:
Complete Arduino Sketch:
int led1=12;
int led2=11;
int buzzer=10;
int gas_sensor=A5;
int sensorthreshold=600;
void setup()
{
pinMode(led1,OUTPUT);
pinMode(led1,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(gas_sensor=A5,INPUT);
Serial.begin(9600);
}
void loop()
{
int analogsensor=analogRead(gas_sensor);
Serial.println("sensor
");
Serial.println(analogsensor);
if (analogsensor>sensorthreshold)
{
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
tone(buzzer,1000,350);
}
else
{
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
noTone(buzzer);
}
}
Like share and comment :
Comments
Post a Comment
If you any query please comment