Devices & Components
Arduino Uno Rev3
Micro Servo Motor
LM393 Flame Sensor
MQ2(gas sensor)
Software & Tools
Arduino IDE
Project description
Code
arduino leakage detection
c
program for gas and flame detection project
1#include <Servo.h> 2 3Servo servoMotor; 4 5#define LEFT_FLAME 2 6#define RIGHT_FLAME 3 7#define SERVO_PIN 9 8 9void setup() { 10 pinMode(LEFT_FLAME, INPUT); 11 pinMode(RIGHT_FLAME, INPUT); 12 13 servoMotor.attach(SERVO_PIN); 14 servoMotor.write(90); // start centered 15 delay(500); 16} 17 18void loop() { 19 int leftState = digitalRead(LEFT_FLAME); 20 int rightState = digitalRead(RIGHT_FLAME); 21 22 // Note: LOW = Flame detected, HIGH = No flame 23 if (leftState == LOW && rightState == HIGH) { 24 // Left flame detected 25 servoMotor.write(0); // Move extreme left 26 } 27 else if (rightState == LOW && leftState == HIGH) { 28 // Right flame detected 29 servoMotor.write(180); // Move extreme right 30 } 31 else if (leftState == LOW && rightState == LOW) { 32 // Flame detected on both sides (center) 33 servoMotor.write(90); 34 } 35 else { 36 // No flame 37 servoMotor.write(90); 38 } 39 40 delay(100); 41}
Comments
Only logged in users can leave comments