Page 1 of 1

Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 12:34 pm
by Alfadaz
Does anyone know of a temperature sensor that is known to be working with the Pi?

I am looking to control the temperature of water. Anywhere between ambient and say 100deg C.

Initial idea is to use the Pi, a temperature sensor and a heating element to keep the water at a precise (to 0.1 deg C) set temperature for longish periods. (maybe upto 24-36hrs). Some sort of timing on the Pi would shut off the heating element after the preset time and a buzzer would sound.

Would obviously need some coding too, i guess to read the temp sensor, then maybe switch a relay on and off for the heating element to keep the desired temp and a bit of code for the timings and the buzzer - any idea on what program/language would best suit? (complete novice on programming, so it doesnt matter which one is recemmended as i would be working learning from scratch)

Cheers

Daz

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 12:53 pm
by pluggy
I think the Arduino would be a better starting point than the Pi. It should be possible to use Maxim DS1820 digital thermomters or similar with the Pi but the libraries and stuff is already written and tested on the Arduino. The Arduino does analogue as well so a thermocouple or thermistor solution is an option.

Heretic ? me ? nahhhh......

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 1:07 pm
by dknute
Alfadaz, I think you're about to find out that 0.1 deg C precision comes with a price. Hefty one.

The best approach would be to buy inexpensive I2C or SPI chip with good linearity and compensate for the initial offset and/or skew with one- or two-point manual calibration. Even that is much more problematic than you think, icy water is usually not exactly 0 deg C and boiling water has too many vapour pockets to get proper readings with small probes. I take it you don't have access to a calibrated instrument you could use to compare results? And by 'calibrated' I mean something that comes with a certificate, not a Chinese toy that says it's accurate on the box.

If this is a hobby project I'd stick to 0.5 deg C precision - this can be done even without additional calibration with some chips (they do it in the factory). Just be sure to pick something that can work with 100 deg C for extented periods of time.

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 1:42 pm
by Alfadaz
I wanted to use the Pi rather than an Arduino because a) i already have a Pi :D and b) i wanted keep the option of maybe being able to monitor it/control it over the interweb at a later date.

dknute - No doubt you are correct, 0.1deg was a figure off the top of my head, i just assumed a digital sensor would be that accurate :oops:

I have been googling the DS1820 that pluggy kindly mentioned (seems to come up as DS18B20 - i assume its the same jobby), which is accurate to +/-0.5deg, which will be good enough for what i need, certainly at this stage.
  • 3.0-5.5V input voltage
  • Waterproof
  • -55°C to+125°C temperature range
  • ±0.5°C accuracy from -10°C to +85°C (87 deg C is probably as high as i will need to go, 100 deg just gave be a bit of headroom)
  • 1 Wire interface
Funnily enough, when i put 'DS18B20' in to Google, the Raspberry Pi gets a mention and that GPIO 4 can now read this data following a kernel update? Hopefully this bodes well for me :D

Daz

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 2:03 pm
by pluggy
The DS1820, DS18B20 and the DS18S20 are all variants of the same thing. I have DS18S20's which default to 1/16th of a degree Celsius resolution. I can't vouch for their accuracy to better than about half a degree, but they all agree with my old 'steam driven' analogue room thermometers. I use them with Arduino, nice libraries already written. Info with using them with the Pi is a bit thin. The one wire digital interface is timing critical which means the Pi might be struggling.

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 4:25 pm
by alexeames
0.1 degree precision is doable cheaply if you use an ADC with a tweakable reference voltage (e.g. MCP3008). For example the way I've done this is found at the end of this link as part of my review of the Pi Cobbler. The accuracy will depend on your calibration. You can adjust the calibration in software.

http://raspi.tv/2012/adafruit-pi-cobbler-review

I've had success with TMP36, LM335Z and recently I got DS18B20 working too (only on GPIO 4). All are good. TMP36 is the easiest analog sensor to use as it requires no additional resistor (costs about £1.50 and the ADC is about £2.50)

Adafruit also has great information on temperature sensors. I initially had trouble with the DS18B20, but the recent Kernel updates made it work - happy days. Those are about £3 each :D (But they have their own ADC onboard)

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 6:09 pm
by pluggy
After researching this and then making a test setup, I found its easier to get DS18X20 running on the Pi than the Arduino.

http://www.cl.cam.ac.uk/freshers/raspbe ... mperature/

If you're running a recent image, start at Step 2.

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 6:31 pm
by alexeames
pluggy wrote:After researching this and then making a test setup, I found its easier to get DS18X20 running on the Pi than the Arduino.

http://www.cl.cam.ac.uk/freshers/raspbe ... mperature/

If you're running a recent image, start at Step 2.
Yep. I used that with the DS18B20.
First time I tried in September I had real trouble with it - i.e. gave up.
Tried again last week and it was quite easy. I like instructions that "just work" :lol:

What I like about the 8 channel ADC approach is that you can get 8 analog inputs for the "price" of 4 GPIO ports. (Of course now you're going to tell me that you can daisy-chain loads of 1-wire devices all off one port - I know that :lol: )

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 7:03 pm
by pluggy
Of course you can daisy-chain the DS1820's and can get many for the price of one GPIO port (I have 5 running on one pin on my arduino setup). My Pi test setup has two. They have their own 1 wire address and can be read individually. My arduino test setup has the two with the bodies touching each other and they read within 0.0625 (1/16) of a degree of each other.

Image

The t=xxxxx is the temperature in milli-degrees

Re: Temperature Sensor & Buzzer

Posted: Thu Nov 29, 2012 7:39 pm
by pluggy
Real world thermometer reading 21.5 - 22 ish with DS18S20s as last post ( 21.25/21.31 ).

Image

Hmmm, that coffee cup needs a wash out....

Re: Temperature Sensor & Buzzer

Posted: Fri Nov 30, 2012 2:38 pm
by Alfadaz
Excellent information and links guys - many thanks!

As the DS18B20 was a known working unit and i could get my hands on it quickly, i went ahead and ordered one yesterday and it was delivered this morning 8-)

I haven't tested it yet as im in work and don't have any 4k7 resistors with me :(

Time to learn some Python :twisted:

Daz

Re: Temperature Sensor & Buzzer

Posted: Fri Nov 30, 2012 3:35 pm
by nr.
Here's a bit of perl I put together a while back to read my DS18B20s:

Code: Select all

#!/usr/bin/perl

$count = 0;

open(INDEX, "cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves | tac|");
@index = <INDEX>;
close(INDEX);

foreach (@index) {
  chop;
  $crc = "NO ";
  while ($crc ne "YES") {
    open(SENSOR, "cat /sys/bus/w1/devices/$_/w1_slave|");
    @data = <SENSOR>;
    close(SENSOR);
    $crc = substr(@data[0], 36, 3);
    $attempt++;
    die if ($attempt == 25);
  }
  my $temp = (substr(@data[1], 29, 5)/1000.00);
  my $fahr = ($temp*9.0/5.0)+32.00;
  $date = `date "+%b %d %H:%M:%S"`;
  chop $date;
  print "$date Sensor $count C: $temp F: $fahr\n";
  $count++;
}
Hope it helps. The reason for piping the read into tac is that I had to replace one of the sensors, and the program then started reading them backwards. Was easier to just reverse the order of the input lines rather than change the graph plotting stuff that I do with the resulting output file.

Ta,

Re: Temperature Sensor & Buzzer

Posted: Fri Nov 30, 2012 3:44 pm
by pluggy
Alfadaz wrote: I haven't tested it yet as im in work and don't have any 4k7 resistors with me :(
From experience with the arduino they aren't particularly fussy if you're not running long cables. You'll probably find anything between 1K and 10K will work if you have anything in that range.