I've been blogging about my experience in Road Test reviewing the Ultimate Raspberry Pi Bundle. As a part of this Road Test I'm creating a Fridge/Freezer Temperature Alarm system for our local food shelf, Channel 1. You can see where this Road Test started for me here

In this post I'll bring together all the steps required to build your own Raspberry Pi powered temperature monitor project.

Background info:

Last Christmas vacation, I volunteered for a local food shelf called Channel One. I was chatting with the warehouse manager and he mentioned that their large freezer and cooler rooms are protected by commercial monitoring systems, but he'd really like a temperature monitor for their walk-in display-case cooler and freezer. The food shelf is closed from Friday Noon until Monday at 8am, they've had several cases where the unit has blown a fuse and food has been ruined. My goal was to use the Ultimate Raspberry Pi Bundle to build a low cost temperature monitoring system that can send free text messages when the temperature in the fridge or freezer is outside of the acceptable range.




Project Objective:

  • Monitor the temperature of the Freezer and the Fridge Unit - the valid temperature target is 33F in the fridge unit, and -10F in the freezer unit. However, during business hours, the doors are opened by customers and stocking personnel, so the  the fridge could possibly fluctuate to 60F. So allow for a wider temperature range during Business Hours vs Off Hours.
  • Audible temp range alarm. Make some noise when the temperature is out of range.
  • Snooze Alarm - If the temperature range is out of whack, support a button that stops the noise.
  • Text message - when the temperature is out of range, send a text message to someone who can either fix the problem, or move the food.
  • LCD Temperature display -make the unit wall mountable, we'll mount it outside of the cold of the fridge/freezer unit but the temperature will be visible to staff.




Parts Needed:


Tools Needed:

  • Soldering iron and solder - to solder the sensor to the Pi
  • Wire-stripper
  • Dremmel tool - to cut the project box
  • Xacto knife - project box tweaks
  • Screwdriver


Steps to build this project :


Install Raspbian


  • Using NOOBS is a very convenient way to install the flavor of Linux you prefer on your Raspberry Pi.
  • NOOBS stands for New Out of the Box Software. You can buy a pre-installed NOOBS SD card (what I used for this project) or download your own from http://www.raspberrypi.org/downloads.
  • Connect the HDMI cable, power adapter, USB keyboard and insert your NOOBS SD card (no ethernet is needed for NOOBS).
  • When NOOBS boots up, you'll be presented with the following options to install:
    • Archlinux - a configurable linux distro not recommended for newbies
    • OpenELEC - Open Embedded Linux Entertainment Center (OpenELEC) a small Linux distribution meant to be a media Center
    • Pidora - Pidora is a Fedora Remix optimized for the Raspberry Pi computer
    • RaspBMC - the XBOX Media Center interface
    • Raspbian (Recommended) Raspbian is a free operating system based on Debian optimized for the Raspberry Pi hardware
    • RiscOS - RISC OS is a British operating system designed specifically for the ARM processor
  • Raspbian is recommended and it's what I used for this project.
  • After Raspbian formatting of the SD card finishes, use the configuration screen to:
    • Change from the default password of pi / raspberry
    • Enabled ssh from the advanced options (more about SSH later)
  • Finally run the startx command to bring up the graphical desktop and move on to the next step

Setup the WiPi Wireless Adapter

I followed these instructions to configure the wireless network using commandline instructions.


The basic steps are:

  • sudo nano /etc/network/interfaces
  • fill in the appropriate lines with your router SSID and password
    wpa-ssid "ssid"
    wpa-psk "password"
  • reboot

After the reboot, the Pi will connect to your network and you'll be able to surf the internet from the Pi or just sit back and enjoy the blue glow from the WiPi adapter.

Setup VNC Remote Access

The Raspberry Pi features HDMI out, but if you're like me you are not flush with many HDMI TVs or Monitors. I ordered an HDMI to DVI cable for more options, but to completely free up your HDMI monitors, why not set up VNC so you can access your Pi from a normal laptop or desktop computer? VNC Remote Access (or Tight VNC) is a tool that includes the vncserver process which allows use of graphical applications without connecting any screen to the Pi itself. You simply connect to the vncserver with vncviewer.

Here's how to set-up  VNC

  • Install vncserver by running this command on the Pi:
    sudo apt-get install tightvncserver
  • Start the VNC server by running the command
    (Note, the first time you run it it will ask you to create a vnc password, remember it you’ll need it later)
  • Download vncviewer for your laptop (or desktop) computer
  • Connect from your laptop using the ipaddress:port of the vncserver (and the password you created above)

Now you can use your Pi even when you don't have a monitor or keyboard connected to it. You can either set it up so vncserver so it starts automatically at boot time (as described later), or connect to the Pi using ssh or winscp, log on command-line style and start the vncserver.


Assemble and Setup the LCD


  • Solder together the LCD - Adafruit has a write-up on the 16x2 RGB LCD for Raspberry Pi which explains step by step how to assemble the LCD (note that the layout of the circuit board has changed since the assembly tutorial was created, but the instructions are still very clear)
  • The RGB LCD shield is very easy to use. As a shield it's designed to just plug onto the Raspberry pi and comes with example code showing how to change the screen colors and poll the buttons
  • Note: this was a significant difference between the Adafruit LCD and the PiFace Control and Display. The PiFace Control and Display supports event driven button handling whereas the Adafruit LCD requires polling the buttons, simply looping through checking to see if each button has been pressed.  (I resolved this problem in the temp4sensor.py code by making the Temperature sensing portion of the code into a timebased event handler.
  • Adafruit also includes usage and testing instructions that describe a program called Adafruit_CharLCDPlate.py which allows you to verify the LCD and buttons have been assembled correctly. It polls the buttons and changes the display and color as you press the various buttons. This program provides a good example for handling buttons in python.
  • Note: one thing to watch for when first using this LCD is that it won't powerup until you actually run code to turn it on. Also be sure to follow the instructions on setting the contrast, the display is impossible to read if the contrast is set incorrectly.

Install Python Modules and Files Required by temp4sensor.py

  • To run the Temperature Monitor, you'll need the GPIO library for Raspberry Pi
  1. sudo apt-get install python-rpi.gpio
  • To play audio files for the alarm sound you'll need mpg321, install this by running the command:
    sudo apt-get install mpg123
  • The audio sound played by temp4sensor.py is a public domain sound from sound bible. The script plays Robot Blip 2 three times to get the desired sound. I also liked the Alien Siren sound effect.
    Download at least the Robot Blip sound from here:
    Robot Blip 2 Sound
    Alien Siren
  • The LCD Pi Plate Python code for Pi is available on Github at  https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code
  1. sudo apt-get install git
  2. git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
  3. cd Adafruit-Raspberry-Pi-Python-Code
  4. cd Adafruit_CharLCDPlate
  5. To test the LCD display use the Adafruit_CharLCDPlate.py script which polls the buttons and changes the screen text and color accordingly
  6. Note: this script requires sudo access so you'll need to run the command as follows:
  7. sudo python Adafruit_CharLCDPlate.py

Solder the Temperature Sensor Jacks


This step is optional as you can clearly solder the temperature sensors directly to the LCD. In a previous blog post I mentioned the Adafruit tutorial that describes how to wire up one temperature sensor To use two temperature sensors we simply wire the sensors up in parallel and I've made code changes to support data returned by two sensors.

The temperature sensors have to be soldered as follows
Blue goes to Ground
Red goes to 3V power

Yellow goes to Data port #4

You'll also need the 'pullup' resistor which is supplied with the ds18b20-temperature-sensor. This resistor is required so the temperature sensor reading can be made by the pi

Plug in the Remote Speaker

A feature of the Raspberry Pi is the 3.5mm analog audio out. We'll use this feature to play an audio mp3 file when the temperature is out of the acceptable range. I happened to have a  Boombotix Portable Speaker, so this step was easy, just plug the 3.5mm jack in to the output port of the Raspberry Pi. A future enhancement for this temperature sensor is to install a smaller speaker inside the project box.

Temperature Sensors


One optional step for the Temperature Sensor is to use a Raspberry Pi Cobbler when testing the temperature sensor wiring. The cobbler is shown above and wiring it to the temperature sensor is described in the following Adafruit tutorial Eventually the temperature sensors need to be soldered to the 3.5mm plugs. I used headphone jacks simply because headphone cables have three wires (the same as the temperature sensor cables) and extension cables can be obtained fairly cheaply. Be careful to match the correct wire from the jack to the correct wire from the plug.


Install the temp4sensor.py code and config file

The temp4sensor.py code is meant to drive the temperature sensor. It requires a configuration file called temp4sensor.cfg. Both should be copied to the directory /home/pi/bin/
Download the files temp4sensor.py, temp4sensor.cfg and tempsensorStart from the Attachments portion of this blog post

The configuration file is a simple text file that needs to have the following lines:

#Temperature values in F:

Test the program by running it from the commandline as follows:

  1. sudo python temp4sensor.py


Configure the system so temp4sensor.py starts up at Pi Boot-Up

In order to cause the temp4sensor.py script to start automatically when the Raspberry Pi powers on, we need to configure it as a Linux Init Script

  • Download the file "tempsensorStart" from the attachment on this blogpost  Once configured, this script calls the temp4sensor.py script at startup.
  • copy tempsensorStart to /etc/init.d
  • run the following command to make it executable
    chmod +x /etc/init.d/tempsensorStart
  • test running the script to ensure it won't have problems at reboot time
  • register the command to run at startup by running the command:
    sudo update-rc.d tempsensorStart defaults

Viola! We're Finished

  • Now the temperature monitor is ready to be mounted at the installation site. As mentioned before we want to install the unit outside of the refrigerator unit, but we also don't want to install the device in too warm of a location either. I've read that Raspberry Pi's can tend to overheat, in fact there are heat sinks available and included in the Ultimate Raspberry Pi Bundle. My device is going to be installed in a somewhat cool warehouse so I'm leaving the heat sinks off for now, it will be interesting to see how the unit holds up.

Video of the Channel One Temperature Monitor In Action

The Ultimate Raspberry Pi Bundle has been a great collection of equipment to work with and test out. Now that the Temperature Monitor is finished I'll be demoing this alarm system to the good people at Channel One Food Shelf. Hopefully it can be used to prevent future food loss in their aging fridge and freezer units.


Note: after some additional testing, I made a few changes, the latest version of the code can be accessed here https://gist.github.com/mazzmn/9441036