Posted on by & filed under hardware, learning.

As a software engineer, I love walking into our server room hearing and seeing the sounds and sights of our machines. Fans whir and LEDs blink while the HVAC unit provides a low bass rumble blowing cold air into the CPU cores. If everything is going right, this room should stay at a constant temperature. However, this is not always the case. Environmental monitoring and alerting is a way to be notified when the temperature is out of the desired range.

Sensor Data

Environmental monitoring in the server room involves getting data from sensors; it should always include a thermometer (temperature sensor) and may include other inputs like humidity sensors. Commercial products for environmental monitoring are usually proprietary and closed source, so your data is locked into someone else’s system instead of having full access to your own data. Many commercial systems are Windows-based and do not easily work in a Linux environment.


In the open source do-it-yourself spirit, I set out to see how we could gather our own environmental monitoring data on an open hardware platform. I looked at community sites to see which open hardware project had the most followers and documentation, as well as practical tutorials. I came across the Arduino Cookbook, 2nd Edition by Michael Margolis. Its Chapter 6 discusses measuring temperature. This was a good place to learn about using a readily-available temperature sensor.

A simple way to get temperature input is via the LM35 sensor. This outputs a voltage based on the degrees Celsius it senses. In an Arduino sketch (code below), I set the Arduino to poll the sensor for temperature every 10 seconds. The Arduino then returned the data to the server via the serial bus connection.

This code is from Arduino Cookbook 2nd Edition by Michael Margolis.
const int inputPin = 0;

void setup()

void loop()
  // LM35 temperature sensor input
  int value = analogRead(inputPin);
  float millivolts = (value / 1024.0) * 5000;
  float celsius = millivolts / 10; // LM35 sensor output is 10mV per degree Celsius
  // convert to fahrenheit
  float fahrenheit = (celsius * 9)/ 5 + 32;

  Serial.print( fahrenheit );
  Serial.println(" degrees Fahrenheit");

  delay(10000); // wait 10 seconds

On an Ubuntu machine, I ran a simple python script (code below) that looked at the same serial bus and grabbed the Arduino output.  The data was then appended to a text file as well as printed to the screen.

import serial
import time
import datetime

ser = serial.Serial('/dev/ttyACM0',9600,timeout=1) // On Ubuntu systems, /dev/ttyACM0 is the default path to the serial device on Arduinos, yours is likely different.
while 1:

    the_goods = ser.readline()

    f = open('/home/spustay/sensor_data.txt','a') // put your path here
    f.write("%Y-%m-%d %H:%M:%S") + ' ' + the_goods)

    print the_goods


I tested this system out on a server rack I keep at my house in a non-climate controlled shed. While this isn’t a real server room (or anything like a real data center), the daily temperature fluctuations we have in Northern California made the data more interesting. This sample data is included on the github page for perusal.


Environmental monitoring with data collection such as this could be extended in many different directions. Because it is open source to the core, code and hardware enhancements could be added or modified, allowing the data to be linked to other projects.


After doing research and getting the right parts, I was able to hook up the sensor and collect data in less than 30 minutes.  Needed supplies include an Arduino board (I used the Arduino Uno), a LM35 temperature sensor, a USB cable, and a computer to capture the data. Environmental monitoring with Arduino is just the beginning of a robust IT infrastructure where you control your data.


I wrote a follow up article explaining how to monitor your data stream.



  1.  » Published Article on Safari Books Online Scott Pustay
  2.  Nagios Plugin for Arduino Environmental Monitoring « Safari Books Online: Publishing & Technology
  3.  » My second article on the techblog was published about Nagios monitoring for the Arduino sensor Scott Pustay