Arduino Freezer Alarm

by tommo_79 in Circuits > Arduino

2651 Views, 7 Favorites, 0 Comments

Arduino Freezer Alarm

IMG_20160618_142848.jpg

I started this project to overcome a design flaw in our freezer. Its door alarm switch is located near the hinges and requires the door to be open wide before the alarm is triggered. Our freezer door could be open several inches without the alarm going off. We've had contents spoil in the past, not to mention wasted energy.

My custom freezer alarm places an arduino in a box located on top and outside of the fridge, so cold and humidity won't be a problem. You might have to be creative to find a switch location to suit your door.

The Innards

IMG_20160618_142931.jpg

The main components of this device are:

  • Arduino pro mini (modified to save power)
  • Two 18650 lithium batteries (old laptop batteries)
  • A circuit taken from a cheap18650 power bank (can be purchased for a few dollars from eBay)
  • A peizo buzzer
  • A momentary push button switch of some kind (mine came from an old microwave door)

The power from this project comes from two 18650 batteries wired in parallel and connected to a charging and voltage converter circuit hacked from a cheap power bank. The circuit outputs 5v via a USB port and accepts 5v to recharge the batteries via a micro USB plug. At the moment I have no idea how much power this device draws!

The momentary switch sits against the edge of the freezer door, near the hinge. The switch has a travel of about 5mm, which means the door has to be open about 10mm before the switch opens.

An annoying peizo tone goes off then the alarm is triggered, it's loud enough to hear from another room of the house.

One thing I think I'll add is an external LED that blinks very briefly occasionally so you can tell if the battery is still good (or a more sophisticated low power alert).

The Brains

The alarm functions as follows:

  • The arduino is kept asleep to save power.
  • Every 30s, the arduino wakes up to see if the door switch is open.
  • If it is, a timer is enabled to wait a few minutes.
  • If after that time, the door is still open, the alarm will sound until the door is closed again.

I used the rocketscream low power library to save power, using the watchdog timer, which is a bit clunky. I experimented using the switch as an external interrupt without luck (perhaps someone could help with my code?). I also tried the narcoleptic sleep library which provides a 'sleep delay', but for some reason this disabled the pwm ability of the arduino so the peizo wouldn't work. My code may not be elegant, but it works. I'm still learning, so any constructive criticism would be appreciated.

The arduino code is below.

#include "LowPower.h"
const int buttonPin = 2; // door open button. Low when door is open. High when door is closed. const int buzzer = 9; const int led = 13; // currently using internal led

int buttonState = 0;

int doorstate = 0;

void setup() {

pinMode(buttonPin, INPUT_PULLUP);

pinMode(buzzer, OUTPUT);

pinMode(led, OUTPUT);

}

void loop() {

// doorstate 0 = idle

// doorstate 1 = door open detected,alarm not triggered

// doorstate 2 = alarm triggered


buttonState = digitalRead(buttonPin);


if(doorstate == 0){

digitalWrite(led, HIGH); // led to flash briefly to indicate the unit is still on: LowPower.powerDown(SLEEP_30MS, ADC_OFF, BOD_OFF);

digitalWrite(led, LOW); // turn LED off:

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

}


if (buttonState == LOW && doorstate == 0){ //if the door is open

doorstate = 1;

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); //wait a few min to determine if it is a genuine alarm

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

if (buttonState == LOW){ //is the door still open after the wait?

tone(buzzer, 500);// alarm tone:

doorstate = 2;

}

}

if (doorstate == 2){

if(buttonState == HIGH){

noTone(buzzer);// turn buzzer off:

doorstate = 0; }

}

}

Power Saving

To reduce the power draw of the arduino, I disabled the power led and removed the voltage regulator. This required me to provide power to the board directly via the vcc pin.

The output from the power bank provided a clean 5v source. I simply stripped the + and - wires from a USB cable to attach to the arduino pins.