Help Fan Control

Hello,

I need help. I try to control my fan.
Description:
Water Temp should be 24 - 26 degries
if Watertemp rise up over 26 degries, the fan should turn on.
with the PWM signal, I want to control the speed.
26 -27 degries 50% Ratio Speed
27-28 dgries , 75% Ratio speed
over 29 degries, 100% ratio speed.

I have started
like this:

void loop()
{
sensors.requestTemperatures();
float TempWatter = sensors.getTempCByIndex(0);
Serial.print(“Wassertemperatur:”);
Serial.println(TempWatter);
if (TempWatter<26){
digitalWrite(Heater, LOW);
Serial.println(“Fan”);
Serial.println(“Off”);
}
if(TempWatter>29,1){
digitalWrite(Heater, HIGH);
Serial.println(“Fan”);
Serial.println(“On”);
byte tgt1 = 255;
getPwm(tgt1);
Serial.print(“Ziel1: “);
Serial.print(map(tgt1, 0, 255, 0, 100));
Serial.println(’%’);
Serial.println(”-----”);
analogWrite(9, tgt1);
}
if(TempWatter<29,1&&TempWatter>27){
digitalWrite(Heater, HIGH);
Serial.println(“Fan”);
Serial.println(“On”);
byte tgt1 = 192;
getPwm(tgt1);
Serial.print(“Ziel1: “);
Serial.print(map(tgt1, 0, 255, 0, 100));
Serial.println(’%’);
Serial.println(”-----”);
analogWrite(9, tgt1);
}
if(TempWatter>26,1&&TempWatter<27){
digitalWrite(Heater, HIGH);
Serial.println(“Fan”);
Serial.println(“On”);
byte tgt1 = 128;
getPwm(tgt1);
Serial.print(“Ziel1: “);
Serial.print(map(tgt1, 0, 255, 0, 100));
Serial.println(’%’);
Serial.println(”-----”);
analogWrite(9, tgt1);
}
}

Please post your entire sketch using code blocks.

You have to use the decimal point '.' in floating point constants

if(TempWatter>29,1){

Hello,
here ist the INO file with all content.
the characters “,” i have not changed yet.
BR
Romai

L_ftersteuerung.ino (2.03 KB)

I have changed the "," to "." and it works now. Have someone a better idea, how I can make the script smarter?

You have three almost identical sections of code like this:

    digitalWrite(Heater, HIGH);
    Serial.println("Fan");
    Serial.println("On");
    byte tgt1 = 128;
    getPwm(tgt1);
    Serial.print("Ziel1: ");
    Serial.print(map(tgt1, 0, 255, 0, 100));
    Serial.println('%');
    Serial.println("-----");
    analogWrite(9, tgt1);

Where the only thing that differs is the value for tgt1. You could write a function that does all that taking a parameter of type byte. That would make your sketch shorter and simpler.

Hey thanks guys,
I am not so familar. how I can do this?

wildbill:
You could write a function that does all that taking a parameter of type byte.

romai2050:
I am not so familar. how I can do this?

Have a look at this, as a start.

Hey guys,
thanks so lot, I have completed my program with function it works fine.