Go Down

### Topic: Temperature Probe DS18B20 (Read 1 time)previous topic - next topic

#### Dustyboy007

##### Jul 21, 2013, 10:44 pm
Good Afternoon,

I have a DS18B20 temp probe that ill be using to control fans for my fish tank. I have the code figured out for reading the temp from the probe but im not sure how to use the temp information to set thresholds to turn the fans on and off. Any information is helpful. Thanks !!

#### UKHeliBob

#1
##### Jul 21, 2013, 10:54 pm
Code: [Select]
`if (temperature > highThreshold){   digitalOutput(fanPin, HIGH);   //turn on the fan}else if (temperature < lowThreshold){   digitalOutput(fanPin, LOW);   //turn off the fan}`
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

#### Dustyboy007

#2
##### Jul 21, 2013, 10:58 pm
thanks for the quick response. while your at it do you know how i can convert from C to F? Thanks again

#### robtillaart

#3
##### Jul 21, 2013, 11:07 pm
float F = C * 1.8 + 32;
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### ingvartage

#4
##### Jul 22, 2013, 01:04 am
take a look at this sketch

#### jerseyguy1996

#5
##### Jul 22, 2013, 02:09 am
Make sure you incorporate some hysteresis in the sketch or else the fans will be cycling on and off very rapidly.
Arduino Uno;
Mega328

#### Dustyboy007

#6
##### Jul 22, 2013, 03:07 am
thank you for all the great responses. I still am having trouble being able to do a digital read for the temperature reading in the code so that i can turn around and use it for the fan proton. In the DS18B20 code the "digitalWrite" is for the "Whole" and "Frac". For reference i pulled the DS18B20 code off of the arduino website. Thanks for all the help.

#### Nick_Pyner

#7
##### Jul 22, 2013, 05:01 am
I don't know why you need digitalwrite, and this sounds like it is getting a lot more complicated than it needs to be. I imagine you only need the whole number anyway, and keeping to that should solve any hysteresis issues.

While I don't think you have a problem, if you really do, it may simply be caused by inappropriate code and/or bad choice of libraries (if any).

You should be able to use commands like

GetTemp(Temp) (which returns a number like 27.27)
Serial.print(Temp) and/.or lcd.print(Temp) (enabling you to see the result, 27.27)
If Temp too high, turn fan on (enabling you to do something)

You can do this using the proper Dallas temperature one-wire libraries. I believe this is worth doing, even if you are only using one sensor, as it requires less code from you.