Automatic regulation of a fan depending on the temperature variation

With this implicit declaration you may find data issues.

float Temperature1 = 0;         //Température1
float Temperature2 = 0;
float Temperature3 = 0;
float Temperature4 = 0;

When using floats better to be explicit with the declarations.

float Temperature1 = 0.0f;         //Température1
float Temperature2 = 0.0f;
float Temperature3 = 0.0f;
float Temperature4 = 0.0f;

That way when the IDE decides that yuppers a float was declared but they want to put an integer in it so to save space I, the complier, is going to make the variable an int instead but I will not tell the programmer that I made the change.

does the code enter and remain in auto mode?

  while(start == 1 && key == '#'){
       
Serial.println( "I am automode" );

        char key = CLV.getKey();
       
        if (Temperature1 < 25){
          pwm_v = 60;
          V = "V=";
          V += pwm_v;
          Mode = "Auto";
        }
        if (Temperature1 > 25 && Temperature1 < 30){
          pwm_v = 75;
          V = "V=";
          V += pwm_v;
          Mode = "Auto";
         }
         if (Temperature1 > 30){
          pwm_v = 150;
          V = "V=";
          V += pwm_v;
          Mode = "Auto";
         }
         if (key == '9'){
          V = "V=";
          V += pwm_v;
          Mode = "Fin reg";
         }
         break;
      }

If the serial prints one time, then the program is stopping automode, if the serial prints continue then automode remains active.

Either way a direction of troubleshooting can be realized.

Isn't every declared variable set to zero by the compiler code, regardless of the type?
I admit I practise

float Temperature1 = 0.0;         //Température1
float Temperature2 = 0.0;
float Temperature3 = 0.0;
float Temperature4 = 0.0;

Railroader:
Isn't every declared variable set to zero by the compiler code, regardless of the type?
I admit I practise

float Temperature1 = 0.0;         //Température1

float Temperature2 = 0.0;
float Temperature3 = 0.0;
float Temperature4 = 0.0;

Perhaps, I do not know. I do know that I have not had to troubleshoot float Xx = 0.0f. So I stick with it.

Fine. We both know that compiler "logic", "strategy" sometimes tricks us. long = int*int.... overflows and leaves an int...

You need to determine the PWM value that gives the MINIMUM fan speed, then the temperature range for MINIMUM and MAXIMUM speeds, then you can scale that to MINIMUM and MAXIMUM PWM values with the map function. The MINIMUM speed will probably be higher than you first think, you don't have to slow a fan down much before it feels like it's doing nothing.

Hello thank u for your help
The code enters in auto mode but does not remain in it. That's my problem.
The fan speed change one time when auto mode is activated but when the temperature changes, the speed does not change automatically. I have to press again # for the speed to change.

My minimum speed for the fan to work is 50PWM that's why i put myy minimum value of automatic regulation to 60PWM.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.