Flame Sensor with Arduino Uno

Flame sensor with the Arduino

The following example uses the digital output from the sensor connected to pin D10 on the Uno. On detection of a flame in infrared spectrum the output from the sensor goes low and an alarm sounds. The alarm sound is from a piezo transducer connected between pins D8 & D9.

/* Detect a flame using IR flame sensor and sound an alarm.

const int sounder_A = 8;  //sounder port definitions.
const int sounder_B = 9; 
const int sensor = 10; //flame sensor port.
bool flame = 1;     //variable to hold the sensor state. The sensor is active
                    //low, so initialised high.

void setup()
pinMode(sounder_A, OUTPUT); //connect the piezo across two ports
pinMode(sounder_B, OUTPUT); //to double the signal amplitude.
pinMode(sensor, INPUT); //initialise the flame sensor input.

// Call function with parameters - duration in mSecs, freq in Hz
void beep(long duration, int freq) {
    duration *= 1000;   //convert the duration to microseconds
    int period 1.0 / freq) * 1000000; //get the oscillation period in microseconds
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(sounder_A, HIGH); //Piezo ports go hi/lo then lo/hi
        digitalWrite(sounder_B, LOW);  //to generate the tone
        delayMicroseconds(period / 2);
        digitalWrite(sounder_A, LOW);
        digitalWrite(sounder_B, HIGH);
        delayMicroseconds(period / 2);
        elapsed_time +period);
        digitalWrite(sounder_A, LOW);  //kill the output
        digitalWrite(sounder_B, LOW);
void loop()
    flame = digitalRead(sensor);
    if (!flame){
        for(int i=0; i<5; i++){
            beep(500, 4000);
Your IP Address is:
Copyright © 2022 Bitsbox. Powered by Zen Cart