Hi, Any help much appreciated
I'm trying to make a temperature controller with a fan~ unsucessfully though
Ultimately im trying to make it a PI controller, but the simple on/off version isn't working
Can anyone see any problems in the hardware/code that may be causing this?
Many Thanks,
H
float temp;
int tempPin = A0; //arduino pin used for temperature sensor
int tempMin = 25; // the temperature to start the fan
int tempMax = 40;
int fan = 6; // the pin where fan is connected
int fanSpeed ;
void setup() {
pinMode(fan, OUTPUT);
pinMode(tempPin, INPUT);
Serial.begin(9600);
}
void loop() {
temp = analogRead(tempPin)*5/1024.0;
temp = temp - 0.5;
temp = temp / 0.01;
Serial.print ("Temperature: ");
Serial.println(temp);
Serial.print ("Fan Speed:");
Serial.println(fanSpeed);
delay(1000); // delay in between reads for stability
if(temp <= tempMin)
{
fanSpeed = 0;
analogWrite(fan, LOW);}
else if (temp >= tempMin)
{
fanSpeed = 255;
analogWrite(fan, HIGH); // spin the fan at the fanSpeed speed
}}
