Arduino Gas Sensor Alarm System
Arduino Code
int gasSensor = A0;
int buzzer = 13;
int led = 11;
void setup() {
pinMode(A0, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
[Link](9600);
}
void loop() {
int sensorValue = analogRead(gasSensor);
[Link]("Sensor Value: ");
[Link](sensorValue);
delay(1000);
if(sensorValue > 250) {
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
}
else {
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
}
}
Code Summary
Components Used
Component Arduino Pin Type
Gas Sensor A0 Analog Input
Buzzer 13 Digital Output
generated by "Markdown to PDF Fast Converter" 👉 [Link]
Component Arduino Pin Type
LED 11 Digital Output
Functionality
Gas Detection System:
Continuously reads gas sensor analog value (0-1023)
Monitors gas concentration levels
Triggers alarm when gas level exceeds threshold
Alarm Conditions:
Sensor Value Buzzer LED Status
> 250 ON ON Gas Detected!
≤ 250 OFF OFF Normal
Operation Flow
1. Read Sensor: Analog value from gas sensor on pin A0
2. Display: Send sensor value to Serial Monitor at 9600 baud
3. Check Threshold: Compare reading with threshold (250)
4. Activate Alarm: If exceeded, turn on buzzer and LED
5. Wait: Delay 1 second before next reading
Hardware Setup
Gas Sensor (MQ-2/MQ-5):
VCC → Arduino 5V
GND → Arduino GND
AO (Analog Output) → Arduino A0
Buzzer:
Positive (+) → Arduino Pin 13
Negative (-) → Arduino GND
generated by "Markdown to PDF Fast Converter" 👉 [Link]
LED:
Anode (long leg) → Arduino Pin 11 (with 220Ω resistor)
Cathode (short leg) → Arduino GND
Configuration
Threshold Setting:
Current threshold: 250 (analog value)
Adjustable based on gas type and sensitivity required
Range: 0-1023
Detection Delay:
1 second between readings
Prevents rapid fluctuations
Can be adjusted via delay() function
Serial Monitor Output Example
Sensor Value: 180
Sensor Value: 195
Sensor Value: 265
Sensor Value: 290
Sensor Value: 220
Safety Notes
⚠️ Important:
Calibrate sensor before use
Test in well-ventilated area
Adjust threshold based on gas type
Use appropriate gas sensor for target gas
This is a basic detection system - use professional equipment fo
generated by "Markdown to PDF Fast Converter" 👉 [Link]