JACK
Published

Gas sensor interfacing with Arduino

In this article we will learn how to make CO Gas Leak detector Using Arduino, Relay and LCD display.

ExpertFull instructions provided3 hours235
Gas sensor interfacing with Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Grove - Gas Sensor(MQ2)
Seeed Studio Grove - Gas Sensor(MQ2)
×1
Buzzer
Buzzer
×1
MINI RELAY SPDT 5 PINS 12VDC 10A 120V CONTACT
TaydaElectronics MINI RELAY SPDT 5 PINS 12VDC 10A 120V CONTACT
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
PCB Holder, Soldering Iron
PCB Holder, Soldering Iron
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires

Story

Read more

Schematics

co_gas_diagram__cqLwYfY4RD.jpg

Code

Gas Detector Circuit

C/C++
#include <LiquidCrystal.h>
// Gas Sensor Pin Configuration
const int MQ7SensorPin = A0;
// Relay Module Pin Configuration
const int RelayPin = 8; // You can use any digital pin
// LCD Configuration
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // Adjust the pin numbers as needed
void setup() {
pinMode(RelayPin, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2); // Initialize the LCD with its dimensions
lcd.clear(); // Clear the display
}
void loop() {
int sensorValue = analogRead(MQ7SensorPin);
// Convert the analog value to voltage (0-5V)
float voltage = (sensorValue / 1023.0) * 5.0;
// Define a threshold level for CO gas detection
float threshold = 3.0; // You may need to adjust this value
lcd.setCursor(0, 0);
lcd.print("CO Gas Detector");
if (voltage > threshold) {
lcd.setCursor(0, 1);
lcd.print("Danger:Gas!");
Serial.println("Danger: High CO gas detected!");
digitalWrite(RelayPin,HIGH); // Turn on the relay
} else {
lcd.setCursor(0, 0);
lcd.print("CO levels normal");
Serial.println("CO gas levels normal.");
digitalWrite(RelayPin, LOW); // Turn off the relay
}
delay(500); // Delay between readings (adjust as needed)
}

Credits

JACK

JACK

21 projects • 2 followers

Comments