Temperature Based Fan Speed Controller using Arduino
Temperature Based Fan Speed Controller using Arduino
Bill of Materials
S.N. Components Name Quantity Purchase Links
1 Arduino UNO Board 1 Amazon | AliExpress
2 LM35 Temperature Sensor 1 Amazon | AliExpress
3 12V DC Fan 1 Amazon | AliExpress
4 16x2 LCD Display 1 Amazon | AliExpress
5 Potentiometer 10K 1 Amazon | AliExpress
6 Transistor 2N2222 1 Amazon | AliExpress
S.N. Components Name Quantity Purchase Links
Circuit diagram of the Temperature Based Fan Speed Control & Monitoring
With Arduino & LM35 is shown above. Arduino is at the heart of the circuit
as it controls all functions. LM35 is a precision integrated-circuit whose
output voltage is linearly proportional to Celsius (Centigrade)
temperature. It is rated to operate over a -55°C to 150°C temperature
range. It has +10.0mV/Celsius linear-scale factor.
The 2N2222 transistor acts as a switch and controls the fan speed
depending upon temperature. 1N4007 diode controls the fan from being
damaged. The LED glows whenever the temperature exceeds 60°C.
#include <LiquidCrystal.h>
56 LiquidCrystal lcd(2,3,4,5,6,7);
57 int tempPin = A0; // the output pin of LM35
58 int fan = 11; // the pin where fan is
59 int led = 8; // led pin
60 int temp;
61 int tempMin = 30; // the temperature to start the fan 0%
62 int tempMax = 60; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
Serial.begin(9600);
}
void loop()
{
temp = readTemp(); // get the temperature
Serial.print( temp );
if(temp < tempMin) // if temp is lower than minimum temp
{
fanSpeed = 0; // fan is not spinning
analogWrite(fan, fanSpeed);
fanLCD=0;
digitalWrite(fan, LOW);
}
if((temp >= tempMin) && (temp <= tempMax)) // if temperature is higher than
minimum temp
{
fanSpeed = temp;//map(temp, tempMin, tempMax, 0, 100); // the actual speed of
fan//map(temp, tempMin, tempMax, 32, 255);
fanSpeed=1.5*fanSpeed;
fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on
LCD100
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
}