You are on page 1of 1

// Define the pin numbers for the components

const int flameSensorPin = 8; // Digital pin for the flame sensor


const int buzzerPin = 4; // Digital pin for the buzzer
const int relayPin = 12; // Digital pin for the relay

void setup() {
// Set the buzzer and relay pins as output
pinMode(buzzerPin, OUTPUT);
pinMode(relayPin, OUTPUT);

// Set the flame sensor pin as input


pinMode(flameSensorPin, INPUT);

// Initialize the serial communication for debugging


Serial.begin(9600);
}

void loop() {
// Read the digital value from the flame sensor
int flameValue = digitalRead(flameSensorPin);

// Print the flame value for debugging


Serial.print("Flame Value: ");
Serial.println(flameValue);

// Check if the flame sensor detects fire (flameValue is HIGH)


if (flameValue == HIGH) {
// Sound the buzzer
digitalWrite(buzzerPin, LOW);

// Turn on the relay


digitalWrite(relayPin, HIGH);

// Print a message indicating fire detection


Serial.println("Fire detected!");
} else {
// Turn off the buzzer
digitalWrite(buzzerPin, HIGH);

// Turn off the relay


digitalWrite(relayPin, LOW);
}

// Delay for a short period before reading the sensor again


delay(1000);
}

You might also like