• Register
  • Login
  • looking for something?

    temperature controlled fan

    In this project, we are going to build something very simple project, a temperature controlled relay that is used to turn on a dc fan. You can actually change the DC Fan to other electrical devices such as light or servo motor. We are going to make an automatic fan that will be ON when the temperature rises above certain threshold temperature and OFF when it is below.

    Just follow the steps below and you are ready to get yourself one Temperature-Controlled Automatic Fan!

    Things that you need

    • Arduino UNO
    • LM35 Temperature Sensor(Celsius) – datasheet
    • Relay Module ( May refer to my previous post on how to make a relay module)
    • A 9V battery (To supply to the coil of relay and the fan)
    • A DC fan (9V/12V)
    • Some jumper wires
    • 16 x 2 LCD

    Okay, now let’s get started.

    Step 1

    Connect the hardware according to the schematic below:

    LCD & LM 35

    arduino lcd lm35

    Relay Module

    arduino relay module

    DC Fan

    arduino dc fan

    Done with the hardware part? Awesome!

    Part 2: Software

    For the software part, I program it using arduino IDE v1.01.

    #include <LiquidCrystal.h>
    int reading = 0;
    int sensorPin = A0;
    int relay =7;
    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    
    void setup() {
    	// set up the LCD's number of columns and rows: 
    	lcd.begin(16, 2);
    	pinMode(relay,OUTPUT);
    }
    
    void loop() {
    	reading = analogRead(sensorPin);
    	int celsius = reading/2;
    	lcd.setCursor(0, 0);
    	lcd.print("Temperature: ");	
    	lcd.setCursor(0,1);
    	lcd.print(celsius, DEC);
    	lcd.print((char)223);
    	lcd.print("C");
    	if (celsius >35) {
    		digitalWrite(7,HIGH);
    	} else {
    		digitalWrite(7,LOW);
    	}
    	delay(500);
    	lcd.clear();
    }
    

    Some brief explanation about the coding:
    1. reading = analogRead(sensorPin);
    – Read analog pin from LM35 temperature sensor input pin and store at reading.
    2. int celsius = reading/2;
    – LM35 are design to give the exact value of temperature in Celsius. To get the celsius
    value, the ADC value are required to divided by 2 .

    So, load this code into your arduino UNO and you are ready to go!

    Demo video

    Problem Encountered & Solutions

    Problem 1

    The GND of the 9V battery is not connected to the GND of the arduino. So, this cause the fan unable to move even if the temperature exceed the threshold temperature.

    Solution 1

    Connect the GND of the battery to the GND of arduino – common GND. If you are using a 5V relay instead of 12V relay, you only have to connect the arduino GND. I am using a 12V relay. So the coil voltage required would be higher.

    Problem 2

    When done uploading the code into my arduino UNO, the LCD display nothing.

    Solution 2

    After some troubleshoot work, I realised it is due to the contrast(pin 3 on LCD). You have to adjust the potentiometer connected to pin 3 of LCD until the LCD would display what you want it to display.

    Hope this simple guides would lead you to make your own success Temperature-Controlled Automatic Fan too.

    If you have any doubt, do leave your comments or contact me.

    Hope you enjoy. Happy reading !

    Thank you.

    Find more projects
    

    18 Responses to "Temperature Controlled Relay with Arduino – Tutorial #6"

    subscribe to newsletter
    1. O S Chandran says: on July 28, 2013 at 8:03 am

      The code has a minor spelling error which showed up while compiling. Celsius is spelt Celcius the third time

      Like or Dislike: Thumb up 0 Thumb down 0

    2. Mr Vincent I just want to know which software did you used to draw the schematic for a relay module.

      Like or Dislike: Thumb up 0 Thumb down 0

    3. Dear Couper,

      The software I used is eagle cadsoft software.

      Thanks :)

      Like or Dislike: Thumb up 0 Thumb down 0

    4. I tried out temp. Monitor, it realy worked without any problum, I love it

      Like or Dislike: Thumb up 0 Thumb down 0

    5. hi!i just wanna ask,how will i make it with two fans?i want to work it with two fans..thanks in advance! :)

      Like or Dislike: Thumb up 0 Thumb down 0

      • Do you want both fans to start at the same time?

        Like or Dislike: Thumb up 0 Thumb down 0

      • Well, if you want to control two fan then just connect two fans at the output parallel will do. Try it :)
        If you want control two fan individually then perhaps you could use two relay module and 2 input/output pin :)
        Thanks !

        Best regards,
        Vincent

        Like or Dislike: Thumb up 0 Thumb down 0

    6. hello! i am confuse on the connections..how will i connect the fan?because when i connect the positive of the fan to the NO of relay and the negative to the negative of battery, it already turned on.where will i connect the VCC,MCU,NO,NC,COM,GND of the circuit of the relay?thank you..

      Like or Dislike: Thumb up 0 Thumb down 0

    7. Do you know if this will work with the TMP36 sensor. I need one that can go to -30 or so.

      Like or Dislike: Thumb up 0 Thumb down 0

    8. How about using a DS18B20 with this setup?

      Like or Dislike: Thumb up 1 Thumb down 0

      • It will work and can be modified easily if you use the OneWire library from Arduino website. Thanks for the great idea!

        Like or Dislike: Thumb up 0 Thumb down 0

    9. hystrix says: on March 3, 2014 at 1:34 pm

      hello sir,can you give me some guides.I want to create this fan and apply it to baby stroller which is can be power up by using battery when there is no sun and switch to solar during afternoon.What should I add to the circuit and the code.Many thanks.

      Like or Dislike: Thumb up 0 Thumb down 0

    10. Hello sir, I have a similar circuit but with a means of setting a variable setpoint via a potentiometer. The pot and the sensor share the same power and ground rails but different analog input pins. My problem is a change in the potentiometer causes the temperature reading to change as well. What could be the course?

      Like or Dislike: Thumb up 0 Thumb down 0

    11. Hi Ian,

      My thoughts would be to set a range for the temp readings.

      Like or Dislike: Thumb up 0 Thumb down 0

    12. hi , may i know the value of resistor for R1 and R2?

      Like or Dislike: Thumb up 0 Thumb down 0

    What do you think about this article? Leave a comment!