Lagging behind real temp - Waterproof (DS18B20)

Hi,

I have been using the waterproof temperature sensor (DS18B20) from Sparkfun. It seems quite accurate, but only if allowed some time to sync against actual temp. I use an SSR that connects to a kettle, and the sensor is placed inside. I have programmed it to stop heating when hitting desired temp, but when I measure with a second thermometer, the real temperature is often 5-6 degrees higher than the sensor senses. If I program in a break of 60secs, the sensor and thermomter syncronizes.

Will the same sensor in stainless steel behave differently? Or does any one have any suggestions of how to "tune" the sensor?

best regards,
Aleksander Hansen

About 5-6 degrees is a lot. Could it be something in the sketch ? If you dump the temperature to the serial monitor, are those temperature okay ? Is it the normal overshoot of the system (kettle with heater) ? You don't use a PID ?

Yes, it too much. I have been playing around with PID also, but anyway, if the reading is so far behind actual temperatures, it will be difficult anyway.

Below is the test code. Can it be something with the code?
In the code, I just set the relay high to start heating from some cold temperature. It is just to monitor the difference between measured temp and actual temp read with a basic thermometer.

If start temp was 16 deg, the temperature difference between my themometer and the temperatures shown in the serial monitor was 4 degrees allready at 25 degrees actual. And it keeps increasing...

#include <OneWire.h>
#include <DallasTemperature.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2


/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

DeviceAddress Probe01 = { 0x28, 0xE2, 0x60, 0x74, 0x06, 0x00, 0x00, 0x3F }; 
DeviceAddress Probe02 = { 0x28, 0x38, 0xF6, 0x73, 0x06, 0x00, 0x00, 0x99 };

int relayPin = 11;

void setup()  
{
  Serial.begin(9600);
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  

}//--(end setup )---

void loop()   
{
  
  delay(1000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();

  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();
 
  
}//--(end main loop )---


/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   Serial.print("C: ");
   Serial.print(tempC);
   Serial.print(" F: ");
   Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}// End printTemperature
//*********( THE END )***********

I have tested the DS18B20 with ice water and boiling water. I forgot how long it took to settle, but it took a while for the maximum accuracy. I think 10 seconds is normal to get close to the temperature. Perhaps the isolation makes it 15 or 20 seconds.
How fast does the temperature rise when the heater is on ?
What is in the kettle ? Water or something lighter, like ethanol ?
Perhaps a NTC is a little faster. A thermocouple is very fast but also inaccurate.

I don't know which material Sparkfun uses, and if glue/sealant is used.
A stainless steel cap could be faster, but also glue/sealant could be used to fix it in the steel cap..

Another question: Is it for food ? I think the Sparkfun sensor is not food safe.

Clearly, the importance of any lag is determined by the rate of change in material being measured, but I think ten seconds is far too long for anything. I use the normal eBay weatherproof sensors and they are so fast I have given up trying to measure anything. This is with domestic hot water systems and comparing with a lab-grade mercury in glass thermometer.

It's not likely to be the cause of your problem, but I don't think much of the code. It appears to mix different methods. You state the addresses of the devices, yet are looking for devices in the system.

You don't need to set resolution to 12. It is there by default.

I have found the sensors very robust. Maybe yours are suss but I recognise this is a bit of a stretch if you have two of them.

I have water in the kettle. Its 2000w and one liter, so it might be tough to keep up?? Im not sure exactly how fast it heats the water but, imo its not so fast that the sensor should fall behind as much as it does. In my final setup, it will be 2500w in 40-50 litres. It will probably slow the heating down to a rate where rhe sensor kan keep up?

Still, if anyone has an idea as to why my sensor Is so slow to adapt, or have any suggestions as to what I might try, I will be very happy.

Also, the sensor will be used to control mashing temps in brewing, so I think I will replace it with the stainless steel (316) version from Adafruit. I guess this is foodsafe?

2000 Watt into 1 liter, that is indeed too fast for the DS18B20. The 5-6 degrees lagging behind is even faster than what I would expect.

2500 Watt into 40-50 liter is better. I think the lagging won't be an issue.

The stainless steel is food safe, but the wires are not.
Adafruit has food safe heat shrink : Food-Grade Heat Shrink - 3/8 diameter 12 long : ID 1020 : $3.95 : Adafruit Industries, Unique & fun DIY electronics and kits
They use it in the souse-vide project : Sous-vide powered by Arduino kit pack - The SousViduino! : ID 1401 : $99.95 : Adafruit Industries, Unique & fun DIY electronics and kits

In a similar topic, someone mentioned a temperature sensor that is food safe, and uses a serial interface, it is even certifed. It is not very expensive. I forgot the name...

Found it : High temp liquid thermostat - #4 by TomGeorge - Project Guidance - Arduino Forum
Scroll up on that page to see the Atlas sensor that TomGeorge mentions.

Impressive specs : http://www.atlas-scientific.com/product_pages/probes/env-tmp.html

I was looking at the ENV-TMP sensor from Atlas, and it will probably fit nicely into my project. Also, coding and wiring seems much easier than the previously mentioned sensor. I did some searching and read that a few others experience that the sensor spends some time settling. The ENV-TMP is also a bit thicker in diameter - - do you think this will be slower or faster than the DS18B20 with a stainless tube? I guess this is just something that I need to test...?

Anyway, thanks a lot! :slight_smile:

You should test it, or just buy one and go for it.

That sous-vide by Adafruit uses a PID. That means the heating is slowed down when it reaches the temperature.

By the way, the DS18B20 is not hard to use. Use the newest OneWire library with the included example, or add also the newest DallasTemperature to the project.
The DS18B20 is cheap and accurate and it stays accurate over the years. Using 10 sensors with a single Arduino pin is not harder than using a single sensor.

I think I'll probably go with the DS18B20. I have testet three of them, and they work fine and are easy to use. I will probably have to replace them with the stainless version, but thats fine.

Another question regarding PID (which I have read very little about). In our brewery setup, we have two tanks, where one is filled with hot water and the second contains the mash. The mash is circulated through a copper coil that is submersed in the hot water tank and returned to the mash tank. The idea is to measure the temperature in the mash tank (which is the important one), and based on this regulate the temperature in the hot water tank. This is two inputs - - does the PID-library support that? Or maybe the "Input" can be a function of the errors between the two, and the setpoint equal to 0?

No, the PID does not support that.
I have to say that I know nothing about brewery, but I see either one control loop, or two.

one
One control loop has the mash temperature as input and the heater as output.
The actual water temperate is not important.
There is a delay between turning on the heater that eventually increases the temperature of the mash.
When the heater is turned off, the mash temperature still increases for a while. To make a temperature control, I think it has to be a slow control, or else the water temperature could oscillate.

I don't know if a PID would always work, since the system parameters change when there is more or less mash. There is an autotune function for the PID, that expects certain fixed system parameters.

two
What about two control loops ?
A PID to control the water temperature with the heater (water temperature is input, heater is output), and another (slower) PID that controls the water temperature setting (mash tempearature as input, water temperature as output).

Suppose there is a switch for the heater, and a temperature display on both tanks. One person could operate the switch to keep the temperate of the water stable. Another person would look at the mash temperature and tell the first person to increase or decrease the temperature a little. That would be two control loops.