• Register
  • Login
  • 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);
    void loop() {
    	reading = analogRead(sensorPin);
    	int celsius = reading/2;
    	lcd.setCursor(0, 0);
    	lcd.print("Temperature: ");	
    	lcd.print(celsius, DEC);
    	if (celsius >35) {
    	} else {

    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.

    subscribe to newsletter

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

    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

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

    3. Dear Couper,

      The software I used is eagle cadsoft software.

      Thanks :)

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

    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! :)

    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..

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

    8. How about using a DS18B20 with this setup?

    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.

    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?

    11. Hi Ian,

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

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

    13. Raul Geovanni says: on April 28, 2014 at 6:49 am

      Hello I really like your project.

      Can you tell me how to connect the relay and the fan to arduino?

      If you you would have a diagram like the one you have on the top would be fine.

      I hope you can help me thank you very much.

    14. How would I go about doing this using a Seeed Relay Shield?

    15. To add onto my previous question, I have a Seeed Relay Shield V2.0 and I have it stacked on the Arduino Uno. I have everything connected as per your schematic above (including the LCD) on a breadboard. The problems that I’m experiencing is (1) as soon as I upload the code, the fan activates immediately and the relays all being making a steady clicking sound, and (2) the temperature read out is giving a temperature in the mid 70s C, which is obviously not correct. The temperature sensor that came with my kit is the TMP36. As such, I modified the code to celsius>85 instead of celsius>35, but it still didn’t make a difference. I’m at an impasse, I can’t figure out if there is a problem with the code, or if (probably more likely) I have a hardware issue. Any advice would be greatly appreciated.

    16. Hi Marian, Nice video ; just wanted to know will the arduino circuit not fry up because of the back emf of the dc fan.
      or will the relay shield take care of that.

    17. how did you connect the relay to the Arduino?

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

    You may add a picture too (related to electronics)