DallasTemperature, Farenheit to Celsius?

I finely made it :smiley: I got it to work. Only one problem remains. How do i convert Farenhit in to Celcius so the display shows the different temperature in Celsius?
Can someone help me with that code ?

Thanks

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1

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

 #define ONE_WIRE_BUS 2  //----DS18B20 definitions (temperature sensors)

 #define pumpPin 8     //Named for clarity.  Pump signal output at digital pin 3 (see setup)

 LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
 
 OneWire oneWire(ONE_WIRE_BUS); //Refer oneWire to Bus for DS18B20 sensor communication

 DallasTemperature sensors(&oneWire);

//---Variables

  int tankLimit = 180;  //set tank overtemp protection
  int startDT = 10;     //set differential temperature to start pump
  int stopDT = 3;       //set differential temperature to stop pump

void setup(void)
{
  pinMode(8, OUTPUT);
  sensors.begin(); //start up the sensors

  lcd.init();                      // initialize the lcd 
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  digitalWrite(pumpPin, HIGH); //starts with pump off (HIGH = relay off)
  lcd.setCursor(9,0);
  lcd.print("Pmp:Off"); //Initial until pump loop changes state
}


void loop(void)
{
  sensors.requestTemperatures(); //get current values from sensors
  float tankT = sensors.getTempFByIndex(0);  
  float collT = sensors.getTempFByIndex(1); 

//display System Status on LCD.  Pump status prints under pump control loop below.
  lcd.home ();             
  lcd.print("Tank:");
  lcd.print(round(tankT));  
  lcd.print("C ");          //"F_" eliminates bug that would display "FF" sometimes.
  lcd.setCursor(0,1);       
  lcd.print("Collector:");
  lcd.print(round(collT));  
  lcd.print("C "); 


//Pump control loop
/*This loop uses three scenarios to control the pump, always with a qualifier that tank limit temp is not exceeded.
 * 1) dT higher than startDT  (turn on pump)
 * 2) dT between stopDT and start dT (keep pump in current state)
 * 3) dT below stopDT (turn off pump)
 */

    if (  ( (collT - startDT) > tankT ) && ( tankT < tankLimit ) ) //if the measured dT is bigger than startDT, turn on the pump
    {
          digitalWrite (pumpPin, LOW); //LOW signal turns relay on
          lcd.setCursor(9,0);          //go to pump status line on LCD
          lcd.print("Pmp:On ");        //extra space clears "f" from "off" state.
    }
    else 
    {
        if ( ( (collT - stopDT) >= tankT) && (tankT < tankLimit) ) //if the dT is between stopDT and startDT, don't change anything
            {
            //do nothing (keep current pump state)
            }
            else
            {
              digitalWrite (pumpPin, HIGH); //turn the pump off (HIGH signal is off)
              lcd.setCursor(9,0);  //go to pump status line on LCD
              lcd.print("Pmp:Off");
             }           
    }
  
  delay(1000);  
}

float tankT = sensors.getTempCByIndex(0);
float collT = sensors.getTempCByIndex(1);

Thanks so you so much. Works perfectly :ok_hand:

Even without that function, you'd think someone with the forum name @solarheat would know that degC = (degF - 32) * 5 / 9.

gfvalvo, did i ask for a converting formula ?

"I finely made it :smiley: I got it to work. Only one problem remains. How do i convert Farenhit in to Celcius so the display shows the different temperature in Celsius?
Can someone help me with that code ?"

Thanks

Once you know the formula, it's a fairly trivial task to write it in code:

  float tankFarenheitT = sensors.getTempFByIndex(0);
  float tankCelciusT = 5.0 * (tankFarenheitT - 32) / 9.0;

FYI:
The 18B20 outputs it's temperature in units of ΒΊC. The getTempFByIndex() function just converts the Centigrade output to Fahrenheit

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.