Hi.
I just started learning about Arduino and programming.
This is my first version and before I will go much more further i hope fore some feedback and guidance.
Is this a good way to control this fermenter tank?
/********************************************************
* This is a code worked from PID RelayOutput Example, This version control cooling and heating on one tank.
* Same as basic example, except that this time, the output
* This version control cooling and heating on one tank.
* 1th. goal is to PID control 2 pcs (125liter) fermenters with glycerol jacked (relay to pump and heating element in lower part) and 1 chiller tank for glycerol
* 2th. gold is to make a Temperature profile (example: 2 days with 19,5°C 4 days with 21°C 6 days with 19°C)
* 3th. gold is to make a Temperature logger over network with Raspberry PI B+
* 4th. gold is to add display to monitor the temperatures. Automatic cycle showing set and act temperature.
* 5th. gold is to Set temperature profile and chiller temp from encoder switch
********************************************************/
#include <PID_v1.h>
#define RelayPin1 5
#define RelayPin2 6
double Setpoint1, Setpoint2, Setpoint3, Hysteresis, Input1, HeatingOutputValue1, CoolingOutputValue1;
//Specify the links and initial tuning parameters
PID HeatingPID1(&Input1, &HeatingOutputValue1, &Setpoint1,2,5,1, DIRECT);
PID CoolingPID1(&Input1, &CoolingOutputValue1, &Setpoint1,2,5,1, REVERSE);
int WindowSize1 = 5000; //Heating cycle time
int WindowSize2 = 5000; //Cooling cycle time
unsigned long windowStartTime1;
unsigned long windowStartTime2;
void setup()
{
windowStartTime1 = millis();
windowStartTime2 = millis();
//initialize the variables we're linked to
Setpoint1 = 20 ; //Fermenter no. 1 Set value
Setpoint2 = 20 ; //Fermenter no. 2 Set value
Setpoint3 = -7 ; //Chiller temperature
Hysteresis = 2/2 ;
//tell the PID to range between 0 and the full window size
HeatingPID1.SetOutputLimits(0, WindowSize1);
CoolingPID1.SetOutputLimits(0, WindowSize2);
//turn the PID on
HeatingPID1.SetMode(AUTOMATIC);
CoolingPID1.SetMode(AUTOMATIC);
Serial.begin(9600);
}
void loop()
{
Input1 = analogRead(0); //Temperatur sensor Fermenter no. 1
//Tells the PID's zero its value and not work against each other?
if (Input1 < Setpoint1-Hysteresis) HeatingPID1.Compute();
if (Input1 < Setpoint1+Hysteresis) CoolingOutputValue1 = 0;
if (Input1 > Setpoint1+Hysteresis) CoolingPID1.Compute();
if (Input1 > Setpoint1-Hysteresis) HeatingOutputValue1 = 0;
/************************************************
* turn the output pin on/off based on pid output
************************************************/
if(millis() - windowStartTime1>WindowSize1)
{ //time to shift the Relay Window
windowStartTime1 += WindowSize1;
}
if(HeatingOutputValue1 < millis() - windowStartTime1) digitalWrite(RelayPin1,HIGH);
else digitalWrite(RelayPin1,LOW);
if(millis() - windowStartTime2>WindowSize2)
{ //time to shift the Relay Window
windowStartTime2 += WindowSize2;
}
if(CoolingOutputValue1 < millis() - windowStartTime2) digitalWrite(RelayPin2,HIGH);
else digitalWrite(RelayPin2,LOW);
Serial.print("Setpoint1:");
Serial.print(Setpoint1);
Serial.print("Input1:");
Serial.print(Input1);
Serial.print("HeatingOutputValue1:");
Serial.print(HeatingOutputValue1);
Serial.print("CoolingOutputValue1:");
Serial.println(CoolingOutputValue1);
}
Best Regards
BeerPal