The project was developed from the structure presented below. This structure is responsible for guarding and protecting the gas leak detector circuit.
The case has an LCD display, 3 buttons, and an MQ2 sensor.
The LCD will be used to present the information of the gas level monitoring and to present a menu for adjustment of settings by the user.
This adjustment can be made using the 3 buttons.
Next, we present the structure of the internal circuit. The internal space allows you to place an Arduino Nano on a small Breadboard.
After installing the Arduino, connect the elements of the project and start programming the project. Below, we present the connection structure of the circuit elements.
After that, download the files for laser cutting on 2.5 mm thick calls.
Download this file in the Attachment section.In addition to offering you the files, we will also offer the Arduino JLCPCB Compatible Board project.
Para realizar a fixação das peças da case, utilize parafusos
A Big bonus of JLCPCB.COMThe JLCPCB wantsto offer 10 units of this Arduino JLCPCBcompatible PCB for your projectsfor$2 in your first order with the link:Earn my PCBs Arduino Compatible.
One of the main causes of fires in homes is the leakage of cooking gas that when it comes in contact with sparks caused by the lighting of lamps through the switches.
Faced with this problem, we will develop a system for the detection of cooking gas present in the environment.
To perform the detection of this gas we will use the MQ2 sensor, this sensor has a resistance that varies according to the gas detection, it is possible to adjust its sensitivity through a trimpot present on the plate.
This detection system will consist of an Arduino Nano, MQ - 2 sensor, red led, buzzer, and I2C 16 x 2 LCD display.
Therefore, through this article you will learn:
- Perform the assembly of the circuit on the protoboard;
- Understand the operation of the MQ2 sensor;
- Perform the communication of the Arduino JLCPCB with the MQ2 sensor;
- Display of measured values on the LCD Display.
- Earn your detector leakage gas case project;
- Earn your Arduino JLCPCB Printed Circuit Board.
Now, we will start the complete presentation of the development of the Gas detection system project with the MQ - 2 sensors.
Developing the Project Gas detection system with the MQ -2 sensorAs previously mentioned, the project consists of creating a kitchen gas detection system with the MQ - 2 sensor. Next, we will explain the details of the operation of this sensor.
The MQ2 SensorThe MQ - 2 sensor is a sensor capable of detecting flammable gases such as LPG, Propane, Butane, Methane, among other flammable gases.
This sensor has two outputs: a digital one that when the gas is detected it goes to 0 V and an analog output that varies its value according to the presence of the gas in the environment.
In figure 2 we have the schematic circuit with the necessary connections for assembling the project.
After assembling the electronic circuit according to figure 2, we will program the Arduino UNO JLCPCB to read the sensor and display the values on the LCD display, activating the LED and the buzzer.
Next, we'll explain the source code.
The source code of the projectIn order to carry out this project, two libraries will be needed, Wire for I2C communication and LiquidCrystal_I2C, which is the necessary library for communication with the LCD display.
// Bibliotecas
/ Inclusão da biblioteca I2C
#include <Wire.h>
Objeto lcd
LiquidCrystal_I2C lcd (0x27,2,1,0,4,5,6,7,3,POSITIVE);
Mapping naming each pin on the board with the name of each actuator or sensor that it will perform the reading.
//Mapeamento de hardware
#define Led 6 // Led
#define buzzer 4 // Buzzer
#define D0 2 // Saída digital do sensor de gás
Declaration of variables to read the gas sensor.
// Variável para leitura do sensor de gás
int val_sensor =0; // Leitura analógica do sensor
boolean val_sensor_d =0; // Leitura digital do sensor
In the void setup function, the serial communication speed is configured, the I2C communication is started, the pins of the led and the buzzer are configured as an output, and the digital output of the sensor as input and configure how many columns and lines the LCD display has.
void setup()
{
Serial.begin(9600);
Wire.begin();
lcd.begin(16,2);
pinMode(Led,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(D0,INPUT);
}
In the void loop function, the sensor is read and if the value is greater than 200, the led and the buzzer are activated, in addition, to display messages with the sensor reading value and if it exceeds the set point of 200 detects the presence of the gas.
void loop()
{
val_sensor = analogRead(A0); // leitura do sensor
val_sensor_d = digitalRead(D0);
Serial.print("Sensor saida analogica : ");
Serial.println(val_sensor);
Serial.print("Sensor saida digital : ");
Serial.println(val_sensor_d);
if( val_sensor > 200)
{
digitalWrite(Led,1);
digitalWrite(buzzer,1);
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print("MONITORAMENTO ");
lcd.setCursor(2,1);
lcd.print("GAS DETECTADO");
}
else
{
digitalWrite(Led,0);
digitalWrite(buzzer,0);
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print(" SENSOR MQ2");
lcd.setCursor(0,1);
lcd.print("Valor:");
lcd.setCursor(7,1);
lcd.print(val_sensor);
lcd.setCursor(11,1);
lcd.print("D2:");
lcd.setCursor(14,1);
lcd.print(val_sensor_d);
}
delay(200);
lcd.clear();
}
Below, we present the complete code for the project.
// Inclusão da biblioteca I2C
#include <Wire.h>
// Inclusão da biblioteca do display lcd I2C 16 x 2
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,2,1,0,4,5,6,7,3,POSITIVE);
//Mapeamento de hardware
#define Led 6 // Led
#define buzzer 4 // Buzzer
#define D0 2 // Saída digital do sensor de gás
// Variavel para leitura do sensor de gás
int val_sensor =0; // Leitura analógica do sensor
boolean val_sensor_d =0; // Leitura digital do sensor
void setup()
{
Serial.begin(9600);
Wire.begin();
lcd.begin(16,2);
pinMode(Led,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(D0,INPUT);
lcd.begin(16,2);
}
void loop()
{
val_sensor = analogRead(A0); // leitura do sensor
val_sensor_d = digitalRead(D0);
Serial.print("Sensor saida analogica : ");
Serial.println(val_sensor);
Serial.print("Sensor saida digital : ");
Serial.println(val_sensor_d);
if( val_sensor > 200)
{
digitalWrite(Led,1);
digitalWrite(buzzer,1);
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print("MONITORAMENTO ");
lcd.setCursor(2,1);
lcd.print("GAS DETECTADO");
}
else
{
digitalWrite(Led,0);
digitalWrite(buzzer,0);
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print(" SENSOR MQ2");
lcd.setCursor(0,1);
lcd.print("Valor:");
lcd.setCursor(7,1);
lcd.print(val_sensor);
lcd.setCursor(11,1);
lcd.print("D2:");
lcd.setCursor(14,1);
lcd.print(val_sensor_d);
}
delay(200);
lcd.clear();
}
It is possible to adjust the sensitivity of the sensor with a trimpot present in the module.
Next, we will analyze the results of the project.
ResultsIn figure 3 we have the system monitoring the presence of gases in the environment, displaying an analog value and a digital value without the presence of gas in the environment.
In figure 4 we have the system detecting the presence of gases in the environment.
Using a cigarette lighter to test the sensor, the setpoint configured was 200, if the sensor's analog reading was greater than 200, turn on the led and the buzzer, display the message detected gas.
The digital output of the sensor goes to a low logic level when it detects the presence of the gas.
ConclusionIn this article, we learned how to use the MQ2 sensor to detect polluting gases and thus develop an alarm system to prevent domestic accidents.
As a suggestion, we can add a gsm module to send a message to a certain number if the sensor detects the presence of gas in the environment.
I thank the JLCPCB for offering electronic boards with great prices and discounts for all of us.
Comments