David K
Published © CC0

Fridge door alarm, ESP8266, Arduino, Blynk, magnetic sensor

A magnetic sensor sends notification to the phone when you forget to close the fridge door.

BeginnerFull instructions provided1 hour1,751
Fridge door alarm, ESP8266, Arduino, Blynk, magnetic sensor

Things used in this project

Hardware components

Adafruit Feather HUZZAH with ESP8266 WiFi
Adafruit Feather HUZZAH with ESP8266 WiFi
×1
Reed Switch, SPST-NO
Reed Switch, SPST-NO
×2
Jumper wires (generic)
Jumper wires (generic)
×2

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Schematics

Schematic

Code

The code for the adafruit board written in Arduino IDE.

Arduino
The code done in Arudion IDE. You have to input your Blynk Auth Token, WiFi SSID and WiFi password.
//Magnetic switch output to blynk by the David Karabalin 
/**************************************************************
 * Blynk links
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * This example shows how value can be pushed from Arduino to
 * the Blynk App.
 *
 * WARNING :
 * For this example you'll need SimpleTimer library:
 *   https://github.com/jfturcot/SimpleTimer
 *
 * App project setup:
 *   LED widged attched to V4
 *
 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "[Here goes your Auth Token]";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "[WiFi SSID]";
char pass[] = "[WiFi Password]";

int StatMagSwitch = 0; // switch status setting to 0 or LOW initially, door closed
int OpenDoorCycles = 0; //counts number of cycles as fridge door is open
unsigned long AlertTimeInSec = 60; // time after which to alert if fridge is open it's not accurate becase cycle will be long
unsigned long CycleTimeInSec = 15; // how often it measures the door sensor

#define MAGPIN 12          // pin for magnetic switch

BlynkTimer timer;          // Initializing blynk

WidgetLED ledDoor(V4);     //Setting led widget as virtual pin 4 first
// This function sends Arduino's up time every second to Virtual Pin (4).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App

void sendReadings()
{ StatMagSwitch = digitalRead(MAGPIN);  // Reading Magnetic switch status 

  if (StatMagSwitch == 1) // status is 1 if magnet is far away HIGH
  {
   OpenDoorCycles += 1; 
   ledDoor.on(); //turning on if magnet far away, i.e. Switch is HIGH
  } 
  else 
  {
   OpenDoorCycles = 0;
   ledDoor.off(); //turning off if magnet is close, i.e. Switch is LOW
  }
  
  if (OpenDoorCycles*CycleTimeInSec >= AlertTimeInSec)
  {
    Blynk.notify("ALERT! THE FRIDGE DOOR IS OPEN");
    OpenDoorCycles = 0;
   }
  
}

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  pinMode(MAGPIN, INPUT_PULLUP); // Defining magnetic switch pin as input_pullup
  Blynk.begin(auth, ssid, pass);

  // Setup a function to be called every second
  timer.setInterval(CycleTimeInSec*1000UL, sendReadings);
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}

Credits

David K

David K

2 projects • 2 followers
I was born in 2007, I was in middle school when I posted my first project.

Comments

Add projectSign up / Login