Introduction and Project Scope
The Idea Behind the Project
The concept is simple: The gas sensor changes resistance to detect dangerous gases, which we interpret as a voltage reading on the Arduino. We assign this a "percentage" (more or less a rough estimate—true experts calibrate using gas). If it goes over 50%, we have a leak, turn on the fan to blow out gas, sound an alarm (which I will add because your original design does not include one, and this is a problem), and display "Alert!" on the LCD screen. Below or at 50%, turn off all systems and display "Safe."
But here’s the counterpoint: Your “percentage” isn’t scientific—it’s simply correlating raw sensor readings (0-1023) to 0-100%. You’re not calibrating in a controlled setting (which you can’t do as a beginner), so this is all speculation. Sensors also take 20-60 seconds to warm up and can be deceived by humidity, temperature, or other vapors (such as alcohol). The fan “cleaning” the air? Please, it’s optimistic at best—it might work in a small room, but in reality, you should evacuate the space and call a professional. The concept is good for learning but bad for implementation. It needs hysteresis (a “buffer zone”) to keep the fan from turning on and off rapidly because of noise—it’s a common issue for beginners that you’ll run into.
Parts Required
Don't cheap out on quality; knockoffs break
easily. Here's what you need—buy from reliable spots like Amazon, Adafruit, or
AliExpress, but check reviews.
- Arduino Board: Uno or Nano . Purchase link
- Gas Sensor: MQ-7 (for smoke/LPG/CO) Purchase Link
- Fan: Small 5V DC Purchase link
- Relay Module: Single-channel 5V
relay . Purchase link
- 16x2 I2C LCD Display: I2C version . Purchase link
- Jumper Wires: Male-female for
connections. Purchase link
- Breadboard: For prototyping without
soldering. Purchase link
- Power Supply: 12V DC for Arduino Purchase link
Flaw alert: No battery
backup? If power fails during a leak, your detector is dead. Add one later.
Circuit Diagram
As a beginner, this is how you should picture it before actually wiring it—errors here will kill your components. I can't show you the picture here, but you can use free software such as Fritzing (download here) or Tinkercad Circuits to simulate. Here's a step-by-step text version: 1. Gas Sensor (MQ-2): * VCC → Arduino 5V * GND → Arduino GND * A0 (analog out) → Arduino A0 pin * DO (digital out) not used yet (we'll use analog for percentage). 2. I2C LCD: * VCC → Arduino 5V * GND → Arduino GND * SDA → Arduino A4 * SCL → Arduino A5 3. Relay for Fan: * VCC → Arduino 5V * GND → Arduino GND * IN → Arduino D8 (digital pin) * Relay COM → Fan positive wire * Relay NO → External 5V+ (or Arduino 5V if low-power fan) * Fan negative → GND 4. Buzzer: * Positive → Arduino D9 * Negative → GND (add 100Ω resistor if passive) Breadboard wiring: Arduino in the middle, sensor on the left, LCD on the right, relay/fan at the bottom. Use a multimeter to check your wiring—no shorts! Most people's mistake: Forgetting GND commons. Simulate this in Tinkercad first to prevent burning your Arduino.
Video Link: - Click Here For Video
Arduino IDE Program
Install Arduino IDE (free from arduino.cc). Add libraries: LiquidCrystal_I2C (via Library Manager). Upload to board via USB.
Here's the full code—explained inline. It's improved from your vague idea: added buzzer, hysteresis (on >55%, off <45%), warm-up delay, and averaging for stable readings. Copy-paste, but tweak and understand it, or you're not learning.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Motor Pins
int IN1 = 5;
int IN2 = 6;
int IN3 = 9;
int IN4 = 10;
void setup() {
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
stopCar();
}
void loop() {
if (Serial.available()) {
char cmd = Serial.read();
switch (cmd) {
case 'F': forward(); break;
case 'B': backward(); break;
case 'L': left(); break;
case 'R': right(); break;
case 'S': stopCar(); break;
}
}
}
void forward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void backward() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void right() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void left() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void stopCar() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Share, Support, and Subscribe!!! 1. PRO KAM EXPLAINED 2. Knowledge KAM 3. PRO KAM Follow us on 1. Facebook 2. Instagram 3. Pinterest 4. Blogspot 5 Twitter If you have any other ideas to make me design, you can describe them in the comment section and if I can, I will make a designing video on it. So I am waiting #prokam #wtc #Arduino #ideas #projects #diy #how #to #ArduinoProjects #gassensor #mq-7 #TechDIY #WeTechCreators #wtczo
0 Comments