D
D
DimiDr0lik2015-03-06 12:54:16
Arduino
DimiDr0lik, 2015-03-06 12:54:16

How to regulate the temperature within the given limits?

In my code, the first condition is executed only for the first time for some reason, although for me the logic is correct, by default ktemp = false

Code:

if (ktemp = false && temp_atmosphere < t1) {
    digitalWrite(heatPin, HIGH); //включение обогревателя
    digitalWrite(airPin, HIGH); //включение вентилятора
    ktemp = true;
    Serial.println("obogrev BKJI");
  }
  else if (ktemp = true && temp_atmosphere < (t1 + 0.5)) {
    digitalWrite(heatPin, HIGH); //включение обогревателя
    digitalWrite(airPin, HIGH); //включение вентилятора
  }
  else if (temp_atmosphere > (t1 + 3) || hum_atmosphere > 85) { //если темепература на 3с или влажность выше 85%
    digitalWrite(heatPin, LOW); //выключение обогревателя
    digitalWrite(airPin, HIGH); //включение вентилятора
    Serial.println("obduv BKJI");
  }
  else {
    ktemp = false;
    digitalWrite(heatPin, LOW); //выключение обогревателя
    digitalWrite(airPin, LOW); //выключение вентилятора
    Serial.println("BCE BbIK");
  }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Armenian Radio, 2015-03-06
@gbg

:[|||||||||||||||||||||||||/////////////////-many more kilometers button accordion-\\\\\\\\\\\\\\|]:
I assume you want to test ktemp for falsehood.
In this case, you need to write two equal signs, because one sign in C++ is an assignment.
Better yet, write:
if ( (!ktemp) && (temp_atmosphere < t1) ) {

V
Vladimir Martyanov, 2015-03-06
@vilgeforce

I see a strange thing: ktemp is set to true only after the heater is turned on, but the second condition checks that ktemp = true and turns the heater on again. But I don't think it's relevant to the problem.
The else branch will work only if the heating is on, and the temperature is between t1 + 0.5 - t1 + 3. I suspect that the system flies this interval very quickly and the else if (temp_atmosphere > (t1 + 3) branch begins, in which ktemp is not reset. Explain , by the way, purpose of ktemp - not absolutely understood what for it.

R
Roots, 2015-03-07
@Roots

This is very similar to trying to write a PID controller .. Exactly the same as various copters can smoothly stabilize or vice versa sharply, depending on the conditions. Nonlinear dependency.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question