FRIDGE MONITORING PROJECT

Many people leave for holidays with freezers full of perishables at home or you might have a business where freezers, fridges or coolers are used and need to stay below a certain temperature. This blog describes a possible way to monitor fridge temperatures and send notifications on abnormal conditions. 

Hardware

There are various hardware setups that can be used. For this post I used what I had available in my DIY kit. For your implementation you can use a fairly simpler setup and I will suggest a few and the end of this article. The setup consists of the following:

The setup has been made quickly and after a few iterations the code was setup to read the temperature and display it on the LCD connected tot he Arduino. The Arduino complete code is below:

#include "liquidcrystal_i2c.h"
#include "onewire.h"
#include "dallastemperature.h"

LiquidCrystal_I2C lcd(0x27,16,2);

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
 
unsigned long currentTime;
unsigned long cloopTime;

union {
  float fVal;
  byte bVal[4];  
}float32Bytes;

byte serBuffer[4];
byte serBuffer2[4];
float tempNormalize;

void setup()
{
   pinMode(anlogOut,OUTPUT);
   
   lcd.init();
   lcd.backlight();
   lcd.setCursor(0,0);
    
   Serial.begin(9600);

   currentTime = millis();
   cloopTime = currentTime;

   //Start up library
   sensors.begin();
}
void loop ()
{
    
    // call sensors.requestTemperatures() to issue a global temperature   
    // request to all devices on the bus  
    sensors.requestTemperatures(); // Send the command to get temperatures  
    
    float tempC = sensors.getTempCByIndex(0);
 
   currentTime = millis();
   if(currentTime >= (cloopTime + 5000))
   {
      cloopTime = currentTime; // Updates cloopTime     
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Temp:  ");
      lcd.print(tempC); // Print litres/hour
      lcd.print(" deg");

      float32Bytes.fVal=tempC;
      
      Serial.write("s");
      Serial.write(float32Bytes.bVal[0]);
      Serial.write(float32Bytes.bVal[1]);
      Serial.write(float32Bytes.bVal[2]);
      Serial.write(float32Bytes.bVal[3]);
      Serial.write(-1);
      delay(100);
      Serial.flush();
      
   }
}

 

The Particle Xenon board is connected to the Arduino through the bidirectional level shift module and the temperature is sent serially to the Xenon board. From the Xenon board the temperature is published to the particle cloud. The temperature is published every two minutes or if a change of more than 0.5 degrees occur in the positive or negative direction. The code can be seen below:

/*
 * Project FreezerMonitor
 * Description:
 * Author:
 * Date:
 */
char* buffer;
float temp;
float prevReportedValue=999.0;
unsigned long oldTime=0;
byte serBuffer[4];
// setup() runs once, when the device is first turned on.
void setup() {
  Serial.begin();
  Serial1.begin(9600);
  // Put initialization like pinMode and begin functions here.

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.
  //Serial.println("Attempting Serial Read");
  bool serialSucces=false;
   if (Serial1.available()>0)
      {
        char cStart=(char)Serial1.read();
        //Serial.print("Start = ");
        //Serial.println(cStart);       
        if (cStart=='s')
        {
          int iCnt=0;
          byte next = Serial1.read();
          while ((Serial1.available()>0)&&(iCnt<4)&&(char)next!=-1)
          {     
            //Serial.print("Available =");
            //Serial.println(Serial1.available());                  
            serBuffer[iCnt]=next;            
            next = Serial1.read();
            iCnt++;
          }   
          serialSucces=true;         
        }
        else
        {
          Serial1.flush();
        }
      }
      Serial1.flush();

      float tempf;
      memcpy(&tempf, &serBuffer, sizeof(tempf));
      if (serialSucces)
      {
        if (prevReportedValue==999.0)
        {          
          prevReportedValue=tempf;
        }
        else
        {
          if (((tempf-prevReportedValue)>0.5) || ((tempf-prevReportedValue)<-0.5))
          {
            prevReportedValue=tempf;
            Particle.publish("Freeser Temperature",(String)tempf,PUBLIC);
          }
          else
          {
            //prevReportedValue=tempf;
            if ((oldTime+120000)<millis())
            {
              oldTime=millis();
              Particle.publish("Freeser Temperature",(String)tempf,PUBLIC);
            }
          }
        }          
      }
      
      //Serial.println(tempf);
      delay(100);
}

 

The setup has not been very elegant as can be seen below:

To make sure the temperature reads correctly, the probe was compared against my multimeter temperature probe and from below it can be seen that the temperatures compares quite well.

From the particle cloud the information is sent to my Losant account. I have setup a time series graph and instantaneous value as seen below:

Various notification options have been looked at, the two that was decided on was Twilio and Pushover. Twilio is an SMS service that can be used to send SMS notifications and pushover has Android, IOS and Desktop apps which sends push notifications to your device. Both provides free trials, but do require payment afterwards. Twilio has a pay as you go option that costs U$0.04 (N$0.8) per SMS and Pushover costs U$ 4.99 (N$99.80) per device for lifetime use. 

Both platforms have a fairly simple API that can be implemented on either the device side or platform side. 

My Losant Workflow for integrating the temperature and sending notifications has been lain out as shown below:

 

 The workflow tests both Twilio for which there is a custom node, with a great help file for implementation. For Pushover, a normal http request block is used. The http request block should be filled in as below:

Losant HTTP Request Node setup for Pushover

Important is to make sure that an SMS or notification is only sent once. For this I used Storage Get and Set nodes. What needs to be done is to indicate that when alarm condition has occurred an SMS/notification can be sent and the next notification can only be sent after the condition has cleared. I have setup an alarm SMS/notification as well as a recovery SMS/notification for Twilio:

As well as for Pushover:

As we are working form a platform we would also like to setup a device disconnect and reconnect notification. That will indicate when my device has disconnected from the cloud and when it has again reconnected. For the disconnect I used an inactivity node and for the reconnect I used the Particle trigger node. Again I used Storage Get and Set nodes to make sure that the notifications only gets sent once. 

Twilio device disconnect SMS notification 

Pushover device disconnect notification

If you don't want to sent notifications only once but periodically you can also use the throttle node. 

Finally I would suggest using the ESP01 or Particle Photon for your controller board if you would like to implement this project. 

Till next time happy building. 

 

Leave a comment