Steve T's Semi-Cohreant Ramblings

Just another WordPress site

  • About Steve
  • Blog Roll
  • Contact

1-Wire for Temperature Monitoring

Posted by stevet on July 13, 2013
Posted in: Geek Out, Home Improvement.

I have an older house with not so good insulation and windows. It gets too hot in the summer and too cold in the winter. My furnace and AC have to work extra hard to maintain a decent environment.

Before I begin spending a lot of money on upgrades, I wanted to get a baseline of the environment.

1-Wire is a fairly simple system that lets you monitor temperature with various sensors spread around the house. It also has support to monitor humidity, but I am only doing temperature for now.

First thing you need is a One-Wire adapter for your computer. I picked up a USB model that I am hooking up to my linux server. It is model DS9490R that I got from Hobby Boards for about $40 shipped. I picked up 10 waterproof DS18B20 sensors from a Chinese seller on eBay for about $20 shipped.

The DSR9490R has a six pin RJ-11 connector, but the sensors have just three wires. I picked up some four-wire telephone wire and some empty RJ-11 plugs at Home Depot and then it was time to start wiring.

It took me quite a while to figure out the pin-out. There seemed to be a bunch of conflicting info so I did a bunch of test crimps and patch wiring. There are three important wires that matter, voltage, data, and ground. On the sensors voltage is red, data is yellow (on some it is white), and ground is black. For the RJ-11 connector, the layout is voltage on pin 1, the data feed is on pin 3, and the ground feed is on pin 4. If you look at the top of a RJ-11 connector with catch on top and the opening pointing away from you, the pins go from 1 to 6 from left to right.

I could not get the waterproof sensor wires to fit and crimp into the RJ-11 plugs I had, so I took three short lengths of wire stripped from a phone cord to make a tail that is a couple inches long. I then wound and soldered the sensor wires to the tail.

Now I have a sensor that will plug into the USB adapter. Time to test it!

There are two main ways to read data from the sensors. DigiTemp and OWFS. To start and debug I decided to use DigiTemp.

First up, install digitemp. I am on a CentOS box so I used this command:
[code]
stevet@neon:$ sudo yum install -y digitemp
[/code]

Then I plugged in my USB adapter and checked /var/log/messages to make sure it connected. I started a tail and left it running:
[code]
stevet@neon:$ tail -f /var/log/messages
[/code]

Then I plugged in the sensor to the USB adapter. If there is a wiring problem, you may see the USB device get disconnected. If so, check that your wiring is going into the correct pins. If it looks good, time to detect your sensor.
[code]
stevet@neon:$ /usr/bin/digitemp_DS2490 -i
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 – http://www.digitemp.com
Found DS2490 device #1 at 001/016
Turning off all DS2409 Couplers
..
Searching the 1-Wire LAN
287B69C7040000BD : DS18B20 Temperature Sensor
ROM #0 : 287B69C7040000BD
Wrote .digitemprc
stevet@neon:$
[/code]

Look a sensor! Now run a query and make sure the sensor is giving back a temperature:
[code]
stevet@neon:~$ sudo /usr/bin/digitemp_DS2490 -a
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 – http://www.digitemp.com
Found DS2490 device #1 at 001/016
Jul 13 18:03:53 Sensor 0 C: 25.94 F: 78.69
stevet@neon:$
[/code]

It is 25.94 Celsius and 78.69 Fahrenheit at my desk. Nice!

Now it is time to log this data over time. First, we want to copy the DigiTemp config file to a standard location so we can script the data gathering.
[code]
stevet@neon:~$ sudo cp .digitemprc /etc/digitemprc
[/code]

If you look at that config file – you will see the one sensor listed along with the log format. The log format is OK, but it can be better. I commented out the exiting log format and added this one:
[code]
# LOG_FORMAT “%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F”
LOG_FORMAT “%Y/%m/%d %H:%M:%S Sensor %s F: %.2F”
[/code]

Sensor 0 is not a very clear sensor name. This sensor will be in my living room, so I wrote a small script to change the output from DigiTemp to be even more human friendly
[code]
#!/bin/bash

sed -e “s/Sensor 0/Living_Room/” -e “s/#10 : 287B69C7040000BD//”
[/code]

Then I setup a cron job that runs as root. This job runs every minute and takes the output from digitemp, does the rename, and writes it to a log file. It looks like this in my crontab:
[code language=bash]
* * * * * /usr/bin/digitemp_DS2490 -q -a -c /etc/digitemprc | /home/stevet/bin/digitemp_rename | sort >> /var/log/temperatures
[/code]

Now let it run for a few minutes and your temperatures log file should begin to add lines of data. It will looks something like:
[code]
stevet@neon:~$ tail /var/log/temperatures
2013/07/13 18:08:02 12 Living Room F: 79.14
2013/07/13 18:09:02 12 Living Room F: 79.25
2013/07/13 18:10:02 12 Living Room F: 79.36
2013/07/13 18:11:02 12 Living Room F: 79.47
2013/07/13 18:12:02 12 Living Room F: 79.47
stevet@neon:~$
[/code]

You now are gathering specific sensor data and putting it into a log file to be processed later.

In Part 2, I will add a bunch of sensors to the 1-wire system and show how they all are logged. In Part 3, I will detail how I graphed that data so I can visually see the temperature changes.

Posts navigation

← Knock Down Cutting Grid with Sawhorses
1-Wire for Temperature Monitoring – Part 2 →
  • Recent Posts

    • DirecTV 775 Message
    • Configuring BFGMiner on CentOS
    • 1-Wire for Temperature Monitoring – Part 3
    • 1-Wire for Temperature Monitoring – Part 2
    • 1-Wire for Temperature Monitoring
  • Recent Comments

    • stevet on BalanceNG Experts?
    • tgo on BalanceNG Experts?
    • stevet on Stupid NFL Officials
    • RoccoBoxer on Stupid NFL Officials
    • RoccoBoxer on Stupid NFL Officials
  • Archives

    • August 2016
    • November 2013
    • July 2013
    • July 2011
    • June 2011
    • August 2010
    • July 2010
    • May 2010
    • November 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • October 2007
    • September 2007
    • August 2007
    • July 2007
    • June 2007
    • May 2007
    • April 2007
    • March 2007
    • February 2007
    • January 2007
    • December 2006
    • November 2006
    • October 2006
    • September 2006
    • August 2006
    • July 2006
    • June 2006
    • May 2006
    • April 2006
    • March 2006
    • February 2006
    • January 2006
    • December 2005
  • Categories

    • Geek Out
    • Home Improvement
    • Poker
    • Random Rants
    • Sports
    • Uncategorized
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
Proudly powered by WordPress Theme: Parament by Automattic.