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 a 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 the analog side to an Arduino board.
  • The third pin can be connected to the Gnd to an Arduino board.
Programming
  1. float temp;  
  2. int tempPin = A1; //arduino pin used for temperature sensor      
  3. int tempMin = 25; // the temperature to start the buzzer      
  4. int tempMax = 70;  
  5. int fan = 9; // the pin where fan is connected      
  6. int fanSpeed = 0;  
  7. void setup()   
  8. {  
  9.   pinMode(fan, OUTPUT);  
  10.   pinMode(tempPin, INPUT);  
  11.   Serial.begin(9600);  
  12. }  
  13. void loop()   
  14. {  
  15.   temp = analogRead(tempPin);  
  16.   temp = (temp * 5.0 * 100.0) / 1024.0; //calculate the temperature in Celsius      
  17.   Serial.println(temp);  
  18.   delay(1000); // delay in between reads for stability      
  19.   if (temp < tempMin)   
  20.   {  
  21.     // if temp is lower than minimum temp      
  22.     fanSpeed = 0; // fan is not spinning  
  23.     digitalWrite(fan, LOW);  
  24.   }  
  25.   if ((temp >= tempMin) && (temp <= tempMax)) //if temperature is higher than the minimum range      
  26.   {  
  27.     fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan      
  28.     analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed      
  29.   }  

Explanation
  • In this article, I  explained the temperature based fan control
  • When the fan is ON/OFF it has been 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.