1-Wire Temperature Monitor

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

Vinic

Well-Known Member
Joined
Nov 9, 2009
Messages
81
Reaction score
6
Location
Missouri
The title is a bit over simplified, as this project has the ability to do much more than just monitor temperatures, but at this point, monitoring and recording is all it does. I have seen other similar systems discussed on HBT, but this has to be a candidate for the least expensive.

I should start with an explanation of the hardware; 1-Wire. Dallas/Maxim came up with some devices that utilize an electronically embedded identification system that allows multiple devices to be wired onto one circuit. It does require a circuit (one wire to the sensor(s) plus a return wire), and thus actually two wires, so their name is a bit of misnomer. It would be more appropriately named '1-circuit', but I suppose everyone is allowed a bit of marketing leeway. Software is used to sort out the individual devices, in this case temperature sensors, by their id number. The main advantage to this is the ease of interfacing with a pc, but it also cuts down a bit on the hard wiring. Plus, the huge draw for me was the economy of the system. At about $4 per sensor plus a $28 interface being the only other required piece of hardware, experimentation was well within my budget.

Of course, a pc is required; I had a few 500 to 800 mgHz laptops available to me, and they're not really good for much else. They are about as slow as I'd consider for this setup.

"So, what's the catch?", you might ask. The installation of the software is a bit, how can I put it, "involved". Mainly because of setting up the pc as a server, which is only needed to display the graphs. But it's all open source software, and can be done within a night or two of dedicated work. Hopefully I can outline it clear enough here that if anyone wants to try it, you'll have a good starting point. Part of my motivation for posting this is the hopes of having another geek or two, help to code some more features into the system. I've been working in my 'spare time' on setting this up for monitoring a mash and brew for a week or so no, and expect to have some nice user interface going by the end of the year. But what I have so far works, and seems to work well within +/- 1 deg F during the first test.

My first setup was built to monitor and chart the temperatures of the cold stabilization of my commercial wine cellar. That system also reacts to the temperatures sensed, so that if the outside air temperature is below the tank temperature, a ventilation fan will turn on to draw the colder air in. You might already see how the possibilities are virtually endless. That system also uploads the charts to our website every 10 minutes and displays the current state of the fan. (NOTE: the fan has a physical power override switch that is off now, otherwise the cellar temperature would follow closer to the outside temp when the fan is on).

The graph for brewing beer is a bit different, of course. The temperature range is from 0F to 220 and the time frame I set to 4 hours. The user interface is being setup to allow variable time frames for multi levels of deconcoction. Here's a screen shot of the chart created while checking the accuracy of the sensor:

http://vinic.com/files/wmChart.PNG

This was just a few quarts of water, but was compared with three other thermometers (two mercury and a digital).

So. If you're still interested after all that, here's the list of software needed (this list is geared towards a winXP install, but is also doable on Linux with the appropriate adjustments. I'll assume that Linuxer's will know what to do):

1-wire
cygwin (cygwin)
digitemp (digi)
perl (Perl)
xampp (xampp)
jpgraph (jp)

Within the brackets is what I used for folder names.

A couple other handy tools:

7zip (to unzip gztar)
Real VNC (to access remotely from other pc’s)

When installing Xampp, allow it to place a desktop icon (you can always move it later). Then use this to start the control panel. Then start Apache and MySQL (we'll make this easier to do later, another day).
Once Xampp is installed and the server/db are running, a little setup is required. Open a browser and point it to:


If it worked, you'll have a splash page with selection of languages. Once you choose your language of choice, you won't see that splash page again if you go back. You should now see a "Congratulations Page"; select the "Security" option from the left column. Should be a link:


All we need is a password for MySQl. You can leave everything else default. There are other ways to do this, but I'm use to using user/password for db's so that's the way I've done it.

The following files are all that is required for a bare bones, "read and chart" system using a simple perl file to read and then a php file to chart. At this point, they need to be invoked independently and have to be manually modified for things like different lengths of time on the chart, or frequency of temperature reading. Both will need the db password chanded, and the perl file will require the id numbers of your particular sensor to be entered manually.

At the risk of sounding like I'm endorsing a product, (which I am); but I've had good service and the prices are about as good as anywhere from hobby boards.

The sensors are DS18s20

And the adapter is the DS9097U


Most of the software above is pretty straight forward in installation, simply follow the instructions or run the setup file.

The two that may seem a little different are digitemp and jpgraph.

digitemp has to be configured from the command line. This is fairly simple to do with the following steps.

First, be sure the 1-wire drivers were installed. Then plug in the 1-wire setup to the serial port of your pc. Run the One wire Viewer (should be in the "Programs" of your start menu. Once it's up and running, you should see the serial number for the sensors and the adapter in the left column. Select a sensor, and then select the "temperature" tab that appears about the right column. In real time it will return temps and chart them.
The viewer does require java, but that's free too)

Next, open a command line window (from start menu, select 'run' from the bottom right column, and type "cmd". A window with black background should appear, and you should be in a subdirectory like:

C:\Documents and Settings\Administrator>

type the following at the command prompt:
cd c:\digi\win

and then type:

C:\digi\win>digitemp_DS9097U -s /dev/ttyS0 -a -c .digitemprc

you should see something like this:

C:\digi\win>digitemp_DS9097U -s /dev/ttyS0 -a -c .digitemprc
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Dec 09 21:41:50 Sensor 0 C: 17.69 F: 63.84

now type:

C:\digi\win>digitemp_DS9097U -s /dev/ttyS0 -w

which should result in something like this:

C:\digi\win>digitemp_DS9097U -s /dev/ttyS0 -w
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
..
Devices on the Main LAN
109DBCFE0008007C : DS1820/DS18S20/DS1920 Temperature Sensor
0943648703000055 : DS2502/DS1982 1Kbit Add only memory

this second step will provide individual sensor id's that get plugged into the brewWare.pl file below.

Jpgraph is simply a library of php modules and requires very little but unpacking into a folder in the root directory (c:\ in windows).

One of the last things to do is to set paths so that some of these new tools can be found from anywhere by any of the software. To set paths:

Right click on "My Computer" (from start menu)
Select "Properties"
Select "Advanced" tab then "Environmental Variables"
In top window (if there is no "Path" option) select "New" and for "Variable Name" put (you guessed it) "Path" and "Variable Value" is "C:\cygwin\bin;C:\Perl;C:\Xampp;" then OK and OK

(cont. in reply due to lengthy post!)
 
Now, the two custom files that do the work. Both of these can just be pasted into a notepad file, and saved with the specific extensions.

First is the perl file that sets things in motion.
Copy the code below into notepad, edit the PASSWORD for the MySQL database, and the id numbers for the sensors, and then save it as "brewWare.pl"
If your paths are set correctly, this can be saved executed from anywhere on your pc. Just remember where you saved it!

If you don't have as many sensors as I've got in there, you can just leave the default number in place and the program will just skip over it.


# Mods = Gill
# Category = i-buttons
# Type = Read and Record Mash and Brew Temps
# Update = Version 1.0 - December 2, 2009

use DBI;

# Database info
my $db_name = "wort_master";
my $db_user = "root";
my $db_pass = "PASSWORD";
my $host = "localhost";

# Connect to the database
my $dbh = DBI->connect("dbi:mysql:$db_name:$host;","$db_user","$db_pass")
or die "I cannot connect to dbi:mysql:$db_name as $db_user - $DBI::errstr\n";
my $air = " ";
my $hotLiquor = " ";
my $mashTun = " ";
my $lauterTun = " ";
my $brewKettle = " ";
my $serialnumber = " ";
my $temperature = " ";
my $sql = " ";

# The DigiTemp Configuration file to use
my $digitemp_rcfile = "c:/digi/win/.digitemprc";
my $digitemp_binary = "c:/digi/win/digitemp_DS9097U";

#this counter test it how many times to take a reading
#it is set in conjunction with the sleep function to come up with the overall
#time. default is to sleep for 20 seconds, so 180 reads per hour, so 720 is 4 hrs
for ($count = 720; $count >= 1; $count--) {

open( DOGI, "$digitemp_binary -q -a -o\"%R %.2F\" -c $digitemp_rcfile | " )
or die "couldn't get the temp up\n";
while( <DOGI> )
{
chomp;
($serialnumber, $temperature) = split(/ /);

if ( $serialnumber eq "109DBCFE0008007C" ){
$air = $temperature;
}
if ( $serialnumber eq "109DBCFE0008007C" ){
$hotLiquor = $temperature;
}
if ( $serialnumber eq "109DBCFE0008007C" ){
$mashTun = $temperature;
}
if ( $serialnumber eq "109DBCFE0008007C" ){
$lauterTun = $temperature;
}
if ( $serialnumber eq "109DBCFE0008007C" ){
$brewKettle = $temperature;
}
}

my $sq="INSERT INTO digi SET Air='$air', HotLiquor='$hotLiquor', MashTun='$mashTun', LauterTun='$lauterTun', BrewKettle='$brewKettle' ";
# print "SQL: $sql\n" if($debug);
$dbh->do($sq) or die "Can't execute statement $sql because: $DBI::errstr";
sleep (20);
close( DOGI );

}

Now the php file that creates the graph: with this one, all you need is the MySQL password

<?php
include ( "c:/jp/src/jpgraph.php");
include ("c:/jp/src/jpgraph_line.php");
//require_once("c:/jp/src/jpgraph_date.php");
$datax = array('1', '2', '3', '4');
$xpos = array("60", "120", "180", "240");
$week = DATE(W);
$db = mysql_connect("localhost", "root","PASSWORD") or die(mysql_error());
mysql_select_db("wort_master",$db) or die(mysql_error());
$sql = mysql_query("SELECT * FROM digi") or die(mysql_error());


while($row = mysql_fetch_array($sql))
{
$ydata[] = $row[3];
$ydata2[] = $row[4];
$ydata3[] = $row[5];
$ydata4[] = $row[6];
$ydata5[] = $row[2];
}


// Create the graph. These two calls are always required
$graph = new Graph(900, 550,"auto");
$graph->SetScale( "intint" ,0,240,0,239);
//$graph->xaxis->SetPos("min");
$graph->SetShadow();
$graph->ygrid->Show(true,false);
$graph ->xgrid->Show( true,false);
//$dateLocale = new DateLocale();
//$dateLocale->Set('');
$a = $gDateLocale->GetShortDay();
$graph->xaxis->SetFont(FF_GEORGIA, FS_BOLD);
$graph->yaxis->SetFont(FF_GEORGIA, FS_BOLD);
#$graph->xaxis->SetMajTickPositions($xpos,$datax);
#$graph->xaxis->SetTextLabelInterval(4,1);
$graph->xaxis->SetTickLabels($datax);
#$graph->xaxis->SetTextTickInterval(15);
$graph->yaxis->scale->ticks->Set(10,2);
#$graph->xaxis->scale->ticks->Set(15);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);



$graph->title->Set ('WortMaster Brew Monitor');
$graph ->title->SetFont( FF_GEORGIA, FS_BOLD, 16);
$graph->img-> SetMargin(60,100 ,30,50);
$graph->xaxis-> title->Set(" Minutes");
$graph->yaxis-> SetTitle("deg. F","low" );
//$graph->SetTitleMargin(0.5,0.01);

//$graph->SetScale( 'datlin');
$graph->xaxis->SetLabelAngle(90);

// Create the linear plot
$lineplot =new LinePlot($ydata);
$lineplot ->SetColor("darkgreen");
$lineplot ->SetWeight(2);
$lineplot2 =new LinePlot($ydata2);
$lineplot2 ->SetColor("darkblue");
$lineplot2 ->SetWeight(2);
$lineplot3 =new LinePlot($ydata3);
$lineplot3 ->SetColor("darkviolet");
$lineplot3 ->SetWeight(2);

$lineplot4 =new LinePlot($ydata4);
$lineplot4 ->SetColor("yellow");
$lineplot4 ->SetWeight(2);

$lineplot5 =new LinePlot($ydata5);
$lineplot5 ->SetColor("brown");
$lineplot5 ->SetWeight(2);
// Add the plot to the graph
$graph->Add( $lineplot);
$graph->Add( $lineplot2);
$graph->Add( $lineplot3);
$graph->Add( $lineplot4);
$graph->Add( $lineplot5);
// Add Legend
$lineplot->SetLegend("HL");
$lineplot2->SetLegend("MT");
$lineplot3->SetLegend("LT");
$lineplot4->SetLegend("BK");
$lineplot5->SetLegend("Air");
$graph->legend->Pos( 0.015,0.5,"right","center");

//$graph->xaxis->SetTickLabels($a);

// Display the graph
#$graph-> Stroke("brew.png");
$graph->Stroke();
?>

Paste this into a notepad file and call it BrewChart.php
Create a folder in:

c:\Xammp\htdocs

and put that file in there.

And finally (for now), the database. Download this zip file:

Open a browser again and go back to http://localhost

Towards the bottom of the left column, under "Tools" select; phpMyAdmin
should have you put your password in. User will be "root"

Towards the middle, on the right, there's a window to enter a name under Create a Database. Type: wort_master

then hit "Enter"

Now select the tab at top that says "Import"
Select the button under File to Import that's labeled "Choose File" and point it do the zip file downloaded (no need to unzip. it knows what to do with it)

hit "go" in the bottom right.

That's it.

If all went well, should be able to open a command line (start>run>"cmd"),
change directory to wherever you put the brewWare.pl file and then type

perl brewWare.pl

The cursor should return to the left side and just flash. The program will run for 4 hours or until the command window is closed.

Open a browser and point it to the php file. If you named the folder in htdocs to 'brew', the you'd point to:


I made probes using 3/8" tubing brazed closed. First made three triangular notches, then bent them over, so not much silver was needed. Important to flux well and TURN THE PROBE UPSIDE DOWN first. Not that you'd do that. But I did on the first on, and some silver went through, preventing the sensor from going all the way to the end :( With the aid of a touch of mineral oil, the sensors and phone wire slip in easy enough to do about a 3 ft. probe, which is probably longer than anyone needs. But I'm not sure how I want these setup yet, so wanted some long enough to play around with.

I'm sure by now that some are thinking I'm a bit crazy for posting all this, but the next time I install this setup might be a year, or even two from now, and I can forget quite a bit in that amount of time. Besides that, perhaps there's someone out there that might possibly be able to use the info.


Maybe?
 
I'm sure by now that some are thinking I'm a bit crazy for posting all this, but the next time I install this setup might be a year, or even two from now, and I can forget quite a bit in that amount of time. Besides that, perhaps there's someone out there that might possibly be able to use the info.


Maybe?

Dude you rock! That is one in depth how-to. I am going to look it over more tomorrow when I can see straight and see how I can use it.

True open source

I took a look at hobby boards. I have not taken the time to look real deep, but do you think it would be much more work to get the 4 or 8 i/o device to control a SSR.

They have built in Relays but........ could you use them to trigger an SSR somehow or maybe take them off the board and solder wires from the relay input that would connect to the SSR. Essentially bypassing the built in relay and sending that signal to an SSR.

It you could figure out how to make it work. I could see this as an interesting automation solution for a brew rig. Temp and Element control from a server interface.
 
Awesome work Vinic! And very thorough writeup.

Just for clarification for myself, you have code setup for multiple (5) temp sensors, but you are currently only running one correct? It threw me for a minute when your code showed you checking the same serial # five times and assigning the same temp to air, mash, HK, etc.

Also, from what I can tell, this 1-Wire system is input-only? Is there any way to send out serial data to a specific device (specific serial #)? Like Brewmoor was talking about, I think you would need a new device to drive SSRs.
 
Just for clarification for myself, you have code setup for multiple (5) temp sensors, but you are currently only running one correct? It threw me for a minute when your code showed you checking the same serial # five times and assigning the same temp to air, mash, HK, etc.

Also, from what I can tell, this 1-Wire system is input-only? Is there any way to send out serial data to a specific device (specific serial #)? Like Brewmoor was talking about, I think you would need a new device to drive SSRs.

So far I have only tested this with water, I'm in the process of building a new brewhaus and the logistics of things had me working on this system first. So yes, each of those id's should be unique to each probe in use. The way this is setup, the input from the perl script is only as significant for what you want to use on the other end; ie the output from the php or whatever you'd like to implement. I haven't decided on exactly how to setup the 'tree' for the probes on this project. My other system spans a distance, and the recommendation is to use twisted wire as it's a passive type electrical signal that has potential for interference when there's a lot of wire involved. (NOTE: there is a third wire that can be run with 5 Vdc power to boost the signal, but I've yet to need that. I run about 20 ft of Ethernet cable to the cellar, then branch off from a wall outlet type fixture that can handle 8 rj45 jacks. This greatly aids in trouble shooting the system. For the beer setup, which will have maybe 8 ft of wire at the longest sensor, I plan on just using straight phone wire. Have found a 5 outlet splitter, but haven't pulled the trigger on that $6 unit yet. Guess that's the Scottsm'n in me: Deep pockets, but short arms!

The setup I have for the cellar, which will eventually monitor and control fermentations, is all setup for output. It employs yet another open source software that gets REALLY sic, including voice commands and responses! It too is perl based (how I got started with perl). The perl code I posted earlier fits into it without only one additional line.

Here's the Misterhouse home automation open source software project, which has a fairly active mailing list. I've had better success with the 2104 build recently. The newer one works, but causes some annoying errors that I've yet to be able to debug. The errors don't seem to hinder the functions I use.

My cellar fan system uses the X-10 powerline control system, (check ebay before pulling the trigger here) as the cellar environment is not a great place to house electronics, and running control wire was a little bit of an issue. Very handy to send the signals through the 'house' wiring.

There is a module built for MH to interface with weeder boards. I've had some limited success with using a simple hobby board, and have attached high power relays to these, and have also used some PLC's attached to it. Just can't pass up a good deal on ebay sometimes!

Though my op might seem a bit static, as the bulk of my attention in the short future is going to be focused on building a brewhaus, I do intend to continue developing a GUI for the setup, but also will be available for discussion if anyone else cares to pursue this route.

Thanks for the compliments, btw. The devil is in the details.

I've been gleaning over this group intensely for a month now, feeling I have very little to contribute, as I'm still in the learning stage of beermaking.
 
One question-- did you think of using an Arduino board for control? They are fairly cheap, and a lot of apps already exist for doing the same type of thing. It would eliminate the need for a PC to be running all the time...
 
One question-- did you think of using an Arduino board for control? They are fairly cheap, and a lot of apps already exist for doing the same type of thing. It would eliminate the need for a PC to be running all the time...

I had looked briefly at the Arduino, and a little bit at the BrewTroller, after seeing mention of them by Yuri and BlackHeart. They may be reasonably priced, but they are priced, and I already have devices in hand that serve my purpose. Control is still a bit off in the distance for me. My main interest is in charting the events of a mash/brew so when I finally hit on the magic process, I'll know what I did and have a better chance at repeating it!

Running without a pc is not an issue with me. Besides, how else would I keep up with HBT while brewing if I didn't have my laptop nearby!!??

I do have Parallax basic stamp laying around here somewhere from another project. Might have to pull it out to play with, once "everything else is done". (last quotes are a running joke around here. I don't ever expect to get everything else done!)

Thanx for mentioning this. I previously did not realize that folks were already using 1-wire devices here. I don't feel so all alone anymore.
 
Here's some pics of the probe I described earlier. They have not been tried on a full run yet (coming up soon, I hope!), but they seem to do real well with initial testing. I think the close tolerance of the small (3/8" o.d.) tubing, combined with the high conductivity of the copper make them fairly decent, quick acting and relatively accurate probes.

First task is to make three tabs shaped like shark teeth, just roughed out using a cutting wheel on a dremel:

probe1.jpg

Next was cleaning up a bit with a small triangular file, and then bending the tabs over by tapping lightly with a plastic-head mallet. This actually closed up a little more than I think is necessary, but it sealed up just the same.

probe2.jpg

I roughed them up a bit with some Scotch Pad, slathered them with plenty of flux, and then it only took a moment of heat and a touch or two of silver to get them to seal up:

probe3.jpg

I would not consider using these for a fermentor, but for hlt, mlt and bk, they should be fine.​
 
My order of some of the temp sensors just showed up today. I ordered from taydaelectronics.com in Thailand for $1.60 per sensor and $0.99 for shipping.

Ordered on 12/3, shipped on 12/4, and arrived today 12/12. Pretty good shipping time and the cheapest price I could find on them.
 
My order of some of the temp sensors just showed up today. I ordered from taydaelectronics.com in Thailand for $1.60 per sensor and $0.99 for shipping.

Ordered on 12/3, shipped on 12/4, and arrived today 12/12. Pretty good shipping time and the cheapest price I could find on them.


Nice find! Name reminds me of how a friend of mine says "today": T'day!

First adapter unit I purchased, years ago, was suppose to be a Cadillac version of the DS9097U: it crapped out about a year later. I adapted the cat 5 line I use to a rj11 plug and switched out with a DS9097U and it's been running that way for the last few years. Never noticed any difference. At the time I purchased it, the "Link" was the same price as the maxim version. I see now that they've 'bout doubled the price.
 
Found this for about 6 bucks at Lowes today and could not pass it up.


jackedUp.JPG


This topology is considered a star configuration and is not the optimal, but it's worked fine for me in the pass and the convenience tells me to at least try it out. It's working perfect so far while just testing. Finished making 3 more probes today. Should be ready to get them wet towards the end of the week if I can get away to get some supplies.

A side note: when adding or switching probes on this system, the digitemp configuration needs to be run again. When running this config again, the original config file (c:\digi\win\.digitemprc) needs to be deleted or moved from that folder.​
 
Back
Top