More if statements ?

Hi everyone.
I have not been programming for so long time, but i have gotten a few programs to work.
Now i have a programming problem i would love to help solving.

I have a heating system in my house that is a little special.
I have some solarpanels directly connected to a few 24 volts heating elements in my water heater, that also have 2 copper coils in it.
I have made a new tank (solartank) that i will use more solarpanels into.
I have an air to water heatpump ,and
I also have a pellets burner (just in case)
The problem i have is that i want to connect these in, in a way that i can use the least electrisity from the grid.
The temp sensors is Dallas18B20 connected into 3,3 volt on pin 7 with oneWire.
The motorized valves is 12 volt controlled thru a small relay onto the different pins (shows in picture)
Sorry that some of the drawing writing is in swedish :frowning:
So the connection should be

1: Water heater
2: Solartank
3: Air to water heatpump (LVVP)
4: Pellets burner.

If the heatpump don’t run, i have another circulation pump as the picture shows.

some of the code i already have written and have a problem with is to understand how to make them start in the order i want is

float currentTemp7;//Temp to heaters
currentTemp7 = sensors.getTempCByIndex(7);
float currentTemp5;//Solartank 1
currentTemp5 = sensors.getTempCByIndex(5);
if(currentTemp7 < 45)
{
 digitalWrite(rele4Pin, HIGH);//Open LVVP
 digitalWrite(rele47Pin, HIGH);//Open V7
}
else 
{
  if(currentTemp5 > 60);
}
{
  digitalWrite(rele45Pin, HIGH);//Open V5
  digitalWrite(rele9Pin, HIGH);//Start circulation pump
  digitalWrite(rele44Pin, HIGH);//Open V4
  digitalWrite(rele42Pin, HIGH);//Open V2
}
float currentTemp0;//Pellets burner
currentTemp0 = sensors.getTempCByIndex(0);
if(currentTemp7 < 40)digitalWrite(rele5Pin, HIGH);//Start Burner
if(currentTemp7 > 55)digitalWrite(rele5Pin, LOW);//Close burner

float currentTemp1;//Return water temp
currentTemp1 = sensors.getTempCByIndex(1);

float currentTemp2;//Waterheater
currentTemp2 = sensors.getTempCByIndex(2);
//Water heater shows 23 degrees less
if(currentTemp2 > 52)//VH more than 75 degree
{
  digitalWrite(rele43Pin, HIGH);//Open V3
  digitalWrite(rele44Pin, LOW);//Close V4
  digitalWrite(rele42Pin, HIGH);//Open V2
  digitalWrite(rele9Pin, HIGH);//Open circulation pump
  digitalWrite(rele46Pin, HIGH);//Open V6
  }
else
{
  if(currentTemp2 < 47);//VH less than 70 degree
}
{
  digitalWrite(rele43Pin, LOW);//Close V3
  digitalWrite(rele44Pin, HIGH);//Open V4
   }
if(currentTemp2 < 69) digitalWrite(rele6Pin, LOW);//Solarheat off @ 92 degree

So how is it possible to write more IF statements to make this work better… ?
Would apreciate all the help i can get right now.

Raptor50-73:
how to make them start in the order i want is

And what order is that?

In general you should have a variable that keeps track of the state of the system. When one step is completed it should change the variable to the value for the next step. For example if a window is to be closed before a heater is turned on you might have something like this

if (roomState == 'C') { // C means window is closed
  roomState = 'H';
}

and then the heater function would check like this

if (roomState == 'H') {
  // heater stuff
}

...R

float currentTemp7;//Temp to heaters
currentTemp7 = sensors.getTempCByIndex(7);

It is not necessary to use two lines of code to read the temperature.

float currentTemp7 = sensors.getTempCByIndex(7);

It IS necessary to use better names than that.

And if you start numbering variables it’s time for arrays :wink:

So to answer Robin first, :slight_smile:
I do have a room temperature set to 23 degrees (onewire), from before when i had the circulation pump connected to the pellets burner. Now it is not in use more than to keep a track of the room temperature.
I will paste the whole program so you can see.
It contains more stuff than the heating, like connecting solarpanels on the roof of the garage when needed, that is not in the picture i added before, and not yet connected properly, and nothing i acctually are about to ask about now. :slight_smile:

Here is the complete program .

Or not… I got an error message that says :
The message has the following error or errors that must be corrected before continuing:
The message exceeds the maximum allowed length (9000 characters).

So i added the program in a file then. :slight_smile:

I have rewritten the currentTemp lines, and it still compiles ok, so thanx to PaulS. :slight_smile:
I have tried to get them to read the hexvalues of every Dallas sensor and implemented that into the program before, but i haen’t managed to fix that. So every time i change a sensor, i have to rename them in the program, kind of annoying, but ok, one thing at the time. :slight_smile:

I still have to look into the Array thing “Septillion” is talking about, i have not a clue yet how that is done, so i will do a little check on that now, maybe thats a better solution than IF statements…
Thanx so far guys…

Varmestyrning-051017-med-ventiler.ino (11.5 KB)

Instead of

int currentTemp1;
int currentTemp2;
int currentTemp3;
//etc
int currentTemp9; //aka 9 items

simply do

int currentTemps[9]; //9 items
//and use them like
currentTemps[5] = 35; //set item 6

Note, like all computer counting, it starts counting at 0. So in this case, currentTemps[9] is NOT valid. You have 9 entries numbered 0 through 8.