Temperature differential pump control

So, I am an extreme novice with programming and also new to Arduino. That being said, I am using an uno with a data logger shield as to take temperature data from a solar thermal collector the fluid streams on either side of the heat exchanger to determine the energy harvested from the collector to my aquaponics pond water.

I have the data logging figured out after adapting code from:

Now I need to use those same Dallas temp probes to control the pump for the solar collector. The idea would be to make the Uno read temp from Probe X and subtract from temp from Probe Y and if the difference is great enough then the digital pin controlling the motor relay would turn on, and if not would turn off. However, I am not sure how to write the code to do this.

Here is my code:

#include <SD.h>

#include <RTClib.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <SD.h>
RTC_PCF8523 RTC;

const int chipSelect = 10;
#define ONE_WIRE_BUS_PIN 2         // The pin that we are using
OneWire oneWire(ONE_WIRE_BUS_PIN);  // Setup oneWire
DallasTemperature sensors(&oneWire);//  oneWire to Dallas Temperature.

DeviceAddress Probe01 = {0x28, 0x9F, 0xC2, 0x79, 0x97, 0x06, 0x03, 0x0B};
DeviceAddress Probe02 = {0x28, 0x08, 0x95, 0x79, 0x97, 0x06, 0x03, 0xFB};
DeviceAddress Probe03 = {0x28, 0xFF, 0x4E, 0x2F, 0xB1, 0x17, 0x01, 0x22};
DeviceAddress Probe04 = {0x28, 0xFF, 0x24, 0x3C, 0xC1, 0x17, 0x01, 0xD1};
DeviceAddress Probe05 = {0x28, 0xFF, 0x34, 0x39, 0xC1, 0x17, 0x01, 0x2C};
DeviceAddress Probe06 = {0x28, 0xFF, 0xE9, 0x5E, 0xC1, 0x17, 0x01, 0x88};






void setup() {
  Wire.begin();
  // put your setup code here, to run once:
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
RTC.begin();

  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
}

void loop() {
  Serial.begin(9600);            //Must match with the serial monitor
Wire.begin();
RTC.begin();
sensors.begin();               // Initialize the Temperature measurement library
  
  // set the resolution to 9 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 9);
  sensors.setResolution(Probe02, 9);

Serial.print(" Date/Time        Temp1    Temp2");    //Print headers
Serial.println();
}

DateTime now = RTC.now();        // Clock call

//-------------Once we have called the clock ,we compare min and sec and print every 10 minutes---------


if(now.minute()==00 && now.second()==00){          
 
now = RTC.now();                 // Print date and time

Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);

 // Command all devices on bus to read temperature  
  sensors.requestTemperatures(); 
   
  Serial.print(" ");              //Print temp
  printTemperature(Probe01);
  Serial.print(" ");

  Serial.print(" ");
  printTemperature(Probe02);
  Serial.println();

  Serial.print(" ");
  printTemperature(Probe03);
  Serial.println();
  
  Serial.print(" ");
  printTemperature(Probe04);
  Serial.println();

   Serial.print(" ");
  printTemperature(Probe05);
  Serial.println();
  
  Serial.print(" ");
  printTemperature(Probe06);
  Serial.println();
}

  
}
delay(1000);                        //One data per second
}


void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

 
   Serial.print(tempC);
   Serial.print(" C");
   
   
}

}

Thank you.

controls.ino (8.14 KB)

If the fluid is not moving through the heat exchanger, will the temperature differential not be near zero? Can you post a diagram of your system?

Hello dapperdabber,

Welcome to the forum. Please read ‘How to use this forum - please read’, posted at the top of this and every forum on here, in particular the bit about posting your code.

Now I need to use those same Dallas temp probes to control the pump for the solar collector. The idea would be to make the Uno read temp from Probe X and subtract from temp from Probe Y and if the difference is great enough then the digital pin controlling the motor relay would turn on, and if not would turn off. However, I am not sure how to write the code to do this.

I’ve not read your code, however, I suggest something along these lines:

float temperature_X;
float temperature_Y;
#define temperature_differential 5   //This is the minimum temperature differential you want, change to suit what you need
#define Hysteresis 1                 //This is so the on and off points are not exactly the same, otherwise the pump could end up being switched on and off every second or two

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  read_temp_probes();
  pump_control(temperature_X, temperature_Y);
}

void read_temp_probes() {
  //Some code that reads the probes and updates the values of temperature_X and temperature_Y;
}

void pump_control(float X, float Y) {
  if ((Y + Hysteresis) - X > temperature_differential) {
    //Whatever you need to do to turn the pump on;
  }
  else if (Y - X < temperature_differential) {
    //Whatever you need to do to turn the pump off;
  }
}

JCA79B:
If the fluid is not moving through the heat exchanger, will the temperature differential not be near zero? Can you post a diagram of your system?

You are correct. Ideally it would be temperature differential from the entrance of the collector to the exit of the collector, but the logistics of probe cord length and other things make that less likely. I may need to trigger the pump on for a minute or two, and then query the probes and if there is no differential to just turn the pump off.

I am out and about, but I can post a simple diagram later.

Place a single probe in the middle of your heat collector, then you know how warm that water has got without flow.
If warm enough, start running the pump. The temperature will drop (cold water flowing in), if dropping too much (not enough heat collected) switch off the pump again.

I have updated the OP to include the code the proper way.

Below is a simple drawn diagram of my project. There are probe wells on either side of the heat exchanger that the dallas probes slide in and allow me to take the temp of the fluid in that stream. Using heat transfer equations and the data collected I will determine the energy extracted from the system. and its efficiency.

perry is correct:
please put the readings in an array like

temp[1] = sensors.getTempC(deviceAddress);

etc
you will have to sort them using the number you get from the sensors.
the do perrys trick.
also note you have to know what the outlet is on the panel, and the lowest in the heatexchanger.