how to work with the temperature from Ds18B20

I have successfully hacked together datalogger using the Adafruit shield. Firstly with the LM36 but then with 2 / DS18b20 physically adding the ID code for each ds. Works well enough.

But now I am trying to chop the code to use as a thermostat but am having difficulty assigning the output temp to a varriable which I can then do if else statements on.
The lines :-
sensors.requestTemperatures();
printTemperature(Ds18b20Thermometer);

print it to the serial for display and #logfile works for the data logger but
if I try
int temp1 = (Ds18b20Thermometer)

I get the conversion error " invalid conversion from 'uint8_t*' to 'int' "
From reading the forum I understand that (ds18b20thermometer) must be a big number? of a long string or something like that that can not squeeze into a number. (something about big bytes and little bytes)

Question is therefore is there a simple way of getting the temp a a number (float or int) out of (ds18b20thermometer) so that I can easily compare that temp to theshold temps for a simple thermostat project.

Sorry I have never posted to any forum so I am not aware of protocol so I don't mean any offense by my include language or omissions.
Any help would be appreciated.
Thank you

I'm new to programming with Arduino, but I have written something very similar to what you are trying to accomplish.

I have declarations for all the devices I am using, and then use this code:

    sensors.requestTemperatures();
    float tempF = sensors.getTempC(WaterThermometer) * 1.8 + 32;

if (tempF > LIGHT_TEMP_UPPER && digitalRead(LightFanPin) == LOW)  {
      NeedAttention = true;
      Serial.print(" FAN TURNED ON!");
      digitalWrite(LightFanPin, HIGH); //Turn on fan
    }
    if (tempF <= LIGHT_TEMP_LOWER && digitalRead(LightFanPin) == HIGH) {
      Serial.print(" FAN TURNED OFF!");
      digitalWrite(LightFanPin, LOW); //Turn off the fan
    }

I use this to monitor the temperature of my aquarium light fixture and turn on a fan if above the LIGHT_TEMP_UPPER variable. Not sure if this is the "correct" way to do it, but it works just fine for me. The serial.print is used for debugging so I can see what's going on, I'm not actually logging it to anywhere.

Hope this helps ya out.

I am at same place here is my sketch its to control a heat transfer fan. When the wood burner is on the "flue" temp should be higher then the temp immediately down stream of the "fan" So turn on fan. Trouble is I keep burning out fan if flue temp is over 60 C so if "fan sensor approaches 60 turn off fan until "fan" temp is safe.
The starting point code is

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Arduino.h"

// Data wire is plugged into pin 5 on the Arduino
#define ONE_WIRE_BUS 5

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);


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

DeviceAddress flueThermometer = { 0x28, 0xAD, 0x7F, 0x3A, 0x03, 0x00, 0x00, 0xBD };
DeviceAddress fanThermometer = { 0x28, 0x2C, 0x41, 0x3A, 0x03, 0x00, 0x00, 0x46 };


void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(flueThermometer, 10);
  sensors.setResolution(fanThermometer, 10);
 
 int fluetemp = 0;
 int fantemp = 0;
 
 
 
 }

void printTemperature(DeviceAddress deviceAddress)
{ float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
 
}

void loop(void)
{ 
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("Inside temperature is: ");
 printTemperature(flueThermometer);
  Serial.print("\n\r");
 // int fluetemp = 
}

I had a Brain wave while searching for a solution to the unst_8 conversion problem
Its nice that you can have several sensors on the same pin BUT Can I have sensors on 2 pins
How to I apply the above code to separate pins
#define ONE_WIRE_BUS 5
#define TWO_WIRE_BUS 6
didn't follow though in the sketch.

Any ideas? is this the way I should be going ?
Thanks for reading.

I'm confused what you are asking now. What do you mean

I keep burning out fan if flue temp is over 60 C

Not familiar with Celsius, but that's about 140F, is your fan rated for that temperature? It's not extremely high, but something to check. Also, if the fans burn out at 60C, when do they turn on. If they turn on at, let's say, 40C, maybe your problem is that the fans aren't able to move enough to sufficiently cool the flue. Try larger fans or turning them on at a lower temp.

If you want the fan to turn off at at a set temperature you can still use your flue sensor, so you can still just use the 2 sensors you already have. Basically, If fluetemp >= flueupper && fluetemp < 60 then turn on the fan. If fluetemp <= fluelower then turn off the fan.

I don't see why you couldn't use separate pins for multiple sensors. They weren't really designed to be used that way though and I'm not sure if the libraries would work that way. In order to try, you'd define your pins (as you did) and then you'd have to "double" you onewire and dallastemp

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
OneWire twoWire(TWO_WIRE_BUS);

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

The only reason I don't think this would work would be the OneWire twoWire statement, but I don't really know for sure and I don't want to hook it all up to test right now. I'd recommend just using the one pin and running the first pin then running the second pin from that one, they don't have to be home runs to one location, that's what is nice about using these sensors.

void loop(void)
{ 
  delay(2000);

Why are you waiting?

void printTemperature(DeviceAddress deviceAddress)
{ float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
}

You really should split this function into two parts - one to get the temperature and one to print the temperature. When you do that, you'll see that printing the temperature is the trivial part of what this function does. The "complicated" part is getting the temperature into a variable. Which is the part that you said initially that you were having trouble with.

if I try
int temp1 = (Ds18b20Thermometer)

I get the conversion error " invalid conversion from 'uint8_t*' to 'int' "

Of course you do. The value in the parentheses is the address if the thermometer, not the temperature returned by that thermometer.

so the question is How to I get the value it returns for each sensor.

void printTemperature(DeviceAddress deviceAddress)
{ float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
}

I know that part returns the temp but with the multiple sensors each time it runs through the loop it prints tempC for one sensor after another.
I would like to return the value for each separatly. I can do it with the

void loop(void)
{ 
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("Inside temperature is: ");
 printTemperature(flueThermometer);
  Serial.print("\n\r");

But is there an alternative command to the print Temperature(*****Thermometer) on the returns the value like you say intead of print that returns the value.

Or just thought of this can you read it from the serial port where you have just displayed it.

Thanks Rayman I think you are right that it is the onewire library which does not support multiple pins but I do remember reading a post which talked on large numbers of sensors groupinb them in groups of 8 to 10 sensors on "each" pin which would suggest that more than one pin could be used. (forgot where I read it you know how it it when you trawl through ).
As for changing the heat transfer fan I live in rural NZ I don't have access to a range thats the one I can get, thats the one I have to use. Unless I direct import from England big bucks. I have to solve things in a different way.

Not 100% what you're after, but if I understand correctly you want to just get the temperature from the sensor and NOT have to print it, correct? If so, you can write your printTemperature function to return the value, but I'd just get rid of the function entirely. Try this in your loop

void loop(void)
{ 
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  float FlueTemperature = sensors.getTempC(flueThermometer);
  float FanTemperature = sensors.getTempC(fanThermometer);

  Serial.print("Flue temperature is:  ");
  Serial.println(FlueTemperature);
  Serial.println();
  Serial.print("Fan temperature is:  ");
  Serial.println(FanTemperature);

This will put the temperature in their own variables that you can do whatever you wish with. This example will simply print them still. I don't think this would be the best way to do this though, but I think this is what you were asking.

Oh, btw, I typed some of that code by hand so double check the capitalization, spelling, etc.

Hey Rayman well done that does it.

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Arduino.h"

// Data wire is plugged into pin 5 on the Arduino
#define ONE_WIRE_BUS 5

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

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

DeviceAddress flueThermometer = { 0x28, 0x99, 0xE6, 0x39, 0x03, 0x00, 0x00, 0x40 };
DeviceAddress fanThermometer = { 0x28, 0x45, 0x7B, 0x3A, 0x03, 0x00, 0x00, 0x2A };


void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(flueThermometer, 10);
  sensors.setResolution(fanThermometer, 10);
 
 //float fluetemp = 0;
 //float fantemp = 0;
 
 
 
 }

void printTemperature(DeviceAddress deviceAddress)
{ float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
 
}

void loop(void)
{ 
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
 float fluetemp = sensors.getTempC(flueThermometer);
 float fantemp = sensors.getTempC(fanThermometer);

   Serial.print("Flue temperature is: ");
 printTemperature(flueThermometer);
  Serial.print("\n\r");
  Serial.print("Fan temperature is: ");
 printTemperature(fanThermometer);
   Serial.print("\n\r");
   Serial.print("Fantemp is: ");
  Serial.print("\n\r");
  Serial.print(fantemp+10);
  Serial.print("\n\r");
   Serial.print("Fluetemp is: ");
  Serial.print("\n\r");
  Serial.print(fluetemp-10);
 
}

I added your bit and just added the extra print variable + - to make sure and it has the value.
So I can now call out and do the if else stuff.

Thank you