Carson DraughnMatthewGarrett Stegall
Published © GPL3+

Kitchen Temperature/Gas/Smoke Sensor

When life makes you step away from the kitchen, this system offers temperature and gas/smoke monitoring and warnings!

IntermediateFull instructions provided10 hours21
Kitchen Temperature/Gas/Smoke Sensor

Things used in this project

Hardware components

Grove - Gas Sensor(MQ2)
Seeed Grove - Gas Sensor(MQ2)
×1
Argon
Particle Argon
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
Included in smoke/gas sensor circuit.
×4
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×3
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×4
KY-028 Temperature Sensor
×1
HC-SR501 Motion Sensor
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Fritzing
App used to make circuit schematics.
ThingSpeak API
ThingSpeak API
Used for Live Graphing

Hand tools and fabrication machines

Digilent Screwdriver
Digilent Screwdriver

Story

Read more

Schematics

Smoke Sensor Circuit

Motion Sensor Circuit

Temperature Sensor Circuit

Code

Temperature Sensor

C/C++
This is the temperature sensor code. It receives data from the motion sensor, then using the temperature data will output to the cloud either "Alarm" or "Noalarm".
int temp;
char tempstr[30];
// the setup routine runs once when you press reset:
void setup() {
pinMode(A0, INPUT);
pinMode(D2, OUTPUT);
pinMode(D3, INPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  Particle.variable("temp", temp);
  Particle.subscribe("motion", myHandler,("e00fce68e492a4e6bb553c3d"));
  Particle.subscribe("smoke/gas present", myHandler, "e00fce6839934a33c1772922");
}



void myHandler(const char *event, const char *data)
{
    if ((strcmp(data,"motion")==0))
        digitalWrite(D2, HIGH);
    if ((strcmp(data, "Smoke or Gas Detected in Kitchen")==0))
        Particle.publish("temp," "Alarm", PRIVATE);
    else
    digitalWrite(D2, LOW);
}
// the loop routine runs over and over again forever:
void loop() 
{
   int MotionValue= digitalRead(D3);
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(2000);// delay in between reads for stability
  temp = sensorValue;
  String temp1 = String(temp);
  Particle.publish("temp1", temp1, PRIVATE);
  
  if (temp < 650 && MotionValue == LOW)
    Particle.publish("temp","Alarm",PRIVATE);
  else
    Particle.publish("temp","NoAlarm",PRIVATE);
  
 
}

Smoke/Gas Sensor

C/C++
This is the code for the smoke/gas alarm component of the system. It detects changes in the nearby air and publishes events to the cloud based on readings from the sensor.
int smokeAnalog = A0;
int WarningLight = D7;                              //sets variables for pins
int smokeDigital = D2;

void setup() 

{
pinMode(WarningLight, OUTPUT);
pinMode(smokeDigital, INPUT);                       //sets input and output pins
pinMode(smokeAnalog, INPUT);
digitalWrite(WarningLight, HIGH);               
delay(1500);                                        //3 SLOW blinks to let user know system is turning on
digitalWrite(WarningLight, LOW);                
delay(1000);
digitalWrite(WarningLight, HIGH);               
delay(1500);
digitalWrite(WarningLight, LOW);                
delay(1000);   
digitalWrite(WarningLight, HIGH);               
delay(1500);
digitalWrite(WarningLight, LOW);                

delay(15000);                                       //15s delay allows sensor to warm-up

digitalWrite(WarningLight, HIGH);                   //3 FAST blinks to signal accurate data aquisition
delay(300);                                       
digitalWrite(WarningLight, LOW);                
delay(150);
digitalWrite(WarningLight, HIGH);               
delay(300);
digitalWrite(WarningLight, LOW);                
delay(150);   
digitalWrite(WarningLight, HIGH);               
delay(300);

Particle.variable("analogvalue", smokeAnalog);      //sets variables to be called and uploaded to console
Particle.variable("digitalvalue", smokeDigital);
Particle.subscribe("motion", myHandler,("e00fce68e492a4e6bb553c3d"));
}

void loop() 

{ 
smokeAnalog = analogRead(A0);                       //these variables will be updated at the beginning of each loop based on pin values
smokeDigital = digitalRead(D2);
delay(1000);
 if (smokeAnalog > 2850)                            //if analog value exceeds tested smoke value, the LED will be lit
 {
     digitalWrite(WarningLight, HIGH);
     Particle.publish("smoke/gas present", "Smoke or Gas Detected in Kitchen", PRIVATE);
 } 
 else 
 {
     digitalWrite(WarningLight, LOW); 
     Particle.publish("no smoke/gas", "All Clear", PRIVATE);
      }
      
delay(2000);                                        //wait 2s for next reading
}

void myHandler(const char *event, const char *data)
{
    if ((strcmp(data,"motion")==0))
        Particle.publish("no smoke/gas", "All Clear", PRIVATE);
        // This is added to 1. Keep the smoke detector from setting off the Alarm when you're present, cause if there is a fire you'll--
        // see it and probably dont want an alarm in your ear frustrating you even more.  2. Added to compete 2 sets of bi-directional comms.
}
        

Motion Sensor

C/C++
The code for the motion sensor receives the digital output from the motion detector, then outputs it to the cloud as either "motion" or "nomotion". It receives from the cloud either "Alarm" or "Noalarm" which controls whether or not to turn on the LED.
int motion;

void setup() {
;
Particle.variable("motion", motion);
pinMode(D6,INPUT);
pinMode(D5,OUTPUT);
pinMode(D3,OUTPUT);

Particle.subscribe("temp", myHandler, "e00fce683f281150ed690fe9");
Particle.subscribe("smoke/gas present", myHandler, "e00fce6839934a33c1772922");
  
}


// the loop routine runs over and over again forever:
void loop() {
  
  int motion = digitalRead(D6);
  
 
  
  digitalWrite(D5, motion);
  
 if (motion == HIGH)
  Particle.publish("motion", "motion", PRIVATE);
 else if (motion == LOW)
   Particle.publish("motion", "nomotion",  PRIVATE);
  

delay(1000);
}


  void myHandler(const char *event, const char *data)
{

        if ((strcmp(data,"Alarm")==0))
    digitalWrite(D3, HIGH);
        if ((strcmp(data, "Smoke or Gas Detected in Kitchen"))==0)
    digitalWrite(D3, HIGH);
        else
    digitalWrite(D3, LOW);
}

Credits

Carson Draughn

Carson Draughn

1 project • 0 followers
Matthew

Matthew

1 project • 0 followers
Garrett Stegall

Garrett Stegall

0 projects • 0 followers
Thanks to Carson Draughn, Garrett Stegall, and Matthew Burns.

Comments

Add projectSign up / Login