0% found this document useful (0 votes)
5 views

Flam Sensor Code

Uploaded by

rfid035
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Flam Sensor Code

Uploaded by

rfid035
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

const int flameDigitalPin = 2;

const int flameAnalogPin = A0;

bool flameLastState = HIGH;


int lastFlameIntensity = 0;

void setup() {

Serial.begin(9600);

pinMode(flameDigitalPin, INPUT);

pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {

int flameDetected = digitalRead(flameDigitalPin);

int flameIntensity = analogRead(flameAnalogPin);

if (flameDetected != flameLastState) {
flameLastState = flameDetected;

if (flameDetected == LOW) {
Serial.println("Flame detected!");
digitalWrite(LED_BUILTIN, HIGH);
} else {
Serial.println("No flame detected.");
digitalWrite(LED_BUILTIN, LOW);
}
}

if (flameDetected == LOW && flameIntensity != lastFlameIntensity) {


if (flameIntensity > lastFlameIntensity) {
Serial.print("Flame intensity increasing: ");
} else {
Serial.print("Flame intensity decreasing: ");
}

Serial.println(flameIntensity);

lastFlameIntensity = flameIntensity;
}

delay(100);
}

You might also like