Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Daisy Castellon ChavezAdam Antolick
Published

Motion Sensor Smoke Detector - MEGR 3171 Group 28

Safety is one of the main issues that the hearing-impaired community struggle with! There has not been any solution yet until now.

BeginnerFull instructions provided115
Motion Sensor Smoke Detector - MEGR 3171 Group 28

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×2
Breadboard (generic)
Breadboard (generic)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
IR receiver (generic)
×1
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Orange
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
USB-A to USB Micro C
×2
Handheld Lighter
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Particle Console
ThingSpeak API
ThingSpeak API
Fritzing
YouTube Video

Story

Read more

Schematics

Infrared (IR) Receiver Sensor Photon Circuit Diagram

The circuit diagram attached below shows how we constructed our Infrared Receiver Sensor Photon circuit, which that allows for our codding to collect data if there is a sense of fire /smoke.

PIR Motion Sensor Photon Circuit Diagram

The circuit diagram attached below shows how we constructed our PIR Motion Sensor Photon circuit that allows for our codding to collect data.

Flow Chart

This flow chart goes into detail about the communication and information given and received between the two photons with the help of ThingSpeak

Fire/Smoke Sensor and Motion Sensor Data

The data collected through ThingSpeak

Code

PIR Motion Sensor Photon Code

C/C++
This is the code that is used for the PIR motion sensor for this project. It first warms up the sensor and sends out a notification that the sensor is active to the user's phone. Then the code goes through a loop of checking if the motion sensor senses anything. If no motion is detected the code sends a value of 1 to the webhook. If motion is detected the code checks if the other photon's fire sensor detects fire. If the fire sensor detects fire the code acts as if no motion was detected to not act like a fire was a person and sends out a value of 1. If there is no fire detected then a value of 2 is sent to the webhook to indicate that motion was detected. Then the code checks for motion again.
	/* PIR sensor O/P pin */
int receivedinteger =0; //global int var
float receivedfloat = 0;

int inputPin = D2;
int ledPin = D6;
int pirState = LOW;
int val = 0; 
int ledout = D5;
int calibrateTime = 10000;

void myHandler(const char *event, const char *data)
{
    receivedinteger = String(data).toInt();
    
    receivedfloat = String(data).toFloat();
}


void setup() 
{
    pinMode(ledPin, OUTPUT );   
    pinMode(inputPin, INPUT);
    pinMode(ledout, OUTPUT);
    digitalWrite(ledout, LOW);
    Particle.subscribe("fire", myHandler);
	Particle.publish("push", "motion sensor is active");
}

void loop() {
    

 Serial.println(receivedinteger);  //using a global variable you can see it anywhere in your code
    Serial.println(receivedfloat);
    receivedfloat = receivedfloat*1.1;
    delay(500);


    if (calibrated())
    {
        readTheSensor();
        reportTheData();
    }  

}
void readTheSensor() {
    
        val = digitalRead(inputPin);
    }
bool calibrated()
    {
        return millis() - calibrateTime > 0;
    }
void reportTheData()
{
        if (val == HIGH)
        {
          
            pirState = HIGH;
            setLED( pirState );
            digitalWrite(ledout, HIGH);
            delay(5000);
            digitalWrite(ledout, LOW);
            delay(5000);
             if (receivedfloat = 2)
            {
                String data = String(1);
            }
            else
            {
                String data = String(2);
            }
            Particle.publish("motion", data, PRIVATE);
        }
        
        else 
        { 
            String data = String(1);
            Particle.publish("motion", data, PRIVATE);
            digitalWrite(ledout, LOW);
        pirState = LOW;
        setLED( pirState );
        delay(5000);
        }
    }
  
void setLED (int state)
    { 
        digitalWrite( ledPin, state );
    }

//void myHandler(const char *event, const char *data)
    //{
        //digitalWrite(ledout, HIGH);
        //delay(5000);
        //digitalWrite(ledout, LOW);
  //  }

Infrared (IR) Receiver Sensor Photon Code

C/C++
This code starts by sending out a notification to the user's phone stating that the fire sensor is active, and checking if the motion sensor detects motion. If the motion sensor detects motion. If motion is detected by the motion sensor then it will turn on an led connected to D6. Then the sensor starts checking for fire. If fire is detected the code sends out a number of "2" to the webhook and sends out a notification stating "Fire Fire Fire!" to the user's phone. If no fire was detected it will send out a value of "1" to the webhook. Then the code scans for fire again.
int receivedinteger =0; //global int var
float receivedfloat = 0; //global float var

int i = 0;
int sensor = D2;
int light = D6;
int val = 0;
int other = 0;


void myHandler(const char *event, const char *data)
{
    receivedinteger = String(data).toInt();
    
    receivedfloat = String(data).toFloat();
    digitalWrite(light, HIGH);
}
void setup() {
    pinMode( sensor, INPUT);
    pinMode( light, OUTPUT);
    digitalWrite(light, LOW);
    Serial.begin(9600);
    pinMode(D7, OUTPUT);
    Particle.subscribe("motion", myHandler);
    Particle.publish("push", "smoke detector is active");
}




void loop() {
 Serial.println(receivedinteger);  //using a global variable you can see it anywhere in your code
    Serial.println(receivedfloat);
    receivedfloat = receivedfloat*1.1;
    delay(500);
   
    digitalWrite(light,LOW);    
    val = digitalRead(sensor);
  if (receivedfloat = 2)
  {
      digitalWrite(light, HIGH);
  delay(5000);
  digitalWrite(light, LOW);
  }
  else
  {
     digitalWrite(light, LOW);
     delay(5000);
  }
    if (val == LOW)
    { 
        String data = String(1);
        Particle.publish("fire", data, PRIVATE);
       
        delay(5000);
    }
    
    else
    {
        String data = String(2);
        Particle.publish("fire", data, PRIVATE);
        Particle.publish("push", "FIRE FIRE FIRE!" );
        delay(5000);
    }

}

Credits

Daisy Castellon Chavez
1 project • 1 follower
Contact
Adam Antolick
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.