matho
The Braumiser
- Joined
- 30/4/08
- Messages
- 1,403
- Reaction score
- 142
I read someplace if you request temp readings on the DS18b20 too often it slowly heats up the sensor and it gives higher and higher readings. (Only just got mine so haven't tested this yet)
I haven't noticed this effect, I have had the unit running for over an hour with 2 other thermometers next to it and they were within 1 deg of each other. Once the sensor is in a thermowell and in liquid I would think the effect of self heating would reduce because there would be a large mass to take the heat away. On the braumiser when I was testing the temp reading of the DS18B20 stayed with my trusty lab thermometer all the way to about 86 deg then it started to vary and by the boil was low by about 1.5 deg.
if your worried about this you could change the code to
Code:
#include <OneWire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
// global variables
float sensor1;
float Temperature(int x){
static boolean Conv_start;
static unsigned double startTime;
float Temp_c;
byte data[2];
OneWire ds(x);
ds.reset();
ds.skip();
// start conversion and return
if (!(Conv_start)){
ds.write(0x44,0);
Conv_start = true;
startTime = millis();
return 0;
}
// check for conversion if it isn't complete return if it is then convert to decimal
if (Conv_start){
if( (millis()-startTime) >= 60000){
ds.reset();
ds.skip();
ds.write(0xBE);
for ( int i = 0; i < 2; i++) { // we need 2 bytes
data[i] = ds.read();
}
unsigned int raw = (data[1] << 8) + data[0];
Temp_c = (raw & 0xFFFC) * 0.0625;
Conv_start = false;
return (Temp_c);
}
return 0;
}
}
void setup()
{
lcd.begin(16,2);
}
void loop()
{
sensor1 = Temperature(11);
if (sensor1!= 0){
lcd.setCursor(0,0);
lcd.print(sensor1);
}
}
which should read the sensor every minute, depending on your PID settings you might want to reduce the amount of times you call your PID function as well