Skip to main content

MQ smoke Gas Sensor with Arduino Uno

In this example, We 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.
What is an 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.


How does it Work?

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 greaterthe output voltage
  • The lowerthe gas concentration,the lowerthe output voltage

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.

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.
Kindly refer to the connection schematic attached below. After you've wired all the
components properly, it's time to upload the necessary code.

Code for Arduino
/*******

 All the resources for this project:
lihuo.blogspot.com

*******/
int RedLED = 12;       // LED Red open in Have problams case
int GreenLED = 11;     // LED Green open in No problams case
int Relay_or_Buzzer= 10;        // Relay for buzzer Alarm
int sensorThres = 400; // Your threshold value


//function of MQ sensor for Gas and Smoke
double MQ(){
 double val;
 val = analogRead (A5);  //Pin A5 for MQ sensor
return val; }


void setup() {
  Serial.begin(9600);      // initialize serial
  pinMode(RedLED, OUTPUT);      // initalize LED as an output
  pinMode(GreenLED, OUTPUT);   // initalize LED as an output
  pinMode(Relay_or_Buzzer, OUTPUT);// initalize Relay as an out
}


void loop() {
  double M ; // for MQ
 
  // out result in serial for MQ by call function
  M = MQ ();
 Serial.print("\nSmoke or Gas = "); Serial.print(M);
      
// out result with buzzer when MQ sensor have problams
 if (M >= sensorThres) {
 digitalWrite(Relay_or_Buzzer, LOW);//LOW for Relay and HIGH   for Buzzer 
 digitalWrite(RedLED, HIGH); }
 
// Out result with buzzer when MQ sensor no Vcc
  else if (M <= 10) { 
        digitalWrite(Relay_or_Buzzer, LOW);//LOW for Relay and HIGH for Buzzer 
        digitalWrite(RedLED, HIGH); }
// out result with buzzer when MQ sensor no GND
  else if (M == 1023) { 
        digitalWrite(Relay_or_Buzzer, LOW);//LOW for Relay and HIGH for Buzzer 
        digitalWrite(RedLED, HIGH); }
// out result when all sensor Don't have problams
  else  { 
        digitalWrite(Relay_or_Buzzer, HIGH);//HIGH for Relay and LOW for Buzzer 
        digitalWrite(GreenLED, HIGH);   }
       
  delay(100);
}
Schematics

Comments

Popular posts from this blog

Discrete mathematics

            It's about Discrete mathematics in this book  #Anthony Croft, Engineering Mathematices, 5e (2017)  So i will choose exercise 5.2 #7 #8 #9  to slow everyone: 7 . The sets A, B and C are given by A = {1, 3, 5, 7, 9}, B = {0, 2, 4, 6} and C = {1, 5, 9} and the universal set, E = {0,1, 2, . . . ,9}. (a) Represent the sets on a Venn diagram. (b) State A ∪ B. (c) State B ∩ C. (d) State E ∩ C. (e) State not A. (f) State not B ∩not C. (g) State not (B ∪C). Ans :  a ) Represent the sets on a Venn diagram : The set containing all the numbers of interest is called the universal set, E. E is represented by the rectangular region. Sets A , B and C are represented  by the interiors of the circles and it is evident that 1 ,   3,  5,  7 and 9 are members of A while 0, 2,  4,  and 6 are members of B that 1,  5  and  9 are members of C....

Software Arduino IDE

Arduino is an open source computer hardware and software company, project, and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices and interactive objects that can sense and control objects in the physical world. A program for Arduino hardware may be written in any programming language with compilers that produce binary machine code for the target processor. Atmel provides a development environment for their 8-bit AVR and 32-bit ARM Cortex-M based microcontrollers: AVR Studio (older) and Atmel Studio (newer). IDE The Arduino integrated development environment (IDE) is a cross-platform application (for Windows, macOS, Linux) that is written in the programming language Java. It originated from the IDE for the languages Processing and Wiring . It includes a code editor with features such as text cutting and pasting, searching and replacing text, automatic indenting, brace matching, and syntax highl...

Lab 2 , 3 , 4 Method math in java

Class Teedcalculator: /*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ package teedcalculator; import static teedcalculator.Oparetor.tand;// to access all static Tand of a class import static teedcalculator.Oparetor.tan;// to access all static Tan of a class import static teedcalculator.Oparetor.cost;// to access all static Cost of a class import static teedcalculator.Oparetor.cosd;// to access all static Cosd of a class import static teedcalculator.Oparetor.degree2;// to access all static Degree of a class import static teedcalculator.Oparetor.divide;// to access all static divide of a class import static teedcalculator.Oparetor.minus;// to access all static minus of a class import static teedcalculator.Oparetor.modulo;// to access all static modulo of a class import static teedcalculator.Oparetor.multiply;// to acce...