Final Year Project

Hey, all

I'm currently working on a project for my last semester of school. Currently, I'm on a co-op work term and haven't practiced much with my Arduino for a couple years go. So my problem is probably fairly simple to solve but I can't seem to figure it out. I have a If/Else If statement that should output the value of the duty cycle (of a fan), depending on the temperature output of a thermistor. I tried to use a nested if statement but it doesn't work like I want. Also, the variable "Enable" is the pin out
I declared for the Arduino to use, it's connected to the EN pin of a motor drive IC. Also, I'm measuring across the DC motor and I'm not getting any readings but I should be able to figure that part out. Any help would be much appreciated. The code is as follows...

if (TempCelsius <25.00)
{
analogWrite(Enable,0);
Serial.println("Fan Speed = 0%");
}
else if ((TempCelsius<=25) && (TempCelsius<30));
{
analogWrite(Enable, 77);
Serial.println("Fan Speed = 30%")
}

else if ((TempCelsius<=30) && (TempCelsius<40));
{
analogWrite(Enable, 153); //255*0.6=153 Duty Cycle
Serial.println("Fan Speed = 60%")

}
else if (TempCelsius<40);
{
analogWrite(Enable, 255);
Serial.println("Fan Speed = 100%")

}

Thanks.

This snippet:

         else if ((TempCelsius<=25) && (TempCelsius<30));

was probably intended to be

         else if ((TempCelsius>=25) && (TempCelsius<30));

Similar issue further down too. Of course you don't actually need the >=25 bit anyway - the evaluation of the first if already established that the temp is not less than 25

if ((TempCelsius>=30) && (TempCelsius<40));Oops

(BTW, don't bother looking for the duplicate of this topic; I deleted it)

Logic error on

else if (TempCelsius < 40);
you probably mean
else if (TempCelsius > 40);

How temperature relates to fan speed though is not clear

mugambi:
Logic error on

else if (TempCelsius < 40);
you probably mean
else if (TempCelsius > 40);

How temperature relates to fan speed though is not clear

I find it hard to believe s/he meant either form; see reply #2

if (TempCelsius <25)
{
analogWrite(E1,0);
Serial.println("Fanspeed = 0%");
}

if ((TempCelsius >=25) && (TempCelsius<35))
{
analogWrite(E1,75);
Serial.println("Fanspeed = 30%");
}

if ((TempCelsius>=35) && (TempCelsius<50));
{
analogWrite(E1,125);
Serial.println("Fanspeed = 60%");
}
if (TempCelsius>50)
{
analogWrite(E1,255);
Serial.println("Fanspeed = 100%");
}

i changed it up a bit just to make it as basic as possible. I still get the Fanspeed = 60% reading even when i'm not within that range. Also im printing the actual temperature onto the serial monitor to make sure that its not a hardware issue. Any help would be much appreciated.

if ((TempCelsius>=35) && (TempCelsius<50));Oops.
Again.

Jonathan.duong:
if (TempCelsius <25)
{
analogWrite(E1,0);
Serial.println("Fanspeed = 0%");
}

if ((TempCelsius >=25) && (TempCelsius<35))
{
analogWrite(E1,75);
Serial.println("Fanspeed = 30%");
}

if ((TempCelsius>=35) && (TempCelsius<50));
{
analogWrite(E1,125);
Serial.println("Fanspeed = 60%");
}
if (TempCelsius>50)
{
analogWrite(E1,255);
Serial.println("Fanspeed = 100%");
}

i changed it up a bit just to make it as basic as possible. I still get the Fanspeed = 60% reading even when i'm not within that range. Also im printing the actual temperature onto the serial monitor to make sure that its not a hardware issue. Any help would be much appreciated.

What if TempCelsius == 50, what then, nothing happens?

Kari