< async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"">

Saturday, December 21, 2013

Build a low cost remote temperature monitoring system for home or server room temperature monitoring

ADVERTISEMENT
Often we need a simple way to log and look at the temperature at the basement or the room while staying away from the property. This may often help to save a couple of water pipes getting frozen or server room getting heated up. Here i will show a simple way to start with a wired solution and later it can be upgraded to a wireless solution. It is easy to buy one system and install it. But it is fun to build one :)

We need a couple of things to start. An LM35 temperature sensor and a micro-controller with an ethernet  module. Here am going to use an ATMEGA328 (arduino uno prototyping board) with an Ethernet shield. (There are more options out there if you have a raspberry pi, so that the need for ethernet shield can be replaced with a wireless link to raspberry pi)

Connecting the hardware is easy and can be figured out from the pictures below. Sensor has 3 pins and connect them to ground, vcc (5 volt) and the output to the analogue input pins of the micro controller.

                                                                         

And here is the PIN connections for LM38

 

Now the interesting part is the firmware for the device to upload the temperature to a web-service. To make things easy for the beginners, am going to use a cloud based serial data logging service. Exosite.com offers a simple and easy to set up solution with beautiful charting. You can see my temperature logger in action at this link. Firmware for connecting to exosite can be seen here.

Modified source for LM35 is given below. dont forget to connect the Ethernet shield and the cable. After the source, an updated version of my logger which uses raspberry pi and tempo-db together with highchart ( a nice charting tool) is used to log and plot the temperature data from a set of sensors

Complet source can be downloaded as a zip file from here

/*
It uses parts of code from exocite and their libraries. 
Create an account there and use that api key for CIK
Set the mac adress for ethernet shield
Replace writeParam = "number="; with the data name of your device in exocite

This is modified to use LM38 temperature sensor and uses ANALOGUE PIN 5 on arduino uno

The original file can be seen at https://raw.github.com/exosite-garage/arduino_exosite_library/master/examples/TemperatureMonitor/TemperatureMonitor.ino

Credit goes to exocite and please see the above link

For more details on setting up and instructions see 

http://blog.riyas.org/2013/12/build-low-cost-remote-temperature.html

*/
  
  
#include <SPI.h>
#include <Ethernet.h>
#include <Exosite.h>
 

 
/*==============================================================================
* Configuration Variables
*
* Change these variables to your own settings.
*=============================================================================*/
String cikData = "0000000000000000000000000000000080000000";  // <-- FILL IN YOUR CIK HERE! (https://portals.exosite.com -> Add Device)
byte macData[] = {0xDE, 0xAD, 0xBE, 0xEE, 0xEE, 0xFF};        // <-- FILL IN YOUR Ethernet shield's MAC address here.

// User defined variables for Exosite reporting period and averaging samples
#define REPORT_TIMEOUT 30000 //milliseconds period for reporting to Exosite.com
#define SENSOR_READ_TIMEOUT 5000 //milliseconds period for reading sensors in loop
#define LM35Pin 14

/*==============================================================================
* End of Configuration Variables
*=============================================================================*/

class EthernetClient client;
Exosite exosite(cikData, &client);

//
// The 'setup()' function is the first function that runs on the Arduino.
// It runs completely and when complete jumps to 'loop()' 
//
void setup() {
  Serial.begin(9600);
  analogReference(INTERNAL);
  Serial.println("Boot");
  Serial.println("Starting Exosite Temp Monitor");
  Ethernet.begin(macData);
  // wait 3 seconds for connection
  delay(3000); 
 
}
 
//
// The 'loop()' function is the 'main' function for Arduino 
// and is essentially a constant while loop. 
//
void loop() {
  static unsigned long sendPrevTime = 0;
  static unsigned long sensorPrevTime = 0; 
  static float tempC;
  char buffer[7];
  String readParam = "";
  String writeParam = "";
  String returnString = "";  
   
  Serial.print("."); // print to show running
 
 // Read sensor every defined timeout period
  if (millis() - sensorPrevTime > SENSOR_READ_TIMEOUT) {
    Serial.println();
    Serial.println("Requesting temperature...");
    tempC =  analogRead(LM35Pin) / 9.31;
    Serial.print("Celsius:    ");
    Serial.print(tempC);
    Serial.println(" C ..........DONE");   
    sensorPrevTime = millis();
  }
 
  // Send to Exosite every defined timeout period
  if (millis() - sendPrevTime > REPORT_TIMEOUT) {
    Serial.println(); //start fresh debug line
    Serial.println("Sending data to Exosite...");
    
    readParam = "";        //nothing to read back at this time e.g. 'control&status' if you wanted to read those data sources
    writeParam = "number="; //parameters to write e.g. 'temp=65.54' or 'temp=65.54&status=on'
    
    String tempValue = dtostrf(tempC, 1, 2, buffer); // convert float to String, minimum size = 1, decimal places = 2
    
    writeParam += tempValue;    //add converted temperature String value
    
    //writeParam += "&message=hello"; //add another piece of data to send

    if ( exosite.writeRead(writeParam, readParam, returnString)) {
      Serial.println("Exosite OK");
      if (returnString != "") {
        Serial.println("Response:");
        Serial.println(returnString);
      }
    }
    else {
      Serial.println("Exosite Error");
    }
 
    sendPrevTime = millis(); //reset report period timer
    Serial.println("done sending.");
  }
  delay(1000); //slow down loop
}
Here is some example for setting up exocite

17 comments:

  1. help me.
    how to setting in web portal exosite?

    ReplyDelete
  2. In exocite, you need to click (after login) Manage devices -> Add device
    and add a generic device and follow the instruction. After this step you get your api key or CIK which is used in your scripts. Once a device is added , you can add data to that and this is done by clicking on the devices and Adddata (in the above example 'temp')

    Once you have done this , you can use the add widget button and play around with the options there to make different types of plots


    ReplyDelete
  3. I run the above code there are some errors.
    please fix it because I am interested in using this technology.
    please send file.pde to [email protected]
    thank you

    ReplyDelete
    Replies
    1. I have updated the code above. You can also download it as a zip file at https://github.com/riyas-org/exocite_LM38/archive/master.zip
      My sensor is up and running (see the chart above and at http://goo.gl/HgsE0g (current test with the code shows a negative test spike :) )

      Good luck with setting it up and running!

      Delete
  4. I am still confused about the configuration in exosite
    1. device
    2. add devices
    3.generic device
    4.device time: jakarta
    5.device location: Bali Indonesia
    6. alias?? i do not know
    7. ID?? i do not know
    8. add the data
    9.Data Source Name???
    10. Data Source Format:?????
    11. Alias​​????

    Replace writeParam = "number ="; the data with the name of your device in exocite????

    thanks for helping to task campus

    ReplyDelete
    Replies
    1. Attached some images above from exocite.

      Data Source Name= number
      Data Source Format=float
      rest can be kept blank (Alias etc)

      Delete
  5. thank you for your help
    now I've been able to connect to the exosite.
    but there is still a problem that I have experienced
    when the microcontroller is connected to the exosite, gauge widget shows temperature data,
    but when the microcontroller is not connected
    gauge widget still displays the temperature data
    such as microcontrollers stay connected

    thank you

    ReplyDelete
    Replies
    1. I haven't noticed this. So when the device is disconnected, you want the gauge to be zero? Usually they have a last reported time on the bottom. There are some other options like using a script option. But i dont know how to work with lua scripts to achieve something similar. You can try contacting the customer service of exocite and they are very helpful.

      Delete
  6. how to set the gauge widget to operate when the microcontroller is turned on and vice versa if the microcontroller is not connected gauge widget off position.

    ReplyDelete
    Replies
    1. As i answered above i have no idea on turning the widget off. One possibility is to use some sort of script which will check the widget every 10 minute and append a zero if no data appears in last 20 minutes.

      Delete
  7. hallo
    I want to ask.
    how to send two data to exosite.
    for example i want to use two sensors on the arduino.
    thanks you

    ReplyDelete
  8. Locate these line in the code and:


    writeParam += tempValue; //add converted temperature String value

    after this uncomment the line (remove those // lines before the line


    writeParam += "&message=hello"; //add another piece of data to send


    This will add a new parameter called message and with value hellow

    ReplyDelete
  9. hallo
    apakah data suhu bisa dikirim ke sosial media twitter?

    ReplyDelete
  10. yes, it is possible to tweet it and will be posting when i get time ( a bit lengthy process)

    ReplyDelete
  11. I do not understand the meaning of this syntax. help me.

    if ( exosite.writeRead(writeParam, readParam, returnString))

    String tempValue = dtostrf(tempC, 1, 2, buffer);

    ReplyDelete
    Replies
    1. dtostrf format the tempc to a number with only two decimals after the '.'

      Delete
  12. dtostrf convert tempC to a string with 2 decimal precision and stores it in buffer.

    ReplyDelete