ds18b20 causes hangup of ardiono uno

Hi all,

I have a simple project.

The aim of the project is to switch on and off a heater and a vakuum pump. The reason behind this is to completely dry transformer oil before use. With a potentiometer I can set a target temperature and the temperature probe does read the current temperature. I use solid state relais to switch on on off the heater and the vacuum pump.

However I am currently strugling with something as simple as the ds18b20 temperature sensor.

It took me a long time to trace down the problem to the ds16b20...

This is the function where I get the temperature...
If I bypass the temperature read there are no hangups - the entire sketch runs as it should...
(but I do not have the temperature :frowning: )

// Temperatur vom Sensor auslesen.
double get_temp() {
  //sensors.requestTemperatures(); 
  //double value = sensors.getTempCByIndex(0);
  return 10;
  //return value;
}

Now this will cause hangups and reboots after a few seconds or a few minutes...

// Temperatur vom Sensor auslesen.
double get_temp() {
  sensors.requestTemperatures(); 
  double value = sensors.getTempCByIndex(0);
  //return 10;
  return value;
}

I have done a whole load of experiments to rule out other reasons I can think of:

  • Try with other power supply.
  • Use a different ds16b20.
  • Add 100 µF paralel to the supply of the sensor.
  • Add 2000 µF paralel to 5V of the entite arduino uno.
  • Drive the SSR not directly, use transistors to drive them...

Nothing helped...

Any ideas?

Here is the complete sketch:

oil_dryer.zip

Here is the shield I have made for it:

EAGLE.zip

Hi,

Can you post your schematic as .pdf, .jpg or something please
(can’t read Eagle files)

Yours,
TonyWilk

Hi,

thanks ...

Here is the scematic as pdf:

scematic.pdf

I have used the ds18b20 in a few projects - I really do not have a clue why it is making trouble now...

I have the sketch now running with deactivated sensor for a few hours and it runs stable - If I activate it, a hang up or restart comes for sure...

Thanks,

Andreas

All I can suggest is:

a. Add 0.1uF capacitor at the sensor end between Vcc and Gnd

b. Try running the examples from Arduino-Temperature-Control-Library e.g. 'single'

Yours,
TonyWilk

The wiring diagram is unintelligible.

Are you sure the DS18B20 is wired the right way round?
Does it get hot?
Is the 4K7 resistor really a 4k7?
How long, and what sort, is the cable?

As for the code, everybody else uses float, not double. I understand this is because double takes more time and more memory for no purpose, i.e. it is not properly supported. I don't think using double is the cause of your problem, but I note the dummy

 return 10;

is an int.

Post your complete code.

See if this helps:

// Temperatur vom Sensor auslesen.
double get_temp() {
  sensors.requestTemperatures();
  delay(800);
  double value = sensors.getTempCByIndex(0);
  //return 10;
  return value;
}

Good morning:

@ToniWilk:

a. Add 0.1uF capacitor at the sensor end between Vcc and Gnd

Have dont it already - does not solve the problem.

b. Try running the examples from Arduino-Temperature-Control-Library e.g. ‘single’

In my code, I have deactivated everything except the temperature part and the lcd part to show the temperature. It works - no hangups… So the problems must be something with the temperature part and the rest of the code… memory???

@Nick_Pyner:

Are you sure the DS18B20 is wired the right way round?

Yes - otherwise it would not deliver any data I thin… But it does…

Does it get hot?

No.

Is the 4K7 resistor really a 4k7?

Yes.

How long, and what sort, is the cable?

1 meter.

As for the code, everybody else uses float, not double. I understand this is because double takes more time and more memory for no purpose, i.e. it is not properly supported. I don’t think using double is the cause of your problem, but I note the dummy

Have changed it to float - still same issue with hangups…

@gvfavo:

I have, check the first post.

@outsider:

See if this helps:

have done so - does not help…


Slowly I think it meight be connected to some memory issue…

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

When you designed this, did the breadboard prototype do this?

If you unplug the SSRs does the problem occur?

Does the problem occur when a change in output state happens or when everything is stable and no state change is occuring?

Thanks.. Tom.. :slight_smile:

Last thing that might be worth a shot...

In your setup, call these:

sensors.setWaitForConversion( false ); //waitForConversion
sensors.setCheckForConversion( false ); //checkForConversion

They seem to clear the flags which make the library wait for stuff (maybe forever?)

You will then have to add a delay like:

sensors.requestTemperatures();
delay(100);

There might be some info here: Dallas Temperature Control Library - Miles Burton - Innovative engineering for pretty much anything
There is a note on that page about: "I recommend you use OneWire 2"

Yours,
TonyWilk

@TonyWilk: did not work...

I have even tried now with an arduino mega.... same things happen, either hang up or reboot after some time...

Next thing I am going to try is to get rid of all float / double and use int only...

Hi,
Simple test: If you disconnect the SSR from the Arduino, does the code run OK and show temperature OK for a long time?

If so, your problem is not anything in code, it is ElectroMagnetic Interference. This is a common problem when controlling power from Arduino.

Here are some suggestions on how to approach these problems:

http://arduino-info.wikispaces.com/Arduino-Project-Planning-Electrical

Also see this:

http://arduino-info.wikispaces.com/RelayIsolation

Let us know what you find out.

Andreas1984:
Next thing I am going to try is to get rid of all float / double and use int only…

No… there is no point.
In any case there is no difference between float and double on an Arduino UNO. they are different names for the same thing.

What may well make a LOT of difference is using String.

  • it is well known for eating memory and can eventually cause hangups… I didn’t spot it til now.

Change your hysteresis marker to be a single char ‘a’ instead of “a” like:

// Gibt auskunft über den momentanen Stand der Hysterese.
// a = unterhalb der Hysterese.
// b = innerhalb der Hysterese steigend.
// c = überhalb der Hysterese.
// d = innerhalb der Hysterese fallend.
char hysterese_marker = 'a';

and change:

// Logik für die Hysterese.
void hysteresis() {

 // Wenn die momentane Temperatur kleiner ist als die Hysterese.
 if (current_temperature < hysteresis_low) {
   general_heating_status = true;
   hysterese_marker = 'a';
 }

  ... and so on

Yours,
TonyWilk