Introduction: Temperature Sensor / Weatherstation

Create a weatherstation or temperature monitor using the very cool digital temperature sensor DS1820.

I use this setup to monitor a server room, and as a weatherstation.

This project consists of:

  • A Dallas 1-Wire bus network
  • Interface between RS-232 and the Dallas 1-Wire system
  • Digital temperature sensors connected to the Dallas 1-Wire bus (DS1820/DS18s20)
  • Software setup to gather and graph temperatures

Updated 2007-11-18 to include automatic graphing scripts and pictures of real life implementations of this system.

Step 1: You Need

This is what you need to make a weather station or temperature logger:

  • Some linux skills
  • Basic electronics skills, soldering etc..

Components
  • 1 6.2V Zener diode (1N5234)
  • 1 3.9V Zener diode (1N5228)
  • 2 Schottky diodes (1N5818)
  • 1 1.5 k resistor
  • 1 2pin screw terminal
  • 1 D-sub 9 female connector with solder points
  • 1 small piece of perfboard.
  • One or more Dallas Semiconductor DS1820 or DS18s20 digital temperature sensor
  • Cat5 cabling
  • Shrink tube

Step 2: Build the RS232 Interface

I like to build the 1-Wire busmaster so small that it can just sit in the back of the computer in the rs232 port.

Step 1)
Figure out how small you can make it.
Put all the components on a perfbaord. Place them with the circuit in mind. We don't want to add any wires to the bottom of the circuit! Se image.

Step 2)
Cut out the right size perfboard.
Just drag a sharp knife a few times over the row of holes where you want to cut.
Do this on both sides, then just break it in two. It usually breaks at the fault line you created.

3)
Solder the components in place. and connect the solder points to complete the circuit.

Step 3: Testing the RS232 Interface

1)
Download and install digitemp.
On Debian and Ubuntu Linux, this is done by running `sudo apt-get install digitemp`.

2)
Connect a DS1820 to your circuit.
The middle leg goes in the DQ port, the other two legs go in GND

3)
Connect the circuit to a computers rs232 port.
I only cover doing this with Linux, but it is also possible to do this in windows..

4)
If the command `digitemp` doesnt work, it's because there are multiple versions of digitemp.
type digitemp, then press tab to see all of them.. digitemp_DS9097 is the right one for this 1wire busmaster.
Just for the sake of simplicity, we want the command to be `digitemp`, not `digitemp_DS9097`.
type `sudo ln -s /usr/bin/digitemp_DS9097 /usr/bin/digitemp`

5)
As root, or using sudo:
Run `digitemp -s /dev/ttyS0 -i`. This searches the 1wire network for sensors, and creates a config file for digitemp. If you are using COM2, use -s /dev/ttyS1.
Run `digitemp -a` to read the temperature of the connected tempsensor.
See the screenshot

6)
Do this for all the sensors you are going to use, and write down the addresses for each one.
When you have multiple sensors, it's nice to know which is which.

Step 4: Make the Sensors and the Network

When wiring up your 1wire network, you wan to use cat 5 network cables.
I have had some bad experiences using other cables, and with combining different types of cable.

When running over cat5, the 1wire bus can have quite long cables.
In one weatherstation setup, I run a 30 meter cat5 from a technical room with a Linux computer and up to the roof. On the roof, the cable is split into 3 5-15 meter long cables with a sensor at the end of each one. This setup works flawlessly. The 1-wire network is quite robust.

Making the sensor:

You want to make the sensor both waterproof, and rigid.

1)
Cut a Cat 5 cable to the desired length.

2)
De-insulate the sensor end.
Cut off 3 of the 4 pairs, leaving the green/whitegreen one.

3)
Slide a small shrink tube over the green wire.

4)
Solder the green wire to the middle pin of the DS1820

5)
Pull the the shrink tube up, so it covers all the metal of the middle leg and the metal of the wire connected to it. Then heat it with a lighter or heat gun to shrink it in place

6)
Solder the white/green wire to the two other pins.

7)
Put a larger shrink tube over the sensor and the cable.
See the picture.
Then heat it gently with a lighter to shrink in place.
You don't want to set the thing on fire, just hold the flame 4-10mm away from the shrink tube.

8)
Put your sensors wherever you want to have them, connect to the rs232 interface and plug into your computer.

Step 5: Software Setup - Data Acquisition

Now that we our sensors in place, we want to gather some data from them.

As root on your linux machine:

1)
Run `digitemp -s /dev/ttyS0 -i -c /etc/digitemp.conf`
This creates the config file digitemp.conf with yoru sensors.
Watch the output to see what number the sensors get.

2)
Check the temperature with `digitemp -aq -c /etc/digitemp.conf`

3)
Dump the output data into a file. I dump to a file within apaches wwwroot, that way I can access the temperature from anywhere.
The command `digitemp -aq -c /etc/digitemp.conf > /var/www/digitemp.txt` puts the output of digitemp into the file digitemp.txt

4)
Automate this process:
type `crontab -e`, this opens roots crontab.
Type `* * * * * digitemp -aq -c /etc/digitemp.conf > /tmp/digitemp; mv /tmp/digitemp /var/www/digitemp.txt` into that file, and save it.
Run `crontab -l` to confirm that the crontab has been installed.
The reason I am piping the output into /tmp and then moving it to /var/www, is that digitemp uses a few seconds to compete its run. If you try to access the output while digitemp is running, you would get an incomplete file. This could mess up other scripts that read data from this file. (This is not included in the screenshot, forgot to do it)

Your weatherstation is now up and running.
Use the data to do whatever you like, graph it, use it to email in case of high/low temp, etc..

Step 6: Software Setup - Graphing

This is the tricky part, lot's of scripting needed here.

1)
Make a place to put the scripts, a place to store the images, and a place to store the data.
`mkdir /etc/tempsensor`
`mkdir /var/www/temperature`
`mkdir /var/log/digitemp_rrd`

2)
Install software:
You will need, PHP and RRDtool.
`apt-get install rrdtool`
`apt-get install php` (there are many php packages, install one with a console executable)

3)
Download and install the scripts responsible for makin the graphs:
Download tempsensor-0.1.tar.gz to your linux machine.
`tar xvzf tempsensor-0.1.tar.gz`
`cp -v tempsensor/* /etc/tempsensor`

4)
Configure the scripts
Open /etc/tempsensor/config.php and follow the comments in this file.
Change the script to read input data from "/var/www/digitemp.txt" if you followed the example in the previous step.

5)
Automate.
Add a crontab entry the same way as in the previous step. The script should run every 5th minute.
The lines should look like this:
`*/5 * * * * php /etc/tempsensor/logdata.php`
`*/5 * * * * php /etc/tempsensor/graphdata.php`

6)
Run the scripts manually to check if it works.
php /etc/tempsensor/logdata.php
php /etc/tempsensor/graphdata.php

7)
Visit http://your.ip.or.hostname/temperature or whatever you specified in the config file.

Step 7: Implementation 1 - Server Room Monitoring

My first implementation of this system was in the serverroom at the student dormitories where I work. Here are some pictures for you.

Step 8: Implementation 2 - Weather Station

When I equipped the server room with temperature sensors, I just couldn't resist putting some on the roof aswel!

The weatherstation is a bit trickier than the serverroom.
There is a lot of interference outside.
The sun may hit a sensor, sending it from -1 to 30 c in 5 minutes.

I solved this by using three sensors placed at points which would receive sunlight at different times during the day. Since heat is the only "noise" in the measurement, I just use the sensor with the lowest reading at any time as my "outside temperature".

This temperature is again smoothed by averaging the last few minutes.

Step 9: Implementation 3 - Student Dorm Room

A friend of mine followed this instructable, and equipped his apartment with temperature sensors. In the fridge, bathroom, computer etc. :)

Comments

author
iRybin (author)2015-01-08

What's the hell with tempsensor-0.1.tar.gz ??

author
erazor (author)2014-12-19

does anybody have tempsensor-0.1.tar.gz???

author
zdrow (author)2014-10-31

tempsensor-0.1.tar.gz:

403 Forbidden

Request forbidden by administrative rules.

author
awilliams102 (author)2014-01-17

Where can i find the trmpsensor-0.1.tar.gz file?

author
makerghost (author)2013-12-23

Cool Stuff! I made the device and used a USB to serial adapter. changed tty0 to ttyUSB0 and all worked perfectly. Now the charts. I am unable to get the files to be able to complete the charts. can any one help? I am currently running a cron job with some scripts to change the data to CSV type file to be able to chart the data using other software.

author
humall (author)2013-06-04

Same here, just need the tempsensor tar file, can someone send it to me, thanks in advance.

author
deadbrain (author)2013-05-10

hi,
anyone would be nice enough to send me the tempsensor-0.1.tar.gz file ?
it seems that the file is unavailable since Mar, 6...

author
shikilee (author)2013-04-22

Hi all, can anyone sent me the link of tempsensor-0.1.tar.gz ?

author
bogaskilop (author)2013-03-06

hello all

where can i download this file tempsensor-0.1.tar.gz ???

author
rfa.ak47 (author)2012-11-19

Cool! Excellent instruction.

author
alantch (author)2012-08-01

I just finished making one of these, but will not be able to test it out until I receive my sensors. In the meantime, I'm getting a voltage of 5.75V between GND and DQ. Would this be too high as I read that the DS18S20's operating voltage range is 3.3-5.5V?

author
gadragon (author)2011-12-12

Can i use 1N5819 instead of 1N5818?

author
humall (author)2011-11-04

I have little experience with soldering so I made a breadboard version of the circuit, see pdf file I added, I used Ubuntu for Digitemp and everything works fine, rrd-tool and web server setup. Tried to use Windows version of Digitemp, did not work. Thanks for making this instructable, it showed me how to use 1-wire bus.

breadboard_temperature_ds1820.pdf
author
garacs (author)2011-09-23

This is EXACTLY what I am looking for, but unfortunately it uses DALLAS DS1820 sensors, I do not have handy at the moment.

Would this also work with a LM35DZ? If so, what would be the differences in the scheme?

BTW, great instructable.

author
andy70707 (author)2011-04-17

Will this interface work with other 1-wire devices such as iButtons? And can it do bi-directional serial (read+write) or just simply reading from the device?

author
Wavy (author)2011-03-16

Great Instructable! Using a breadboard, everything worked out smoothly. I also used the MartyBugs' schematic to confirm the setup. Very nice and fun, thanks!

author
titan44 (author)2009-08-28

Is it possible to make this work with a db25 instead of a db9?

author
Brafferton (author)titan442011-01-27

Db25:
Pin 2 Transmit
Pin 3 Receive
Pin 7 Ground
Pin 20 DTR (if using non-parasitic)

author
Brafferton (author)2011-01-27

Short answer is, you don't.
The 18S20 is a 1 wire serial device
Your printer port will only talk to parallel devices.

author
thermoelectric (author)2009-05-08

I tried this on Linux (Ubuntu) and when I typed this into the terminal "digitemp -s /dev/ttyS0 -i" i get this

"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

Searching the 1-Wire LAN"

Problem is it doesn't show any sensors....

author

It's not physically working. Check all the components are correctly polarised (My goof was wiring the D"18S20 back to front)

author
darkcape (author)2009-07-06

Loving this I have wanted to do this ever since reading about it in the linux toys book. on question I have though what is the maximum number of sensors that the 1 wire network can handle?

author
Brafferton (author)darkcape2011-01-27

Depends on whether it's in parasitic mode or non parasitic. From the number of components used, I'd say it in parasitic mode. Therefore, no more than 3.
In non-parasitic mode (2 more components required) 10 or 12 would be quite happy. With a separate 5 volt PSU, several thousand.

author
Waren-Neutron (author)2010-09-05

you have to work in weather forcast

author
eng_islam_h (author)2010-04-10

thats really great,i've done it and it works really fine with the 1 wire driver from maxim, now i'm trying to read the data in LabView and i'm really close
great job
thanks 

author
salimi (author)2009-06-23

hi please write vb code for monitoring graph

author
thermoelectric (author)2009-05-22

I don't know if I have done it right, but when I try to run the logdata script manually I get a error. What do you suggest? beau@beau-desktop:~$ php /etc/tempsensor/graphdata.php ERROR: opening '/var/log/digitemp_rrd/0.rrd': No such file or directory ERROR: opening '/var/log/digitemp_rrd/0.rrd': No such file or directory ERROR: opening '/var/log/digitemp_rrd/0.rrd': No such file or directory ERROR: opening '/var/log/digitemp_rrd/0.rrd': No such file or directory ERROR: opening '/var/log/digitemp_rrd/0.rrd': No such file or directory ERROR: opening '/var/log/digitemp_rrd/0.rrd': No such file or directory ERROR: opening '/var/log/digitemp_rrd/0.rrd': No such file or directory ERROR: opening '/var/log/digitemp_rrd/0.rrd': No such file or directory Warning: fopen(/var/www/temperature/index.html): failed to open stream: Permission denied in /etc/tempsensor/graphdata.php on line 75 Warning: fwrite(): supplied argument is not a valid stream resource in /etc/tempsensor/graphdata.php on line 76 Warning: fclose(): supplied argument is not a valid stream resource in /etc/tempsensor/graphdata.php on line 77 Warning: fopen(/var/www/temperature/index_0.html): failed to open stream: Permission denied in /etc/tempsensor/graphdata.php on line 102 Warning: fwrite(): supplied argument is not a valid stream resource in /etc/tempsensor/graphdata.php on line 103 Warning: fclose(): supplied argument is not a valid stream resource in /etc/tempsensor/graphdata.php on line 104 Warning: fopen(/var/www/temperature/index_all.html): failed to open stream: Permission denied in /etc/tempsensor/graphdata.php on line 102 Warning: fwrite(): supplied argument is not a valid stream resource in /etc/tempsensor/graphdata.php on line 103 Warning: fclose(): supplied argument is not a valid stream resource in /etc/tempsensor/graphdata.php on line 104

author
bhp0528 (author)2009-04-30

I'm a little shy (actually lazy) when it comes to circuit boards and solder. I noticed a similar tutorial was using a http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2982 to interface from serial to RJ-45.

Looking at the documentation it appears this would do the same as your diodes and soldering and give you a RJ-45 to boot. The site appears to spec the device for $21. Any idea how that would compare to soldering diodes in price and functionality?

author
bhp0528 (author)bhp05282009-04-30

After looking at the site a little longer I found a number of different adapters (USB, Serial, etc). Has anyone tried these?

http://www.maxim-ic.com/products/ibutton/products/adapters.cfm#rs232

author
Solargoat (author)2009-04-04

I built it, but having zero electronics experience, and not much software experience, I am not sure if it works. After downloading various programs to read it, including 1-WireViewer, Lampomittari, and I can't seem to get it to recognize my interface. I guess it is a hardware problem in how I constructed it. What can I do to troubleshoot this device with a multimeter? What is the proper voltage that should be coming out of my serial port on my Dell Latitude D620 notebook? I am getting 4.98 Volts now. If someone could get me started, I would be eternally grateful!

author
Solargoat (author)Solargoat2009-04-04

That was a quick reply! I have an iMac and a Gigaware USB-serial converter. I guess I'll try that, but now that will introduce its own issues with software.

author
chr (author)Solargoat2009-04-04

Some notebooks don't output the full RS232 voltage of +/- 12-ish volts. Try the device on a desktop computer first to figure out if the voltage level is causing the problem.

author
ax89 (author)2008-11-27

Very neat! How many sensors can you hook up? (I apologize if this was asked and answered but I didn't see it when I read through.)

author
thermoelectric (author)ax892009-03-06

It will tell you how many sensors can be connected on the datasheet of the 1-wire sensor.

author
thermoelectric (author)2009-02-23

Wow, After attempting to make the interface, I can safely say that you are GREAT at using protoboards.

Do you know how I can use this on windows?
I have tried what you said below but it doesn't work, What does the digitemp -aq > c:\path\to\webserver\root\temperature.txt mean?

author
chr (author)thermoelectric2009-02-23

Thanks, -a means aquire, -q means quiet the "> file" means put the output into this file I don't know if this is the right syntax in windows. I don't know anything about windows, so I can't help you there...

author
thermoelectric (author)chr2009-02-23

Oh, Thanks anyway, I might just have to try the alternate install of Ubuntu (128mb RAM)

author

That is a definite thing i'm going to have to do since I can't get it to work in windows....

author

Scratch that :-)

author
thermoelectric (author)chr2009-02-24

By the way, Why do you reccommend using CAT5 cable over telephone cable?

author
chr (author)thermoelectric2009-02-25

I had some major issues when using telephone cable. I have an installation using cat5 with about 50 meters of cable, and that one works just fine.

author
thermoelectric (author)chr2009-02-25

Issues? What was happening with the telephone wire to cause major issues?

author
thermoelectric (author)2009-03-06
Hey, I'm back. I have been able to make it run on Windows but it can't dectect my interface, Is there a way to test what I have wired incorrectly?

BTW to get it to run on windows you need to
  • download the current Windows digitemp
  • find the digitemp.exe file in the digitemp file
  • copy that to WINDOWS/system32
  • Go into command prompt and type "digitemp", That will give you the syntax of the command

Hope I could help anyone that is trying to use it on Windows...
author
BCHurricane89 (author)2008-08-31

looks good, nice job. just wondering, because someone asked before, and I have the same question, but it wasnt answered: Can i use a DS18S20+ sensor? the DS1820 is discontinued, and I can get the DS18S20+ free, as a sample. :) plz respond, THANKS!

author
chr (author)BCHurricane892009-02-23

I think any DS18*20* would work. try googling the digitemp documentation..

author

Yes you can use the DS18S20+ (All the + indicates is the lead free status...)

author
goldust (author)2007-11-21

hi chr this tutorial is very Useful. but i want to Setup software for WindowsXP . can you help me? (i know you are Professional)

author
chr (author)goldust2007-11-21

Hehe I don't know if I'm professional. Most people who call them selves professional would probably have bought a ready made system for $5000 ;)

Anyways, I find doing these kind of things on windows to be kind of a pain.
Although most of the software is available for windows.

Digitemp is available here: http://digitemp.com/software/windows/
I would think dtreg25.zip is the most current version.
With digitemp the setup would be pretty much the same as in Linux.
Make a batch file, i.e. readtemp.bat containing a line like this:
"digitemp -aq > c:\path\to\webserver\root\temperature.txt"

There are many other programs to run 1-wire sensors on windows. A google search brings up plenty.
For example: http://www.henriksens.net/1-wire/

Good luck making it work on Windows.

Maybe I'll give it a go myself, and post a step on win32, but now I'm in the middle of my final exams.

author
thermoelectric (author)chr2008-08-25

Have u had a go at making it run on windows?

author
thermoelectric (author)2008-08-08

Can I use a DS18S20+ (i think the plus indicates the RoHS status)

About This Instructable

91,062views

227favorites

License:

Bio: I like microcontrollers and LEDs :D
More by chr:Reverse Engineering: RGB LED Bulb with IR remoteReverse engineering: USB controlled home automation hackLED Cube 8x8x8
Add instructable to: