Go Down

### Topic: Final Year Project (Read 632 times)previous topic - next topic

#### Jonathan.duong

##### Apr 27, 2017, 07:18 pm
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.

#### wildbill

#1
##### Apr 28, 2017, 01:22 amLast Edit: Apr 28, 2017, 01:24 am by wildbill
This snippet:
Code: [Select]
`         else if ((TempCelsius<=25) && (TempCelsius<30));`
was probably intended to be
Code: [Select]
`         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

#### AWOL

#2
##### Apr 28, 2017, 08:24 pmLast Edit: Apr 28, 2017, 08:49 pm by AWOL
Code: [Select]
` if ((TempCelsius>=30) && (TempCelsius<40));`Oops

(BTW, don't bother looking for the duplicate of this topic; I deleted it)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### mugambi

#3
##### Apr 29, 2017, 11:47 pm
Logic error on

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

How temperature relates to fan speed though is not clear

#### AWOL

#4
##### Apr 30, 2017, 08:10 am
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
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Jonathan.duong

#5
##### May 01, 2017, 06:21 pm

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.

#### AWOL

#6
##### May 01, 2017, 07:46 pm
Code: [Select]
`if ((TempCelsius>=35) && (TempCelsius<50));`Oops.
Again.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### GaryP

#7
##### Sep 03, 2017, 10:25 am
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
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Go Up