Garrett Colby
Published © GPL3+

MEGR 3171 Fire Detector

Uses 2 Particle Photons to detect flames via an IR sensor and transmit the data.

BeginnerFull instructions provided1 hour530
MEGR 3171 Fire Detector

Things used in this project

Hardware components

Photon
Particle Photon
×2
Buzzer
Buzzer
Active Buzzer from Arduino sensor kit
×1
Flame Sensor
×1
5 mm LED: Red
5 mm LED: Red
×2
LED, Blue
LED, Blue
×1
Resistor
Any Resistor value should work
×1
Jumper wires (generic)
Jumper wires (generic)
×8

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Detector Schematic

Receiver Schematic

Code

Detector Code

Processing
int sensor = A5;        //Pin Declaration
int alarm = D6;         //Pin Declaration
int status = D7;        //Pin Declaration

int detect = 0;         //Pin Data

bool fire = false;      //Flag
bool buzz = false;      //Flag

void setup() {
    Serial.begin(9600);                                         //Has to do with hardware ports
    pinMode(sensor, INPUT);                                     //Pin Setup
    pinMode(alarm, OUTPUT);                                     //Pin Setup
    pinMode(status, OUTPUT);                                    //Pin Setup
    Particle.subscribe("alarmoff", buzzOff, MY_DEVICES);        //Listen for Alarm Off
    Particle.variable("detect", detect);                        //allows me to read the value of detect from CMD prompt
}

void loop() {
    detect = analogRead(sensor);                                //Get input from sensor
    if(detect <= 2900 && fire == false){                        //If sensor reads fire and there wasn't a fire last clock cycle
        String num = String(detect);                            //Converts int to string so it can be published
        digitalWrite(alarm, HIGH);                              //Turn on the alarm
        digitalWrite(status, HIGH);                             //Turn on the D7 LED
        fire = true;                                            //Set the Fire Flag to True
        Particle.publish("Fire_Detected", "fire", PRIVATE);     //Let the other Particle know there was a fire
        Particle.publish("Fire_Value", num, PRIVATE);           //Give ThingSpeak a value to graph
        delay(2000);                                            //Prevents overflow of publish events
    }else if(buzz == true && fire == true){                     //If there is still a fire and you have been told to buzz off
        digitalWrite(alarm, LOW);                               //Turn off the alarm
        buzz = false;
    }
    
    if(fire == true && detect >= 2900){                         //If no fire
        Particle.publish("Fire_Detected", "nofire", PRIVATE);   //Let the other Particle know there was a fire
        digitalWrite(alarm, LOW);                               //Turn off the alarm
        digitalWrite(status, LOW);                              //Turn off the D7 LED
        fire = false;                                           //Set the Fire Flag to False
    }
}

void buzzOff(const char *event, const char *data){              //Function that runs when an "alarmoff" event is published
    if(strcmp(data, "off") == 0){                               //If the event was published
        buzz = true;                                            //Set Flag of buzz to True
    }    
}

Receiver Code

Processing
int status = D7;        //Pin Declaration
int press = D6;         //Pin Declaration

bool actnow = false;    //Flag

void setup() {
    Particle.subscribe("Fire_Detected", panicMode, MY_DEVICES);   //Subscribe to the other photon to get fire info
    pinMode(status, OUTPUT);
    pinMode(press, INPUT);
    Serial.begin(9600);                                           //Has to do with hardware ports
}

void loop() {
    if(actnow == true && digitalRead(press) == HIGH){
        Particle.publish("alarmoff", "off", PRIVATE);             //Let the other Particle know we aknowledged the fire
        delay(2000);
    }
}

void panicMode(const char *event, const char *data){              //Function that runs when an "alarmoff" event is published
    if(strcmp(data,"fire") == 0){                                 //If the event data "fire" was published
        actnow = true;                                            //Set Flag to True
        digitalWrite(status, HIGH);                               //Turn on LED
    }else if(strcmp(data,"nofire") == 0){                         //Else if "nofire" was published
        actnow = false;                                           //Set Flag to false
        digitalWrite(status, LOW);                                //Turn off LED
    }   
}

Credits

Garrett Colby

Garrett Colby

1 project • 1 follower

Comments