Archive for December, 2010


Sunday, December 12th, 2010

This is my first winter in my new place. I’m finding the living area difficult to keep warm. I wanted to get an idea of how the temperature changes in my living room throughout the day. I decided to build a simple thermometer that would sample and record the temperature.

I purchased an Arduino starter kit from The kit came with an Arduino UNO board, the serial->USB cable, power adapter, and a small breadboard. I also purchased a temperature sensor. I wasn’t sure which board to get, so I went with the starter kit. The board has various features such as a few analog and digital inputs/outputs and an LED.

The initial setup was amazingly simple. I followed the getting started guide, and it all went according to plan. The Arduino appears as a serial device on my Mac. Within minutes, I had a sample script running on the Arduino that would toggle the LED every second.

The temperature sensor is a DFRobot LM35 Linear Temperature Sensor. It has three pins: power, ground, and signal, so it is super simple to connect to the board. However, this sensor has a JST connector for the pins, so it isn’t as easy to connect to the board as a sensor with three bendable legs. I ended up buying a DFRobot analog sensor cable which had a JST connector on one end, and three female headers on the other.

Once the temperature sensor was connected, I wrote a script to read the signal from the sensor and write the temperature. There is a serial console in the Arduino software, so you can see what is being written to the serial port.

void setup() {

void loop() {
Serial.println((analogRead(A0) * 500) >> 10);
delay(1000 * 10);

This snippet reads from the analog pin, does some math on the value, and writes it to the serial port. This is done every 10 seconds. I verified that is was working correctly by looking at the output using the serial console.

Now I wanted to read the data from my computer. I installed the py-serial Python module on my Mac. The interface is simple: blocking and non-blocking calls to read a byte at a time. Sort of a very simple socket-like interface, without nice things like reading a line at a time. My Python script would read ten values, calculate their average, and then send the result to a web service. The web service stored the data points and created nice graphs using the Google Charts API. Using this service, I was able to see how long it took my living room to heat up and cool down.

There are lot of possibilities going forward. It would be cool to build a smart thermostat. One that knows how long it takes to heat my living room, and can be smarter about the schedule; perhaps it can get hints by learning my routine, or by reading my availability from my calendar, or I could give a hint using an Android app by saying “I’m coming home at 9 tonight, I want the place to be 20 by then.”.

The ultimate end goal would be to be able to control various aspects of my home using my phone; the TV, the heating, and the PS3.