Sunday, November 7, 2010

Handling the output

I built a Windows service to run on my Home Server. This reads the data received by the XBee and logs it in SQL Server. So far it's just a web page but the next step is to make a device for the kitchen that shows the information.


Saturday, November 6, 2010

Garage Status Monitor details

For my garage status monitor, I wanted two functions:
  • Tell whether the door was open or closed
  • Ambient temperature reading
The temperature part was easy. It's just a standard TMP36 temperature sensor that is hooked up to the Arduino analog pin 0. The sensor returns an integer millivolt reading that can be converted a temperature reading in one line of code.

I had several options for detecting the state of the garage door, but I settled on cheap and easy by using a roller contact switch. It is mounted on a wood shelf just ahead of where the top edge of the door comes to rest when it is open. When the circuit is closed, the Arduino knows the garage door is open.

Getting the signal upstairs could also be done a bunch of different ways. I had been fiddling with XBee radios for a while so I thought I'd use a set for this. The Arduino has an Xbee shield mounted, which uses up the ICSP headers and the first eight digital I/O pins.

The receiver XBee radio is hooked to my PC via an XBee Explorer USB adapter. It shows up as COM7, and I have both XBees setup to work at 9600 bps.

When the garage door is closed, it transmits a plain English sentence like this for the moment:

GARAGE DOOR IS CLOSED. TEMP IS 59.77.

I say "for the moment" because my ultimate goal is to make a receiver device to hang in the kitchen that just displays a red or green light, and maybe the temperature on a pair of 7-segment LEDs. The only thing I have in place so far to represent the output is a PuTTY window running on my machine.
Here's the code for the Arduino:


const int switchPin = 10; // The pin used for the switch.
const int ledPin = 13; // The pin used for the LED to display status locally.
const int tempPin = 0; // analog pin for the temperature sensor.

int buttonState = 0; // variable for reading the switch status

void setup() {
// Get the LED pin setup as an output.
// Using the on-board LED for this.
pinMode(ledPin, OUTPUT);

// Get the switch pin setup as an input.
pinMode(switchPin, INPUT);

// Get serial communications ready to rock.
Serial.begin(9600);
}

void loop(){
// Get the state of the switch.
buttonState = digitalRead(switchPin);

// Is the circuit closed?
// If so, the garage door is open, so...
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.print("GARAGE DOOR IS OPEN. ");
}
else
{
digitalWrite(ledPin, LOW);
Serial.print("GARAGE DOOR IS CLOSED. ");
}

Serial.print("TEMP IS ");
Serial.print(getTemp());
Serial.println(".");

// Pause for five seconds.
delay(5000);
}

float getTemp()
{
// Read the temperature from the sensor.
int tempReading = analogRead(tempPin);

float voltage = tempReading * 5.0 / 1024.0;

// Convert the voltage to temperature.
float tempC = (voltage - 0.5) * 100;
float tempF = tempC * 1.8 + 32;

// I like Fahrenheit, so return it.
return tempF;
}

Pictures of the setup:







My first real gadget: Garage status monitor

After building about a hundred blinking/beeping/servoing/sensoring Arduino devices that did nothing useful, I finally decided to build something that we would really enjoy. And that was the hardest part - figuring out what I really needed done and then giving the task to the Arduino. I probably spent a month just pondering.

In the middle of July, I was wondering why the air conditioner in the house wasn't keeping up. I must have spent hours looking things over, making sure the compressor was working, replacing filters, blah blah blah. After a while, I found myself standing downstairs in the middle of my garage and it hit me.

The garage door had been open all day. This was the reason why the ductwork was sweating and the cement floor looked damp, and probably a big contributor to the air conditioning problem. From the main floor of the house, it's impossible to tell if the garage door is open, and with a 5-year-old always going out to ride her bike, you can bet it's open more often than not.

And that's when I decided it was time to find a way to build a gadget to let me know. And like all good books (yeah right, like this is a good book), this set of posts is written after I've actually built it, so I'm going to go back through and document it for you in future posts.

Weapon of Choice

As I said, I'm your basic garden variety computer nerd. I spend my day writing C# code for a mid-sized company and my nights alternating between chasing my kids, Xbox 360 and tinkering. As previously stated, this blog is about the latter.

For the past few years, I've been fooling around with the Arduino microcontroller platform. It's a great open source gadget that can take readings from sensors, engage servos, and communicate with a whole host of other devices. It's the perfect bridge for the digital and the physical worlds.

This blog will spend a great deal of time on this little gadget and the myriad ways I find to make it work.


An Introduction

This blog is titled "Stinkering" because "Tinkering" was already taken. Also, I'm brand new at the sort of shenanigans that I'm proposing to write about, so it could be said I "stink" at it. Clever, eh?

Anyway, this blog is going to be about my adventures in learning electronics. I've been a computer nerd since I was in single digits but I never really learned how to make the computer interact with real physical items.

And so my journey begins. Hope you're not bored along the way. And if you see something here that you could have done a lot better, I'd love to hear about it.