Devices & Components
Arduino Uno Rev3
Grove - Buzzer - Piezo
MQ2 gas and smoke sensor
flame sensor
LED (generic)
Resistor 330 ohm
Software & Tools
Proteus 8 professional
Arduino IDE
Project description
Code
Here is the code for this project
cpp
1// ANALOG 2int gasPin = A0; 3int flamePin = A1; 4 5int gasThreshold = 400; 6int flameThreshold = 350; 7 8// OUTPUT 9int buzzer = 8; 10int led = 9; 11 12void setup() { 13 Serial.begin(9600); 14 15 pinMode(buzzer, OUTPUT); 16 pinMode(led, OUTPUT); 17 18 digitalWrite(buzzer, LOW); 19 digitalWrite(led, LOW); 20} 21 22void loop() { 23 24 int gasValue = analogRead(gasPin); 25 int flameValue = analogRead(flamePin); 26 27 Serial.print("Gas: "); 28 Serial.print(gasValue); 29 Serial.print(" | Flame: "); 30 Serial.println(flameValue); 31 delay(200); 32 33 if (gasValue > gasThreshold || flameValue > flameThreshold) { 34 digitalWrite(buzzer, HIGH); 35 36 // LED 37 digitalWrite(led, HIGH); 38 delay(200); 39 digitalWrite(led, LOW); 40 delay(200); 41 42 } else { 43 digitalWrite(buzzer, LOW); 44 digitalWrite(led, LOW); 45 } 46}
Downloadable files
Diagram
gas-flame.jpg

Comments
Only logged in users can leave comments