How to Build a Raspberry Pi Refrigerator/Freezer Monitor

Rick Kuhlman
Sep 3, 2020 · 10 min read
Image for post
Image for post

Breast Milk — or liquid gold as many moms attest — can be extremely difficult to generate and keep in order to create a consistent supply for your little one.

One afternoon, my wife called me in tears. She noticed that the chest freezer in our pantry suddenly quit working. Months worth of breast milk was ruined. She was understandably depressed. So much so, that I never mentioned that I lost a few important things too — three racks of ribs, a pork butt, and a whole box of mozzarella sticks.

Losing breast milk really sucks, but there are lots of stories about refrigerators and freezers malfunctioning with devastating consequences. In March of 2018, two fertility clinics lost frozen embryos within days of each other — first in Ohio, and then in San Francisco.

This tutorial will tell you exactly how to build a smart freezer thermometer that SMS/Texts and emails if it has a problem. You can make this fully-monitored reliable solution for temperature and humidity in a freezer or refrigerator at a cost of around 30 dollars. The system also monitors the temperature sensor acquisition device in case it malfunctions. With this double-redundancy, you can be confident that if temperatures start to deviate or the device stops working, you will be notified in plenty of time to make arrangements.

Can’t I just throw a wireless SmartThings sensor in the freezer? Unfortunately, No — alkaline batteries and lithium batteries do not work when frozen.

Git Tech’d — Raspberry Pi Freezer Monitor

Refrigerators and Freezers

Did you know? A full freezer runs more efficiently and last longer in a power outage, because there’s less space for warm air to intrude when the door opens. Also, there is more frozen material to keep the space cooler longer.

  • Refrigerator |Operating Temperature: 36°F to 40°F | Spoilage: 4 Hours
  • Freezer | Temperature: -2°F to 0°F | Spoilage: up to 48 hours

note: Spoilage times vary widely if you open the door. Keep it closed if you can help it.

Materials Needed

  • MicroSD card — 16GB is enough for the operating system and code.
  • BME280 — Integrated temperature and humidity sensor. You can find these for very cheap, but you’ll want it already integrated onto a breakout board, and it needs to expose the I2C lines for this tutorial code to work.
  • Hammond Miniature ABS Enclosure — Model: 1551QGY — used to enclose and mount the sensor inside the freezer.
  • Flat Flex Cable — TE Connectivity Part: A9AAT-0808F — This is crucial, we need an extremely flat cable to bridge the seal of the freezer without causing an air leak. In addition, the linked cable already has solder tabs at the proper spacing for standard through-holes on the Pi and the BME280 protoboard.

Hardware Setup

Image for post
Image for post
Wiring diagram for connecting Raspberry Pi Zero W to Adafruit BME280
  1. Modify the cable — The protoboard for the BME280 has 7 solder points, but the cable has 8 connectors. I used a utility knife to carefully strip of one conductor.
  2. Solder to the sensor board — this is where choosing the right flat flex cable comes in handy. The solder tabs already line up with the holes.
  3. Modify enclosure — I needed to Dremel away the lip of the mounting ridge for the cable to friction fit and exit the enclosure.
  4. Mark your signals — before closing the clamshell enclosure, it is a good idea to mark the signals on other end of the cable with a sharpie. We’ll need to locate the two wires for I²C : Clock — SCL and Data — SDA. Also locate your power pins and ground.
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Solder the sensor, modify the enclosure, and close it up.
  1. Cut Flat Flex into “flying leads” — Slice each of the flat flex conductors you need into individual wires so they are flexible enough to go through the proper connection points.
  2. Solder — I soldered the leads right to the board, but there are lots of way to interface between the Raspberry Pi I/O and your flat flex leads.
  3. Install — The flat flex goes between the freezer seal and the edge of the freezer. Sensor on the inside — Pi on the out side. Use double sided Velcro or suction cups so that you can easily take the sensor in and out.
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Connected to the proper I/O and mounted with velcro in the fridge

troubleshooting notes: (1) If you use the BME280 from Adafruit, you should solder in a jumper from CS to VIN to increase I²C reliability. (2) I connected VIN to the 5V pin on the Pi. This is not always the case because some BME280 breakout boards use the 3.3V.

Software: Raspberry Pi Setup

  1. Get Raspbian Lite onto your MicroSD card using and SD card reader for your computer. Once you can access the SD card from a computer, use the imagers available from raspberry Pi to get a fresh image installed.
Image for post
Image for post

2. Enable SSH — After the imager finishes you should see a root directly on the SD card named boot . Simply create an empty file called ssh to enable ssh. Yeah that’s it for that.

3. Setup Wifi — create a simple text file and call it wpa_supplicant.conf. Edit the file with your own wifi credentials like this:


4. Move your SD card from your PC to the socket on your raspberry pi and apply power. You need to wait about 30 seconds or so until your device connects to wifi.

Software: Get an SSH Terminal

  1. A fresh raspberryPi image will have a hostname of raspberrypi . Try searching for that in your router device list.
  2. Open the terminal on your computer and try pinging it. ping raspberrypi.local
  3. If those don’t work take a deeper dive at the IP Address page on

Once you get your IP Address use SSH in the terminal to log in to your device. pi is a default username and the default password is raspberrypi

ssh pi@

Software: I²C Setup

  1. Enable I²C in the OS by opening the configuration menu:
sudo raspi-config
Image for post
Image for post

Select 5 Interfacing Options, P5 I2C, and select <YES> to enable i2c. Select <Finish> to save and exit.

2. Install smbus and i2c-tools

sudo apt-get install -y python-smbus i2c-tools

3. Verify installation using this command. If you see something like the output below, you are good.

lsmod | grep i2c_
Image for post
Image for post

4. This is the moment of truth! Test your connection to the I²C bus of the BME280 sensor. You should see an address at 0x76 or 0x77 like below. Take note of the address, we’ll need it later.

sudo i2cdetect -y 1
Image for post
Image for post

Software: Install Python Libraries

sudo apt install python3-pip

2. Install the BME280 pre-made raspberry pi driver, which gives us quick access to the sensor readings in our code.

sudo pip3 install RPi.bme280

3. Install the Initial State streamer library which creates a simple data stream connection to Initial State for monitoring, alarming, and the dashboard.

sudo pip3 install ISStreamer

Software: Python Code


  • The User Settings area is for you to fill in your desired names and sampling. It is a good idea to use 10 minutes as a preset minimum for this use-case.
  • You will need an access Key from Initial State. Register for a free trial, with no credit card required. The account access key has to be specified on line 10. Copy/paste this key from your Initial State account settings. (more info).
  • You’ll also need to fill in the I²C Address we found after setting up and testing the bus. Edit line 16. Mine was 0x77, yours may be something else. I’ve seen 0x76 on other BME280 sensor setups.
  • WHILE TESTING: Uncomment lines 36–37 and Comment line 40. I added some code in the bottom to test your implementation more efficiently. It reduces the sleep time so you see faster sensor reads and prints them to console.
Image for post
Image for post
With the testing code, you’ll see sensor output, and you should be seeing data on a dashboard in Initial State.
  • FINAL PRODUCT: Comment lines 36–37 and uncomment line 40.

Build a Web Dashboard

Image for post
Image for post
You can check on my actual fridge if you like! Public Link —

Go to your Initial State account (, click on the “❄ Pantry Freezer” bucket name on your bucket shelf, and view the data coming into your dashboard. It’s live now, so go nuts… customize your dashboard by adding and sizing line graphs, gauges, statistics, images etc. (more info). Use expressions to round decimals and convert to degrees Fahrenheit if you like. Make it easy to read

Wanna see a public dashboard of my actual fridge?

Brass Tacks: Alert me when temperature goes wrong

Image for post
Image for post
Image for post
Image for post
Set a trigger in Initial State to watch and alert on you fridge temperature 24/7.

Make it Reliable: Run on Startup and/or Reboot

Adding a process that runs on boot is really easy. At the Pi terminal:

crontab -e

It might ask which text editor you want to use (e.g. nano). Add one line to the bottom of the crontab file save and exit:

@reboot nohup python3 /home/pi/freezer_monitor/ &

You will need to specify the exact path of your script. In the example above, I created a directory called freezer_monitor and the script is called

Now your code will run headless any time your Pi reboots.

Make it Reliable: The Watchdog

Image for post
Image for post
Configure the Bucket Watchdog Data Integration

The bucket watchdog counts incoming data points in the specified time interval. In the image above, I set the watchdog to watch my “Pantry Freezer” Bucket and return the count every 15 minutes. Since the code sends something every 10 minutes, we expect the number in the last 15 minutes to always be > 1. This logic becomes the trigger you make in your dashboard that ultimately sends you a text and/or email.

Note: The reason you set it to 1 and not 0 is because the watchdog itself sends one data point. If the devices stops sending, then that count will go down to one.

Image for post
Image for post
Image for post
Image for post
When data points haven’t been received in 15 minutes, send an SMS and Email Alert.


Ahhh… Although our family is through the breastfeeding phase, I can finally sleep at night knowing my two prime briskets from my last Costco run are safe and sound (and frozen)! My freezer alarm’s got me covered.

Initial State

IoT Dashboards for Real-Time Data

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store