Let us see how to connect smoke sensor with arduino.
It consists of four pins:
Step 1: Connect the Vcc pin of arduino with Vcc of gas sensor.
Step 2: Connect the GND teminals of arduino and gas sensor
Step 3: Connect Do pin of gas sensor to any of the digital pin you prefer in arduino.
if you want the sensor to show digital reading you can connect it to digital pin or if you want to show analog reading connect analog pin Ao to any of analog pin in arduino.
int sensor=7;
int gas_value;
void setup()
{
pinMode(sensor,INPUT);
Serial.begin(9600);
}
void loop()
{
gas_value=digitalRead(sensor);
Serial.println(gas_value);
}
Hardware Requirements:
- Breadboard (optional)
- Arduino
- MQ2 Gas sensor
Software Requirements:
- Arduino uno
MQ2 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.
Pin Configuration:
pin configuration of mq2 sensor |
- Vcc - power supply pin
- GND - ground
- Do - Digital pin
- Ao - Analog pin
Connecting steps:
Step 1: Connect the Vcc pin of arduino with Vcc of gas sensor.
Step 2: Connect the GND teminals of arduino and gas sensor
Step 3: Connect Do pin of gas sensor to any of the digital pin you prefer in arduino.
if you want the sensor to show digital reading you can connect it to digital pin or if you want to show analog reading connect analog pin Ao to any of analog pin in arduino.
connecting arduino with gas sensor |
Codings:
For Digital output:
int sensor=7;
int gas_value;
void setup()
{
pinMode(sensor,INPUT);
Serial.begin(9600);
}
void loop()
{
gas_value=digitalRead(sensor);
Serial.println(gas_value);
}
Here sensor Do pin is connected to the 7th digital pin of gas sensor and the value 9600 indicates the baud rate.
For Analog output:
float sensor=A0;
float gas_value;
void setup()
{
A0
pinMode(sensor,INPUT);
Serial.begin(9600);
}
void loop()
{
gas_value=analogRead(sensor);
Serial.println(gas_value);
}
float gas_value;
void setup()
{
A0
pinMode(sensor,INPUT);
Serial.begin(9600);
}
void loop()
{
gas_value=analogRead(sensor);
Serial.println(gas_value);
}
Here pin Ao of sensor is connected to Ao pin of arduino and the value 9600 indicates the baud rate.
The output of both mode can be seen in serial monitor using arduino uno.
No comments:
Post a Comment