Inexpensive Freezer Alarm System using Linux


Diagram of alarm system
This is the setup of our freezer alarm system. Most -80° freezers have a small port on the back for a temperature probe. A thermocouple is placed inside the freezer and attached to a small unit that communicates over an RS-232 serial line. The RS-232 signal goes through our network wiring to a patch panel. A Linux server with a multiport serial card monitors all the freezers simultaneously.

The thermocouple is a Type J iron-constantan bolt-on washer type. We used Omega part number WTJ-6-60. This part number means:
      J = Type J
      6 = 6-32 size hole
      60 = cable length in inches

About 1/3 of these thermocouples will fail when cooled to -80° for the first time. It is necessary to order several extra ones. The cable length should be as short as possible because the signal is quite small.

The converter is a DGH D5311 module, which interfaces a Type J thermocouple with a serial port. Remember that thermocouple cables are not ordinary copper wires, but are made of the same materials as the thermocouple junction. Make sure the leads aren't switched when connecting to the converter or the measured temperature will be wrong.

See incubator-alarm.html for details on the serial-RJ45 adapters needed for connecting the serial line to the network.

Wiring the Thermocouple-to-serial converter

DGH Wiring diagram

Note that lines 2 and 3 are reversed.

Serial to RJ-45 adapters

Serial wiring diagram

This diagram shows the connections for connecting a DE9F to a DE9M or a DB25M connector through a patch panel. The DE-9F on the right connects to the computer's serial port. Colors are not standardized on serial cables. Wiring should be "straight through". However, serial cables are not all wired the same; some have fewer than 9 wires, while in others lines 2 and 3 (RXD and TXD), lines 4 and 6 (DTR and DSR), and lines 7 and 8 are crossed to create a "null modem" cable (see table below). The only way to distinguish different types of serial cables is by measuring them electrically.

RS232 Serial Connections
DE9 DB25 Function
2 3 RXD Receive data
3 2 TXD Transmit data
4 20 DTR
5 7 Signal ground
6 6 DSR
7 4 RTS
8 5 CTS
9 22 Ring indicator
1 8 Carrier det

Null modem cable wiring
DE9F Side 1  1  2  3   4  5  6   7  8  9 
DE9F Side 2  1  3  2   6  5  4   8  7  9 

This is sometimes called a "crossover cable". There are several different types of serial crossover cables, each with a different wiring diagram, and all identical in appearance. It is good practice to test every serial cable and label it before using it.

Important: The computer and freezer should be protected from electrostatic discharge by placing an RS-232 optical isolator or a diode-based surge protector such as a Tripp-Lite DRS232 between them. Otherwise, a surge could destroy the serial port on the computer or the freezer.

Freezer Monitoring Software

Freezer monitoring software is simple, because the computer can query the thermocouples at any time. There is no need to use the select() function. Send the text string $1RD\r\n to query location 0, $2RD\r\n for location 1, etc. (where \r\n is a DOS-style CR/LF). The DGH module responds with a string containing the temperature, such as *+00072.00. One serial port is needed for every four locations. The example software below uses ncurses to display a table of the temperatures, and also creates an HTML file with the same table.

When a location is above an alarm setpoint, the program executes the script file named "alarm-commands". The program remembers its previous state so that this only happens once when the freezer goes into an alarm state. The freezer alarm program is run as a separate user, "freezer", not as root. The serial ports should be owned by the freezer or made read-write:
crw-rw----    1 freezer  
users      4,  64 2005-01-25 
02:07 /dev/ttyS0

freezer.h include file monitoring source code file

Auxiliary files

  1. logcommands does whatever extra processing is needed when data is received. It must be made executable. This example assumes users will check using a browser or using "finger".
    # logcommands - Comman
    ds to be executed by a
    # after each temperatu
    re measurement.
    cp ./temperatures.html
    cp ./temperatures /hom

  2. The locations file gives a descriptive list of what is on each serial port. This example has 8 freezers on 2 serial ports.
    0  0 location 0/0 - Syut Guai
    0  1 location 0/1 - Qi Liang
    0  2 location 0/2 - Bing Kuai
    0  3 location 0/3 - Ambient
    1  4 location 1/0 - NC
    1  5 location 1/1 - Steve
    1  6 location 1/2 - Chuck
    1  7 location 1/3 - Dave

  3. The alarm-commands file is a list like the one shown below. This example shows two freezers, 0 and 6. If no commands are found for a given freezer, the freezer is ignored. The program automatically sends a message to syslog in the event of an alarm, so using "logger" is not needed here. See incubator-alarm.html for details on using the alarm-commands file to dial the telephone.
    # alarm-commands file 
    # Any commands here 
      will be executed 
      when threshold is 
    # Format is:
    #Freezer no.  Threshold  Command
    #freezer 0 0/0  -80 in room 354
    0   -40   /bin/mail jripper@burp < /home/freezer
    0   -20   /bin/mail jripper@burp < /home/freezer
    0     0   /bin/mail jripper@burp < /home/freezer
    #freezer 6 0/1 Forma -80 in room
    6   -40   /bin/mail jripper@burp < /home/freezer
    6   -20   /bin/mail jripper@burp < /home/freezer
    6     0   /bin/mail jripper@burp < /home/freezer

  4. serial.h is also needed to get to compile. If you don't have this, a serial.h appropriate for your system is in the linux kernel source.