Elsa LeeLindsey Brewer
Published © GPL3+

Monitoring Your Fridge Door Activity

Keep tabs on your refrigerator door to maintain the quality of the contents inside, save energy, and save money.

BeginnerFull instructions provided2 hours656
Monitoring Your Fridge Door Activity

Things used in this project

Hardware components

Photon
Particle Photon
×2
Breadboard (generic)
Breadboard (generic)
×3
Buzzer, Piezo
Buzzer, Piezo
×1
Push Button 12mm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets
Maker service
IFTTT Maker service

Hand tools and fabrication machines

Tape, Double Sided
Tape, Double Sided

Story

Read more

Schematics

System Schematic

Code

Photon 1 Code

C/C++
unsigned long lastdoortime=0;
int buttonPin = D3;
int buzzerPin = D4;
int currentdoorstate=0;
int lastdoorstate=0;
int led = D7;

void setup() {
    pinMode(buttonPin, INPUT_PULLUP); //Applies 3 Volts to the pullup resistor 
    pinMode(buzzerPin, OUTPUT);
    pinMode(D7, OUTPUT); //write voltage to pin
    digitalWrite(led, LOW); //have LED off initially
    
    Particle.subscribe("fridgeneedshelp2", helpthefridge2,"430035000847373336323230"); //subscribe to event from device you are recieving from
    Particle.subscribe("fridgeisgood2", leavefridgealone2,"430035000847373336323230"); //subscribe to event from device you are recieving from
}

//These next LED responses are triggered from the LED responses on the other photon
void helpthefridge2(const char *event, const char *data) //call on the function
{
    digitalWrite(D7,HIGH); //turns LED on
}                                    
void leavefridgealone2(const char *event, const char *data) //call on the function
{   
    digitalWrite(D7,LOW); //turns LED off
}

void loop() {
    currentdoorstate=digitalRead(buttonPin);
    if ((currentdoorstate == LOW)) //If button is low then fridge is shut
       
    {
        digitalWrite(buzzerPin, LOW);
        Particle.publish("fridgeisgood","leavefridgealone", PUBLIC);
        delay(2000);
    }
    if ((currentdoorstate == HIGH) && (lastdoorstate==LOW)) //If button is high then fridge is open but we want to wait # seconds before buzzer goes off
       
    {
       digitalWrite(buzzerPin, LOW); //buzzer pin should not be on yet, we are only defining that the door has been opened here
       delay(2000);
       lastdoortime=millis(); //we are recording the latest time after the door has been opened
    }
    else //counter has already started, buzzer will go off after # seconds
    {
       if(((millis()-lastdoortime)>14000) && currentdoorstate==HIGH) //If current door state is open and it has been # seconds the buzzer will go off
       {
            lastdoortime=millis();
            digitalWrite(buzzerPin, HIGH);
            delay(2000);          
            Particle.publish("fridgeneedshelp", "helpthefridge", PUBLIC);

       }
    }
    lastdoorstate=currentdoorstate; //door state is updated here
    
}

Photon 2 Code

C/C++
int led = D7;

void setup() {
    pinMode(D7, OUTPUT); //write voltage to pin
    digitalWrite(led, LOW); //have LED off initially
    
    Particle.subscribe("fridgeneedshelp", helpthefridge,"2d0045000347343339373536"); //subscribe to event from device you are recieving from
    Particle.subscribe("fridgeisgood", leavefridgealone,"2d0045000347343339373536"); //subscribe to event from device you are recieving from
    }

void helpthefridge(const char *event, const char *data) //call on the function
{
    digitalWrite(D7,HIGH); //turns LED on
    Particle.publish("fridgeneedshelp2", "helpthefridge2", PUBLIC);
}                                    
void leavefridgealone(const char *event, const char *data) //call on the function
{   
    digitalWrite(D7,LOW); //turns LED off
    Particle.publish("fridgeisgood2", "helpthefridge2", PUBLIC);
}
void loop() {

}

Credits

Elsa Lee

Elsa Lee

1 project • 0 followers
Lindsey Brewer

Lindsey Brewer

1 project • 0 followers
Thanks to pixabay.

Comments