Fridge Door Alarm + Weather Forecast

This handy gadget serves as both a fridge door alarm — make a noise when the door is open for too long — and as a weather forecaster. The first part is simple, using reed switches to monitor the doors and a buzzer to sound the alarm. The forecasting is a bit more complicated and works by fetching weather data from a news site and parses the relevant numbers from that. The brains of the system is a Raspberry Pi Zero, running a python program, with the information being displayed on an LCD screen.

The device solves two actual problems. Firstly, in the past it has sometimes happened that I have left a door in the fridge open, and the fridge’s own alarm system did not notice it. Even though the Bosch machine is otherwise of great quality, the alarm does not recognize if the door is only slightly ajar. This can compromise the contents of the fridge, possibly totaling quite a lot of money. Secondly, looking at the weather forecast has become increasingly important since our child is in the daycare. They will spend time outside playing during the day, regardless of the weather, so knowing when to pack rain clothing with him is paramount.

The display shows the temperature and the chance of rain in the next 8 hours, the current temperature outside, and the time (in Finnish).

Parts

  • 2  Reed switches (1 for each door)
  • Active buzzer alarm module
  • 16×2 LCD module
  • Raspberry Pi Zero (W)
  • Internet connection, wires, power cord

The Build

Door Alarm

The 2 reed switches were connected between GPIO (BCM) pins 17 and 27 and ground (respectively). In python, this required:

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)

 

After which the state of the doors could be read using

door1 = GPIO.input(17)   # ==1 door is open, !=1 door is closed
door2 = GPIO.input(27)   # ==1 door is open, !=1 door is closed

 

Similarly for the buzzer:

GPIO.setup(21, GPIO.OUT)
GPIO.output(21, GPIO.HIGH)  # my buzzer module was active low
...
if door1 == 1 or door2 == 1:
	time_door_open += 1
	if time_door_open > 200:  
		GPIO.output(21, GPIO.LOW)   # sound the alarm
else:
	GPIO.output(21, GPIO.HIGH)	    # door is closed, silence alarm
	time_door_open = 0

 

Where “time_door_open” is a running counter started when the door was opened.

I used the tutorial from raspberrypi-spy.co.uk to set up my LCD display, since I didn’t have a I2C control board for the LCD. This was a lot of hassle and an ugly mess of wires. I highly recommend buying an LCD display with the control board, it makes connecting the LCD to your project a breeze.

The reed switches need to be set up with care to trigger just right. Here, they’re attached with tape, waiting for a more permanent solution. Too bad quite often the temporal quick fixes tend to become permanent…

Weather Forecast

I used the python library “requests” for fetching the website which had the relevant weather information to my location. New weather data is fetched every 5 minutes.

r = requests.get("http://www.your_weather_site.com/.../")
site_as_string=r.text

 

After that, it’s a matter of simply parsing the relevant numbers from the page using (e.g.) find() and split() string functions. Because this parsing depends highly on the site being parsed and is subject to change every time the site has a layout revamp, the actual code I currently use is not presented here.

 

Afterthoughts

This project has been quite useful to my daily life. Checking the key numbers for the weather forecast can be done with a glance, which is a great help in the mornings. The door alarm has saved me and our food already 5+ times, so that too is a nice feature to have.

Since the gadget was so fun, I also implemented a website which keeps track of the times the door has been opened. This allows me to also check remotely whether someone left the door open. One thing left to do is to get a nicer housing for the Raspberry Pi and the display.

On a side note, building and updating electronic projects on the Raspberry Pi platform feels luxurious compared to Arduino, because the code on the Pi can be updated on the fly over wifi.

You May Also Like

1 Comment

Leave a Reply

Your email address will not be published.

Note: comments are moderated.