Ali
Published © CC BY-SA

Automatic Temperature Control Fan Speed

I will design a practical temperature controller that controls temperature of any device.

IntermediateFull instructions providedOver 2 days1,139
Automatic Temperature Control Fan Speed

Story

Read more

Code

flexable_temp.ino

Arduino
Error opening file.

Code snippet #1

Plain text
/*practical temperature controller that controls temperature using a speed<br>fan (Cooling fan)
created by: Ali Shwaiheen May 2017*/
/******************************************
 * LCD RS pin to digital pin 8            * 
 * LCD D4 pin to digital pin 4            *
 * LCD D5 pin to digital pin 5            * 
 * LCD D6 pin to digital pin 6            *
 * LCD D7 pin to digital pin 7            *
 * LCD A pin to 220 Resistor To 5V        *
 * LCD k pin to Ground                    *
 * LCD Enable pin to digital pin 9        *
 * LCD VDD  pin to VSS to Ground Pos      *
 * LCD RW  pin to VSS to Ground Pos       *
 *****************************************/
#include 
 
#include 

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int set_btn = 2;     // Set Botton
int decr_btn = 1;    // Decrement Botton  
int incr_btn = 0;    // Increament Botton
int brk_btn = 3;     // break Botton  
int RLED = 12;       // LED Pin */
double temp;         // Sensor Data 
int tempPin = A5;    // Thirmoster Output Pin
int tempMin = 20;    // Minumum Temperature Where The Fan Start to Operate At Low Rate Of Speed
int tempMax = 30;    // Maximum Temperature Where The Fan Start to Operate At Full Rate Of Speed
int fan = 11;        // Fan Enable
int fanSpeed;        // Fan Data 
int fanLCD,x=0;      // LCD setup for varialble bush botton 

void setup() {

  pinMode(fan,OUTPUT);
  pinMode(RLED,OUTPUT);
  pinMode(tempPin,INPUT);
  attachInterrupt(0,set_Tmp,LOW);
  lcd.begin(16, 2);

}

void loop() {

 int temp = readTemp();                                       // Get the Temperature 
 
  if(temp < tempMin) {                                     // If Temperature is Lower Than the Minimum Temperature
    fanSpeed = 0;
    digitalWrite(fan,LOW);
  }
 
  if((temp > tempMin) && (temp <= tempMax))                // If Temperature is Between The higher and Lower Tempertature
  { 
    fanSpeed = map(temp,tempMin,tempMax,32,255);            // Actual Speed of The Fan 
    fanLCD = map(temp,tempMin,tempMax,0,100);              // Speed of Fan To Display on LCD
    analogWrite(fan,fanSpeed);                             // Spin the fan at the fanSpeen speed
  }
  
  if( temp > tempMax)                                      // If temperature higher than the Maximum Temperature turn on the LED 
  {
    digitalWrite(RLED,HIGH);                                // Turn on LED 
  }
  
  else {
    digitalWrite(RLED,LOW);
    
  }

  lcd.print("TEMP:");
  lcd.print(temp);                                        // Display the Temperature
  lcd.print("C");
 
  lcd.setCursor(0,1);                                     // Move cursor to next line
  
  lcd.print("FANS:");
  lcd.print(fanLCD);                                      // Display the fan speed
  lcd.print("%");
  
  delay(1000);                                           // Delay One second
  
  lcd.clear();
}

   double readTemp(){                                      // Get Temperature and Convert it To Celsius
   double temp;
   int ADCVal = analogRead(tempPin); // Inputs ADC Value from Thermistor and outputs Temperature in Celsius
   temp = log(10000.0*((1023.0/ADCVal-1))); 
   temp = 1 / (0.001129148 + (0.000234125 * temp) + (0.0000000856741 * temp * temp * temp));
   temp = temp - 273.15;            // Convert Kelvin to Celcius
   return temp; // Return the Temperature
   
}
    
void set_Tmp(){

    x = !x;

    if(x==1)
    {
      lcd.clear();

      lcd.setCursor(0,0);

      lcd.print("PLEASE SET ");

      lcd.setCursor(0,1);

      lcd.print("MIN TEMPERATURE");

      while(1)
      {
      if(digitalRead(incr_btn)==LOW)
      {
        
      while(digitalRead(incr_btn)==LOW)
      {
        tempMin = tempMin+1;

        lcd.setCursor(0,0);

        lcd.print("SET MIN TEMP:");

        lcd.print(tempMin);

        delay(10000);
    
      }
    }

you may download... 

Credits

Ali

Ali

4 projects • 3 followers
Electrical Engineer

Comments