Watch Your Fridge

Introduction: Watch Your Fridge

About: Electronic is my passion. I like to work with programming devices like Arduino, ESP8266, Raspberry Pi. I enjoy design electronic projects. IG: lab_torord.

I wanted to measure how many times and for how long my fridge was opened every day.

This device check how many times and for how long you open your door fridge, then every 30 minutes, it sends that data to the IoT platform Adafruit IO.

The device is based in the ESP-01 which is able to connect via wifi to an Internet network. It has a door magnetic sensor. When the door is open, the device increases a counter and gets the ESP-01 clock time. Then after the door is closed, it gets the ESP-01 clock time again and makes a subtraction. That time and the counter are stored in two variables and send every 30 minutes to the Adafruit IO platform.

You can change the interval time between data is sent if you will.

Supplies

Step 1: Have a Hand All Components

Collect all the components that you need to implement this project.

Step 2: Make Connections

Make the connections shown in the schematic.

Be aware about these two things:

GPIO2 pin needs to be high at boot.

Remember ESP-01 works with 3.3V.

Step 3: Upload the Code

The code has two files. In the config.h you set your Adafruit credentials and network configuration like wifi name and password.

// Information about Adafruit IO
// Link: https://learn.adafruit.com/welcome-to-adafruit-io... // Adafruit invests time and resources providing this open source code. // Please support Adafruit and open source hardware by purchasing // products from Adafruit! // // Written by Todd Treece for Adafruit Industries // Copyright (c) 2016 Adafruit Industries // Licensed under the MIT license. // // All text above must be included in any redistribution. //************************** Configuration *********************************** // In the config.h you should set the Adafruit IO credentials and configure the // network settings. #include "config.h" //************************ Example Starts Here ******************************* // Variables bool valor; int count = 0; bool flag = false; unsigned long previo; unsigned long actual; unsigned long tiempo; unsigned long ttotal = 0; unsigned long intervalo = 1000; unsigned long duracion = 0; const int puerta = 2; // GPIO2 const int led = 0; // GPIO0

// set up the feeds AdafruitIO_Feed *tempo = io.feed("tempo"); AdafruitIO_Feed *cuenta = io.feed("cuenta");

void setup() { // start the serial connection Serial.begin(115200); pinMode(puerta, INPUT); pinMode(led, OUTPUT); pinMode(led_conteo, OUTPUT); pinMode(led_puerta, OUTPUT);

// wait for serial monitor to open while(! Serial);

// connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect();

// wait for a connection while(io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); }

// we are connected Serial.println(); Serial.println(io.statusText()); } void loop() { // io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); digitalWrite(led, LOW);

valor = digitalRead(puerta); // Read the sensor. If the door is close valor = High or true. If the door is open valor = low or false. if (valor == false & flag == false) { delay(200); valor = digitalRead(puerta); if (valor == false){ count++; // Increase the opening counter flag = true; previo = millis(); // Get the time at that moment } }

if (valor == true & flag == true) { delay(200);

valor = digitalRead(puerta); if (valor == true){ flag = false; actual = millis(); // Get the time at that moment.

// Increase the time variable after the door was closed. if (actual - previo > intervalo){ tiempo = actual - previo;

tiempo = tiempo/1000; // Change time from miliseconds to seconds. ttotal = tiempo + ttotal; // Add time to the total timer. } } } duracion++; // increase by one the duracion variable delay(400); if (duracion > 3800){ //Set time between data sending. // Show the variable ttotal in the serial monitor and send it to Adafruit Serial.print("sending -> "); Serial.println(ttotal); tempo->save(ttotal); // Show the variable count in the serial monitor and send it to Adafruit Serial.print("sending -> "); Serial.println(count); cuenta->save(count);

// Reset variables duracion = 0; ttotal = 0; count = 0; digitalWrite(led, HIGH); // turn on the light to show sending data delay(1000); //Delay 1 second

}

}

Step 4: Set Adafruit IO

You should open an account on Adafruit IO. After that, you need to know how it works.

Check the link below to know about Adafruit IO, there you know how you can use Adafruit the credentials, how set the feeds and how configure the dashboards.

https://learn.adafruit.com/welcome-to-adafruit-io/overview

Step 5: Test It and Enjoy

I show a picture with my Adafruit dashboards.

Note: If you are having issues connecting, please ensure you have the latest Adafruit IO Arduino library.

Be the First to Share

    Recommendations

    • Tinkercad Student Design Contest

      Tinkercad Student Design Contest
    • Plastic Challenge

      Plastic Challenge
    • Retro Tech Challenge

      Retro Tech Challenge

    Comments