Hello,
I'm a beginner in Arduino, I took a code from the internet and tried to adapt it to my needs. The code :
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
//These first three variables are where the adjustments are made.
//set maximum tank temperature in C
int tankmax = 65;
//set how much higher collector temperature should be, in C, before turning on pump
int diff = 8;
//Turn off pump whan temp is within this many degrees of the collector
float werethere = 2;
//set up pins for lcd display
LiquidCrystal lcd (5, 6, 7, 8, 9, 10);
// Set input pin for onewire bus
#define ONE_WIRE_BUS 2
// 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);
//The thermometers are identified by their unique identifier
byte tanktopThermometer[8] = {0x28, 0x4F, 0xB2, 0x46, 0x92, 0x10, 0x02, 0x5D};
byte collectorThermometer[8] = {0x28, 0xAE, 0xEB, 0x46, 0x92, 0x11, 0x02, 0xE1};
static bool pumpOff=false;
//set pin for pump relay
int pump = 3;
//set pin for led pump indicator
int pumpLed = 4;
int pumpstate;
void setup ()
{
//start serial port
Serial.begin(9600);
Serial.println ("Solar hot water Differential Controller");
// Start up the onewire library
sensors.begin();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// set the sensor resolution from 9 to 12 bit
sensors.setResolution(tanktopThermometer, 9);
sensors.setResolution(collectorThermometer, 9);
//initialize lcd
lcd.begin(16,2);
lcd.setCursor (0,0);
lcd.print ("CL");
lcd.setCursor (0,1);
lcd.print ("TT");
//set pins to output
pinMode (pump, OUTPUT);
pinMode (pumpLed, OUTPUT);
digitalWrite (pump,HIGH);
}
//functions that reads temp from sensors and returns as floating point value.
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
return tempC;
}
void loop ()
{
//get all sensor values
sensors.requestTemperatures();
//set variables
float tank = (sensorValue(tanktopThermometer));
float collector = (sensorValue(collectorThermometer));
//prints temperature values to serial port and lcd
Serial.print ("tank ");
Serial.println (tank);
Serial.print ("collector ");
Serial.println (collector);
lcd.setCursor (2,0);
lcd.print (collector);
lcd.setCursor (2,1);
lcd.print (tank);
Serial.print ("pump state ");
Serial.println (pumpstate);
Serial.println ("");
/turns on pump when collector is (diff) degrees above tank.
and tank is below (tankmax) temperature.
once pump turns on, pumpstate variable turns to "1" and causes pump to remain
on as long as collector temp is higher than tank temp.
If max tank temp is reached, pump always turns off./
static bool pumpOn=false;
if ( pumpOn)
{
if (((collector - werethere) < tank ) || (tank >= tankmax) )
{
digitalWrite (pump, LOW);
digitalWrite (pumpLed, LOW);
pumpOn =false;
}
}
else
{
if (((collector - diff) > tank ) && ( tank < tankmax ) )
{
digitalWrite (pump, HIGH);
digitalWrite (pumpLed, HIGH);
pumpOn = true;
}
}
delay(1000);
}
-
One of the sensors displays 4 decimals instead of 2 on the LCD, after the pump LED lights up and sometimes it also displays negative temperatures like -170 degrees which appear in "serial monitor". In the "serial monitor" temperatures appear with only 2 decimal places.
-
I would like to show the status of the pump on the LCD when it is on or off.
I do not know how to upload LCD photos because it seems that the files are too large