Home » guide » Monitoring Refrigerator with TI SensorTag

Monitoring Refrigerator with TI SensorTag

I’ve been doubting my refrigerator for some time now as my vegetable tend to spoil earlier than expected. Hence, for a start, I would like to monitor the interior temperature and humidity and understand how it changes every time the door is opened.

I’ve been placing ESP8266 based sensor nodes all around the house, which allows me to track temperature, humidity, brightness and motion. However, deploying the same hardware in the refrigerator is not feasible as the existing sensor node is:

  1. Powered with micro USB. It’s not so pleasant to run wires around my food.
  2. Not designed for extreme temperature (possibly below -10°C).

SensorTag as remote sensor node

So… a while ago, I came across the TI SensorTag CC2650 which you can get it at $29. It boast 10 different on-board sensors, the notable ones:

  • 9-axis motion
  • Magnetic (reed)
  • Humidity, ambient temperature
  • Ambient light

All these comes packed in a nice form factor powered with C2032 coin cell. TI claimed that at 1Hz publishing rate, a single coin cell should last 1 year. I have yet to put this claim to test. There is also a solder point for using an external battery, which I intend to use in the future. Unfortunately, there’s no battery dev pack being sold although the picture on TI’s website implied otherwise – so it’ll be harder work.

Connectivity wise, it supports BLE (GATT server) out-of-the-box. If you want to work with ZigBee or 6LoWPAN, you’ll want to buy the Debug DevPack which allows for advance configuration and firmware flashing.

I read somewhere that its operation is tested/rated up to -20°C but cannot find this in the official documentation now. The coin cell I’m using is from Maxell which is also rated from -20°C, so I can safely say it’s not a problem to place them in the refrigerator.

In this setup, I’m using the Raspberry Pi 3 which has BLE support. It reads the data from the SensorTag and then post it to an MQTT broker, which is then stored into ElasticSearch cluster so that we can visualize the data with Kibana.

Humidity and temperature reading is taken. We will place a magnet to the refrigerator door so that the magnetic sensor will know whether it’s open or close.

The focus of this post is to read the data from SensorTag using NodeJS and posting to MQTT broker. We will not look into the “box” item. Setting up MQTT Broker, ElasticSearch and Kibana is a post for another day.

Setting up the Raspberry Pi

This guide has been tested on Raspberry Pi 3 running Raspian Jessie.

Install the necessary BLE related libraries.

sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
Update apt-get source list and install latest nodejs (npm will be installed automatically). Older version of nodejs doesn’t work well.
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install nodejs
We will be using the NodeJS SensorTag library.
sudo npm install -g node-gyp
npm install sensortag
 Now, create a new file called sensortag.js with the following content.
var SensorTag = require('sensortag');
var mqtt = require('mqtt').connect(process.env.BROKERURL || 'mqtt://'); //change the broker URL
var topic = 'cc2650/fridge';

console.log("starting script");

var data = {
    temperature:     0,
    humidity:        0,
    reed:            false,

function fix(num, dec) {
    var s = num.toFixed(dec);
    return parseFloat(s);

SensorTag.discover(function(tag) {
    tag.on('disconnect', function() {
        console.log('attempting reconnect...');

    function publishData() {
        var payload = JSON.stringify(data);
        mqtt.publish(topic, payload);

    function setup() {
        data._id = tag.id;
        data._tagtype = tag.type;

    function enableSensors() {

        tag.notifySimpleKey(function() {
            tag.on('simpleKeyChange', function(left, right, reed) {
                data['reed'] = reed;

        tag.setHumidityPeriod(3000, function(error){});
        tag.notifyHumidity(function() {
            tag.on('humidityChange', function(temperature, humidity) {
                console.log("tem: " + temperature + "   hum: " + humidity);
                data['temperature'] = fix(temperature, 2);
                data['humidity'] = fix(humidity, 2);

The javascript code, in sequence:
  1. Discovers the SensorTag within proximity (only 1 at a time) and connect.
  2. Enables the Humidity (ambient temperature is together) sensor.
  3. Sets the periodic Humidity reading interval to 3s.

In practice, the maximum period supported out-of-the-box is 2.55s. So even if we set the period to 20000ms, it’s still 2.55s. We’ll need to modify the firmware if we really need such feature.

Now, try running the code.
sudo node sensortag.js
You should see the following output:
pi@raspberrypi:~/sensortag $ sudo node sensortag.js
 starting script
 tem: 4.9359130859375 hum: 5.21240234375
 tem: 4.9359130859375 hum: 5.21240234375
The message, which is JSON formatted is published on MQTT topic “cc2650/fridge”. Check this post if you are not familiar with MQTT.

Positioning the SensorTag

Once the RaspberryPi is done, it’s time to place the SensorTag into the refrigerator. I am using 3M acrylic tape. Wipe the surface area so that it is clean and dry, otherwise it will not stick well. Tape the SensorTag to the side wall, and the magnet to the door, such that when the door is close, the magnet will be aligned to the SensorTag’s magnet sensor (it’s right below the power button).


On my Kibana dashboard, I’m able to see a graph of temperature and humidity overtime.

As seen from the graph, every time the door opens, the humidity which is normally <20%H increased immediately to ~60%H while temperature increase by few °C. Temperature fluctuates between 4-6°C throughout the day.

2 Responsesso far.

  1. Pratik Naik says:

    Hello Calvin,
    This is a really fantastic use-case for using the TI SensorTag CC2650. I am looking at using SensorTag to determine the temperature inside a cooler container, and using a mobile app to detect or read the values over BLE connection.

    I have certain questions or concerns that I believe you may have come across or given a thought to, and I would highly appreciate if you could provide your views on it.
    I am curious to know about the signal strength of the sensor, how far was the Raspberry Pi placed from the sensor tag, did you record the ambient temperature or IR temperature, what impact does the door opening has on both the temperature scales, does the placement of the sensor tag impact the communication between the tag and Raspberry Pi, did you consider other locations, how has been the performance over time, etc.

    I am eagerly awaiting your response.
    Thank you.

    • calvin says:

      Hello Pratik,

      Unfortunately, after a couple of weeks it did not work so well, the sensor tag started to fail due to the extreme temperature, seems to recovers once place in room temperature but fails again when place in refrigerator. I haven’t have the time to investigate the root cause.

      What I do now is use the ESP8266 + DHT22 + single 18650 battery, which is connected to my home WiFi and publishing data to my MQTT broker every few minutes. The battery last for about 6 weeks at a time. This have been working well, both in the fridge and in the freezer (~-20c).

      I’ll answer your question based on my existing setup. DHT22 only measures ambience temperature. I don’t know how accurate it is as I haven’t compare with anything else. Opening the door (even for a couple of seconds) will see an almost immediate rise of at least few degrees (and it takes many minutes to recover).

      If you need BLE solution, you may consider to look into the ESP32. It’s the successor of the ESP8266.


Leave a Reply

Your email address will not be published. Required fields are marked *