twitter
Search
Wednesday
Feb012012

Arduino server room thermometer (Blinky)

This is the first generation of the project with only visual alerts. The second generation was Ethernet enabled.

At my last job, I rarely had to set foot in my server room. The air conditioning unit, however, sometimes falls behind in the summer. I wanted something that would grab the attention of people walking by if it were to go over 80F ambient temperature. Except for a little wiring, the parts list is 100% Adafruit stock:

 


That's $31.75 if you have an UNO handy, $30 more if you don't. 

To build the LCD shield: http://forums.adafruit.com/viewtopic.php?f=31&p=112887#p112887

A long section of ribbon cable (I used 7 wires - more than I need) to go around the door and a little wire, time, and solder to assemble the bits together are all that is left. I have the proto shield's LEDs on pins 12 and 13, the LCD shield exactly how I described it built in a previous thread, and the temperature sensor on (analog 0) pin 14. I have analog 1 and 2 going to the back breadboard too just in case I want to use them.

On the ribbon cable, I am using VIN to power the display. This way the power supply can sit inside the server room and won't be hanging off the wall in the "public area." The barrel jack was perfect for that. 

Make sure to get the required libraries for the temperature sensor and LCD from the product links above or it'll never compile. The code is ugly and poorly commented, but it does the job. I even got lazy and read the temperature through two different functions (one as a string, one as an int) because I hate converting back and forth. 

Code:

// Arduino "FREAK OUT OVER 80F" thermometer

#include <PCD8544.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "String.h"
#include "WProgram.h"



// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 14

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// arrays to hold device address
DeviceAddress insideThermometer;
PCD8544 nokia = PCD8544(7, 6, 5, 4, 3);
char msg[125];
int flash = 0;
int currTemp;

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");
  // locate devices on the bus
  Serial.print("Locating devices...");
  sensors.begin();
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");
  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();
  // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
  sensors.setResolution(insideThermometer, 9);
  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();
  nokia.init();
  nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYALLON);
  delay(500);
  // back to normal
  nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
  pinMode(13, OUTPUT); // Green  LED
  pinMode(12, OUTPUT); // Red LED 
  digitalWrite(12, HIGH);
}


void loop(void)

  nokia.clear();
  sensors.requestTemperatures(); // Send the command to get temperatures
  String msgHead = "The current   server room   temp is ";
  String termMessage = msgHead + fetchTemp(insideThermometer) + "F " + "\0";
  Serial.println(termMessage);
  int msglen = (termMessage.length()+1); // count the characters, add 3 just in case
  Serial.print(msglen);
  Serial.println(" - message length");
  termMessage.toCharArray(msg,msglen); // Convert it to an array called msg
  Serial.print("Attempted message ");
  Serial.println(msg); 
  nokia.drawstring(0, 0, msg);
  nokia.display();
  if (numTemp(insideThermometer) > 80){
    for (int flash = 1; flash < 10; flash++){
    digitalWrite(13, HIGH);
    digitalWrite(12, LOW);
    delay(60);
    digitalWrite(12, HIGH);
    digitalWrite(13, LOW);
    delay(60);
    }
  }
  else {
  delay(600);
  }
  nokia.clear();

}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

String fetchTemp(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  int tempF = DallasTemperature::toFahrenheit(tempC);
  String reportTemp = tempF;
  String reportText = reportTemp + "F";
  return reportTemp;
}

int numTemp(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  int tempF = DallasTemperature::toFahrenheit(tempC);
  return tempF;
}

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.
« Ethernet enabled server room thermometer | Main | DFRobotShop Rover example code »