Gas Alert System
Using Arduino
Detect LPG, methane & smoke with an MQ-2 sensor. Triggers buzzer + LED on gas leak. Includes circuit diagram, code, and Tinkercad simulation.
Objectives
- ✓ Detect harmful gases — LPG, methane, and smoke
- ✓ Trigger dual alert: buzzer (audible) + LED (visual)
- ✓ Build a low-cost, real-world safety system
- ✓ Learn MQ-2 sensor interfacing with Arduino
Components Required
Circuit Diagram
Step-by-Step Wiring
Connect MQ-2 Gas Sensor
Connect Red LED
Connect Buzzer
Working Principle
Arduino Code
// ── Gas Alert System | MakeMindz.com ────────────── // Detects LPG, methane, smoke via MQ-2 sensor // Triggers buzzer + LED when gas exceeds threshold // ── Pin Definitions ────────────────────────────── int gasSensor = A0; // MQ-2 analog output → A0 int led = 7; // Red LED → Digital Pin 7 int buzzer = 8; // Buzzer → Digital Pin 8 int threshold = 300; // Adjust based on sensor sensitivity // ── Setup ──────────────────────────────────────── void setup() { pinMode(led, OUTPUT); pinMode(buzzer, OUTPUT); Serial.begin(9600); // Open Serial Monitor for live readings Serial.println("Gas Alert System Ready!"); } // ── Main Loop ──────────────────────────────────── void loop() { int gasValue = analogRead(gasSensor); // 0–1023 Serial.print("Gas Level: "); Serial.println(gasValue); if (gasValue > threshold) { // ⚠ Gas detected — activate alerts digitalWrite(led, HIGH); digitalWrite(buzzer, HIGH); Serial.println("⚠ WARNING: Gas Detected!"); } else { // ✓ Air is clean — keep quiet digitalWrite(led, LOW); digitalWrite(buzzer, LOW); } delay(500); // Check every 500 milliseconds }
Tinkercad Simulation
🧪 Try it in Tinkercad
No hardware? Run the complete circuit simulation online — drag the MQ-2 sensor slider to trigger the alert.
Open SimulationHow to run the simulation:
Open Tinkercad
Click the simulation button above to open the pre-built circuit
Click "Start Simulation"
The green Start button at the top right of the Tinkercad editor
Open Serial Monitor
Click "Serial Monitor" (bottom panel) to see live gas readings
Adjust Sensor Slider
Click on the MQ-2 sensor and drag the gas concentration slider above 300 — the LED lights up and buzzer activates
Test & Modify
Change the threshold value in the code and re-simulate to see the difference
Real-World Applications
More Arduino Projects
BEGINNER
INTERMEDIATE
ADVANCED
Comments
Post a Comment