#define led 12 // Connect LED to pin 12
#define smoke A5 // Connect sensor analog output to A5
int threshold = 400; // Threshold for smoke detection
void setup() {
pinMode(led, OUTPUT); // Set LED as output
pinMode(smoke, INPUT); // Set smoke sensor as input
Serial.begin(9600); // Start serial communication
}
void loop() {
int value = analogRead(smoke); // Read sensor value
Serial.println(value); // Print sensor reading to Serial Monitor
// Check if smoke level exceeds threshold
if (value > threshold) {
digitalWrite(led, HIGH); // Turn LED ON (smoke detected)
} else {
digitalWrite(led, LOW); // Turn LED OFF (no smoke)
}
delay(1000); // Wait 1 second before next reading
}
Instruction Details
Wiring: Connect smoke/gas sensor VCC to 5V, GND to GND, A0 to Analog Pin A5. Connect LED anode to Digital Pin 12 via 220Ω, cathode to GND.
Library: Not required (built-in).
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: Open Serial Monitor at 9600 baud. LED turns ON when smoke detected. Heat sensor 24–48 hours before first use.
How to Use
Connect the required components as per the Pin Configuration above
Open Arduino IDE and create a new sketch
Copy and paste the code above
Select your Arduino board and COM port from Tools menu
Click the Upload button to upload the code to your Arduino
Open Serial Monitor (if applicable) to see the output