Programming Help

Good Afternoon,

I need a little bit of help with a peice of code. The code works ok and almost does what I want.

The aim of the code below is to drive a digital output when the temperature is above the setpoint. This part works except it turns off before the second part of the code tells it to. See below.

if (tempTop > 45 && digitalRead(GasOn) == HIGH)
digitalWrite(HeatValve, HIGH);
else if (tempTop > 45 && tempRet > flow + hyst1)
digitalWrite(HeatValve, HIGH);
else if (tempTop < 43 || tempRet < flow - hyst2)
digitalWrite(HeatValve, LOW);

I want the HeatValve to stay until the low limit is reached, except it turns off really quickly. This is making the valve and pump open and start too frequently.

The rest of the code works fine looking at the GasOn Etc

Looking for a sloution.

Thanks

Richie

Without knowing the types of the variables in the snippet, or how anything is wired, all we can suggest is that some variable doesn't contain the value that you think it does, or that there is something wrong with your wiring.

Hi

Thanks for your thoughts there is nothing wrong with the wiring the valve and pump start as per the output from the relay fed from the Arduino. The problem is instead of looking at the lower limit and turning off it turns off when it drops below the start limit.

Rich

We need to see all of your code AND seeing some serial output would be useful. What do tempTop, tempRet, flow, hyst1, and hyst2 contain?

Here you go. The rest of the code works fine including the server

/*********************** Marque’s Arduino Controller Example /
/
for questions: marque.l@gmail.com **********************/
/

In the android app settingsscreen you can set up you IP and port.
For this example you need to call prefix 1 “B” and prefix 2 “C”.
*/
#include <Ethernet.h>
#include <HTTPClient.h>
#include <SPI.h>

int imm = 70;
int coil = 50;
int flow = 60;
int und = 65;
int mix = 57;
int hyst = 3;
int hyst1 =6;
int hyst2 =22;

float tempTop;
float tempMid;
float tempBot;
float tempFlow;
float tempRet;

int RecievedString;
int valueB;
int valueC;
String readString = String(20);

int tempPin5 = 5;
int tempPin1 = 1;
int tempPin2 = 2;
int tempPin3 = 3;
int tempPin4 = 4;

int NeutValve = 2; // Valve from neutralizer to Cylinder
int MPump = 3; // Mixer Pump
int MPumpA = 4;// Auto control Mixer
int HeatValve = 5; // Central Heating Main Pump
int ProgOn = 7; //Programmer Heating Demand
int GasOn = 6; // Gas boiler run output
int UndFlor = 8; // Underfloor heating run output
int FlorLiv = 9; // Underfloor Heating Living Room Output Over heat protection
int GasBoiler = 44; // Software boiler output only
int RainPump = 23;// Rain Water Pump
int WaterValve =5;// Fresh Water Valve to Top Tank
int Hotwater =25;// Hot water Demand
int hwaterV = 11;

byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(xx); // port to listen on
IPAddress ip(xxx,xxx,xxxx,xxx); // Ip for fixed IP Address

EthernetClient client;

char content_main_top = “”;
char S11 = “Boiler on” ;
char S12 = “Boiler off” ;
char S13 = “Mixer Pump on” ;
char S14 = “Mixer Pump off” ;
char S15 = “Heating Valve on”;
char S16 = “Heating Valve off”;
char S17 = “Turning Underfloor On”;
char S18 = “Turning Underfloor Off”;
char S19 = “Turning All On”;
char S20 = “”;
char S21 = “Manual Control”;
char S22 = “Manual Control”;
char S23 = “Rain Water Pump On”;
char S24 = “Rain Water Pump Off”;
char S25 = “Fresh Water Valve Open”;
char S26 = “Fresh Water Valve Closed”;
char S27 = “Auto Enabled”;
char S28 = “Manual Control”;
char S29 = "Water Valve Open ";
char S30 = “Water Valve Closed”;
char S31 = “Refresh”;
//char S404 = "Not Found ";

/************************** Setup **********************/
void setup()
{
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7,INPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(13,OUTPUT);
pinMode(24,OUTPUT);
pinMode(12,OUTPUT);

Serial.begin(9600);
Serial.println(“Getting IP…”);
//Ethernet.begin(mac);
Ethernet.begin(mac,ip);
Serial.print("My IP address: ");
Ethernet.localIP().printTo(Serial);
Serial.println();
Serial.print("Gateway IP address is ");
Ethernet.gatewayIP().printTo(Serial);
Serial.println();
Serial.print("DNS IP address is ");
Ethernet.dnsServerIP().printTo(Serial);
Serial.println();
}
void loop()
{

tempTop = analogRead(tempPin5); //read the value from the Cylinder Top sensor
tempTop = (5.0 * tempTop * 100.0)/1024.0; //convert the analog data to temperature
//Serial.print((byte)tempTop);
//Serial.println(" *C Top Temp");

tempBot = analogRead(tempPin2); //read the value from the sensor Cylinder Bottom
tempBot = (5.0 * tempBot * 100.0)/1024.0; //convert the analog data to temperature
//Serial.print((byte)tempBot);
//.println(" *C Temp Bot");

tempFlow = analogRead(tempPin3); //read the value from the sensor Neutraziler Flow Temp
tempFlow = (5.0 * tempFlow * 100.0)/1024.0; //convert the analog data to temperature
//Serial.print((byte)tempFlow);
//Serial.println(" *C Flow Temp");//send the data to the computer

tempRet = analogRead(tempPin4); //read the value from the sensor Return Temp
tempRet = (5.0 * tempRet * 100.0)/1024.0; //convert the analog data to temperature
//Serial.print((byte)tempRet);
//Serial.println(" *C Return Temp");//send the data to the computer

delay(2000);

//Over Temperature Protection

if (tempFlow > 90)
digitalWrite(HeatValve, HIGH);
digitalWrite(FlorLiv, HIGH);

if (tempFlow < 79)
digitalWrite(HeatValve, LOW);
digitalWrite(FlorLiv, LOW);

// Heating Circulating pump

// New controls

if (tempTop > 45 && digitalRead(GasOn) == HIGH)
digitalWrite(HeatValve, HIGH);
else if (tempTop > 45 && tempRet > flow + hyst1)
digitalWrite(HeatValve, HIGH);
else if (tempTop < 43 || tempRet < flow - hyst2)
digitalWrite(HeatValve, LOW);
if (tempTop < tempFlow && tempTop < 48)
digitalWrite(hwaterV, HIGH);
else if (tempTop > tempFlow || tempTop > 50)
digitalWrite(hwaterV, LOW);

// Programmer Input

if (digitalRead(ProgOn) == HIGH)
digitalWrite(GasOn, HIGH);
if (digitalRead(GasBoiler) == HIGH)
digitalWrite(GasOn, HIGH);
if (tempTop < 42)
digitalWrite(Hotwater, HIGH);
else if (tempTop > 45)
digitalWrite(Hotwater, LOW);
if (digitalRead(Hotwater) == HIGH)
digitalWrite(GasOn, HIGH);
else if (digitalRead(ProgOn) == LOW && digitalRead(GasBoiler) == LOW && digitalRead(Hotwater == LOW))
digitalWrite(GasOn, LOW);

// Cylinder Circulating Pump Control

if (tempTop > 55 && (tempTop - tempBot >= 7 ))

digitalWrite (MPumpA, HIGH);

else if (tempTop - tempBot <= 4 || tempTop < 50)

digitalWrite (MPumpA, LOW);

// Underfloor Heating Control
if (tempFlow > und + hyst && digitalRead(HeatValve) == HIGH || digitalRead(HeatValve) == HIGH && digitalRead(GasBoiler) == HIGH)
digitalWrite(UndFlor, HIGH);

if (tempFlow < und - hyst && digitalRead(HeatValve)== LOW)
digitalWrite (UndFlor, LOW);

// Neutralizer Valve Control
if (tempTop >(coil + hyst)) // Neutralizer to Cylinder Valve Close Temperature
digitalWrite(NeutValve, HIGH);

if (tempTop <(coil - hyst)) // Neutralizer to Cylinder Open Temperature
digitalWrite(NeutValve, LOW);

// Water Tank Level Control

//if (digitalRead(Control) == HIGH && digitalRead(LowTank20) == HIGH && digitalRead(HighTank30) == LOW)
//digitalWrite (RainPump, HIGH);

//if (digitalRead(Control) == HIGH && digitalRead(LowTank30) == LOW || digitalRead(HighTank90) == HIGH)
//digitalWrite (RainPump, LOW);

//if (digitalRead(Control) == HIGH && digitalRead(LowTank30) == LOW && digitalRead(HighTank40) == LOW)
//digitalWrite (WaterValve, HIGH);

//if (digitalRead(Control) == HIGH && digitalRead(HighTank60) == HIGH)
//digitalWrite (WaterValve, LOW);

// Water Tank Level Control

//if (digitalRead(Control) == HIGH && digitalRead(LowTank20) == HIGH && digitalRead(HighTank30) == LOW)
//digitalWrite (RainPump, HIGH);

//if (digitalRead(Control) == HIGH && digitalRead(LowTank30) == LOW || digitalRead(HighTank90) == HIGH)
//digitalWrite (RainPump, LOW);

//if (digitalRead(Control) == HIGH && digitalRead(LowTank30) == LOW && digitalRead(HighTank40) == LOW)
//digitalWrite (WaterValve, HIGH);

//if (digitalRead(Control) == HIGH && digitalRead(HighTank60) == HIGH)
//digitalWrite (WaterValve, LOW);

checkclient();
}

If it turns off before the temperature gets to 43, then tempRet < flow-hyst2.

Does LOW turn the valve on or off?

Please read Nick Gammon’s two posts at the top of the Forum for proper posting of source code using code tags ("</>"). It makes it easier for us to read.

int RecievedString;

So, now I’m going to look for

String ReceivedInt;

Don’t use types in names when the type doesn’t match that used in the name.

//Over Temperature Protection

if (tempFlow > 90)
digitalWrite(HeatValve, HIGH);
digitalWrite(FlorLiv, HIGH);

if (tempFlow < 79)
digitalWrite(HeatValve, LOW);
digitalWrite(FlorLiv, LOW);

How does unconditionally toggling the FlorLiv pin prevent over-temperature?

Some Serial.print() statements to confirm what is happening would be useful, along with a lot of curly braces.

Can I suggest that you always put the statements to be conditionally executed in braces. I know that is not strictly necessary when only one statement is involved but it makes the code much easier to read, particularly if you use Ctrl/T to format it and put each { and } on its own line. It also prevents up the problem highlighted by Paul.

Whenever there are problems with if/else not doing what is expected it is helpful to print the values being tested but label them so that you know what you are seeing.

Hi

Thanks for the responses, unfortunately I could fit all the code in the post, there are serial writes further down the code.

The FlorLiv pin drives a third valve which drives the underfloor heating to on. It basically controls a heating circuit with to heat sources GasOn - Gas Boiler. And a wood burner.

The HeatValve is turning off as soon as it drops below the high out put value 60.

Low writes the out put off and closes the valve.

I can't see why the HeatValve does latch on until the low value is reached

Rich

|500x336

From