Advice for simplification

Hi all, just wanted some feedback on this piece of code, i am trying to controll some heatpads, and the moment any of them drop below a certian temperature, i want them all to activate, i tinkered some with if or statements, but i couldnt get it to function the way i wanted. ill show you my attempt, and my solution, if you know how to make it simpler, let me know!

Attempt:

if ((Tc1>30)||(Tc2>30)||(Tc3>30)) {
  digitalWrite(Heatpads, LOW);
  Serial.println("Heatpads are now off!");
}
else {
  digitalWrite(Heatpads, HIGH);
  Serial.println("Heatpads are now on!");
}
  delay(2000);

solution:

if (Tc1<30){
  digitalWrite(Heatpads,HIGH);
  Serial.print("Sensor 1 to low, heatpads on!");
}
else if (Tc2<30){
  digitalWrite(Heatpads,HIGH);
  Serial.print("Sensor 2 to low, heatpads on!");
}
else if(Tc3<30){
  digitalWrite(Heatpads,HIGH);
  Serial.print("Sensor 3 to low, heatpads on!");
}
else{
  digitalWrite(Heatpads,LOW);
  Serial.println("Temps are ok, heatpads are off!");
}
delay(5000);
if ((Tc1<30)||(Tc2<30)||(Tc3<30)) {
digitalWrite(Heatpads, HIGH);
Serial.println("Heatpads are now on!");
}
else {
digitalWrite(Heatpads, LOW);
Serial.println("Heatpads are now OFF!");
}

Welcome to the forum

Did you read the advice that you were directed to in order to make the best use of the forum ? If so, then why did you ignore it ?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

what you did seems fine

what about

    digitalWrite(Heatpads, (Tc1 < 30 || Tc2 < 30 || Tc3 < 30)

may want an LED indicating if turned on

You could put the TC's in an array.

Your 'Attempt' is: If ANY are above 30, turn the heatpads off but if ALL are below (or equal) 30, turn the heatpads on.

Your 'solution' is: If ANY are below 30, turn the heatpads on but if ALL are above (or equal) 30, turn the heatpads off.

yup, you solved my issue, cant belive how easy that was, just flip it around.. thank you! now its a lot more clean

though it woundt be necessary since its only a snippet of the full code, guess i was wrong, my bad, ill try to follow this advice the next time i post any code

wait, you can put statements there?! this is groundbreaking news for me!

ill be sure to look into that! thx!

yes! i want them to be atleast 30 all the time, i see my error now

The problem with only posting snippets of code is that they cannot be seen in context. For instance, what is data type of the variables, are the variables local or global or even both as is sometimes the case, etc