Control Fan With Temperature Sensor Using Arduino Mega 2560

Introduction
  • In this article I will explain about controlling the fan by temperature sensor by using Arduino Mega 2560.

  • In the range it can be controlled by the fixed temperature so that it can easily be done. 
Parts Of Lists
  • Arduino Mega 2560
  • Fan or servo motor
  • LM35
  • Bread Board
  • Hookup Wires. 
Connection

Step 1 Connect the ServoMotor To the Arduino Mega 2560
  • Connect the Vcc of the servo Motor to the 5v of the Arduino Mega 2560.
  • Connect the gnd of the bluetooth to the Gnd of the Arduino Mega 2560.
  • Connect the Vin of the bluetooth to the 09 of the Arduino Mega 2560.
Step 2 Connect the Temperature Sensor To The Arduino mega 2560
  • The first pin can be connected to the Vcc of the 5V to an Arduino board.
  • The second pin can be connected to the A1 of analog side to an Arduino board.
  • The third pin can be connected to the Gnd to an Arduino board.
Programming
  1. float temp;  
  2.   
  3. int tempPin = A1; //arduino pin used for temperature sensor    
  4.   
  5. int tempMin = 25; // the temperature to start the buzzer    
  6.   
  7. int tempMax = 70;  
  8.   
  9. int fan = 9; // the pin where fan is connected    
  10.   
  11. int fanSpeed = 0;  
  12.   
  13. void setup()  
  14. {  
  15.   
  16.     pinMode(fan, OUTPUT);  
  17.   
  18.     pinMode(tempPin, INPUT);  
  19.   
  20.     Serial.begin(9600);  
  21.   
  22. }  
  23.   
  24. void loop()   
  25. {  
  26.   
  27.     temp = analogRead(tempPin);  
  28.   
  29.     temp = (temp * 5.0 * 100.0) / 1024.0; //calculate the temperature in Celsius    
  30.   
  31.     Serial.println(temp);  
  32.   
  33.     delay(1000); // delay in between reads for stability    
  34.   
  35.     if (temp < tempMin)  
  36.     {   
  37.         // if temp is lower than minimum temp    
  38.   
  39.         fanSpeed = 0; // fan is not spinning    
  40.   
  41.         digitalWrite(fan, LOW);  
  42.   
  43.     }  
  44.   
  45.     if ((temp >= tempMin) && (temp <= tempMax)) //if temperature is higher than the minimum range    
  46.   
  47.     {  
  48.   
  49.         fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan    
  50.   
  51.         analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed    
  52.   
  53.     }  
  54.   
  55.  
Explanation
  • In this article I  explained about the temperature based fan control
  • When the fan is ON/OFF it has be based on the temperature I have fixed.
  • When the temperature is low it can be started. 
  • When the temperature is high it can be stopped. 

Up Next
    Ebook Download
    View all
    Learn
    View all