I finely made it
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);
}