Khaled Md Saifullah
Published © MIT

Temperature Controlled Fan

This project will learn you how you can build a temperature controlled fan.

IntermediateFull instructions provided1 hour26,486
Temperature Controlled Fan

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1
Resistor 330 ohm
Resistor 330 ohm
×1
5 mm LED: Red
5 mm LED: Red
×1
Temperature Sensor
Temperature Sensor
×1
Buzzer
Buzzer
×1
Geared DC Motor, 12 V
Geared DC Motor, 12 V
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Temperature-controlled-fan

Code

temperatureControlledFan.ino

C/C++
// Declare all the pins 
int temp = A0;
int greenLed = 2;
int redLed = 4;
int fan = 7;
int buzzer = 8;

int thresholdValue = 0;
int celsius = 0;
int fahrenheit = 0;

// Functions for various work
void greenLightOn(){
	digitalWrite(greenLed, HIGH);
}
void greenLightOff(){
	digitalWrite(greenLed, LOW);
}
void redLightOn(){
	digitalWrite(redLed, HIGH);
}
void redLightOff(){
	digitalWrite(redLed, LOW);
}
void fanOn(){
	digitalWrite(fan, HIGH);
}
void fanOff(){
	digitalWrite(fan, LOW);
}
void buzzerOn(){
	digitalWrite(buzzer, HIGH);
}
void buzzerOff(){
	digitalWrite(buzzer, LOW);
}

void setup()
{
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(temp, INPUT);
  Serial.begin(9600);
}

void loop(){
  
  // Temperature calculation
  celsius = map(((analogRead(A0) - 20) * 3.04), 0, 1023, -40, 125);
  fahrenheit = ((celsius * 9) / 5 + 32);
  
  Serial.print(celsius);
  Serial.print(" C : ");
  Serial.print(fahrenheit);
  Serial.println(" F");
  
  if( celsius<= 30){
    greenLightOn();
    redLightOff();
    fanOff();
    buzzerOff();
    //Serial.println("green light on");
  }
  else if(celsius >= 31 && celsius <= 40){
    greenLightOff();
    fanOff();
    buzzerOff();
    redLightOn();
    //Serial.println("red light on");
  }
  else if(celsius > 40){
    redLightOn();
    fanOn();
    buzzerOn();
    greenLightOff();
    
    //Serial.println("Red Light On | Fan on");
  }
  else{
  	Serial.println("Temperature is Normal");
  }
  delay(1000);
}

Temperature-controlled-fan

Credits

Khaled Md Saifullah
18 projects • 44 followers
🦸Tech Enthusiast 👨🏾‍💻Programmer 📳IoT Specialist
Contact

Comments

Please log in or sign up to comment.