Home » Heater Controllers » 2 Automatic Temperature Controlled DC Fan Circuits
2 Automatic Temperature Controlled DC Fan Circuits

2 Automatic Temperature Controlled DC Fan Circuits

In this article we are going to construct a couple of simple Arduino based automatic temperature controlled dc fan circuits which will switch ON a fan or any other gadgets connected to it, when the ambient temperature reaches a pre-determined threshold level. We are going to utilize DHT11 sensor and arduino for this project.

By: Arduino Guru


The beauty of microcontrollers is that, we get very precise control over the peripherals which are connected to it. In this project the user just need to input the threshold temperature in the program, the microcontroller will take care of rest of the function.

There are tons of non-microcontroller based automatic temperature controller projects available around the internet, such as using comparator and transistors.

They are very simple and they do work well but, the problem arises while calibrating the threshold level using preset resistor or potentiometer.

We have a blind idea while calibrating it and the user may need to do trial and error method to find the sweet spot.

These problems are overcome by microcontrollers, the user just need to enter the temperature in Celsius in this project, so no need for calibration.

This project can be used where internal temperature of circuit need to be stabilized or saving it from overheating.

In diagram 1, we are connecting a CPU fan as output. This setup can be used to control the internal ambient temperature of an enclosed circuit.

When the threshold temperature is reached the fan turns on. When the temperature goes below threshold temperature fan turns off. So it’s basically an automated process.

In diagram 2, we connected a relay for controlling devices which runs on mains voltage such as table fan.

When the room temperature reaches the threshold temperature the fan turns on and turns off when the room cools down.

This may be the best way for saving power and this can be heaven for lazy people who wish others to switch the fan ON when they feel warm.

Circuit Diagram Showing a DC Fan Control

DC fan control for temperature adjust automatic

This setup may be deployed for circuits which are enclosed in a box. The LED turns ON when the preset threshold level reached and also turns ON the fan.

Connecting a Relay for Controlling Bigger Fans

Relay switch fan control using Arduino temperature sensor

This circuit does the similar function of previous circuit, now the fan is replaced by relay.

This circuit can control a table fan or ceiling fan or any other gadget which can cool down the ambient temperature.

The connected device turns off as soon as the temperature reached below preset threshold level.

The temperature controlled dc fan circuit diagram illustrated here are just few of many possibilities. You may customize the circuit and program for your own purpose.

NOTE 1: #Pin 7 is output.

NOTE 2: This program is only compatible with DHT11 sensor only.

Program for the above explained automatic temperature regulator circuit using Arduino:

Program Code

//--------------------Program developed by R.Girish---------------------//
#include <dht.h>
dht DHT;
#define DHTxxPIN A1
int p = A0;
int n = A2;
int ack;
int op = 7;
int th = 30; // set thershold tempertaure in Celsius
void setup(){
Serial.begin(9600); // May be removed after testing
void loop()
int chk = DHT.read11(DHTxxPIN);
switch (chk)
// you may remove these lines after testing, from here
Serial.print("Temperature(°C) = ");
Serial.print("Humidity(%) = ");
// To here
if (DHT.temperature>=th)
if(DHT.temperature>=th) digitalWrite(op,HIGH);
// may be removed after testing from here
Serial.print("NO DATA");
// To here
//-------------------------Program developed by R.Girish---------------------//

Note: In the program

int th= 30; // set the threshold temperature in Celsius.

Replace “30” with the desired value.

Second Design

The second temperature controlled dc fan circuit project discussed below automatically senses the ambient temperature and adjusts the fan motor speed to keep the surrounding temperature under control. This automatic processing is done through an Arduino and a temperature sensor IC LM35.

By: Ankit Negi


1). As soon as temperature of the surrounding increases beyond 25 degree Celsius (you can change this value in program according to your need, explained in working section) motor starts running.

2). And with each degree of rise in temperature, speed of motor also increases.

3). Motor run at its top speed as soon as temperature rises to 40 degree Celsius ( this value can be changed in program).


To achieve the task mentioned above, we are going to use temp. Sensor LM35 as it is used widely and easily available.

LM35 has 3 pins as you can see in figure.

LM35 IC pinout

1. Vin-- this pin is connected to dc power supply between 4 to 20 v.
2. Vout-- this pin gives output in the form of voltage.
3. GND-- this pin is connected to gnd terminal of circuit.

LM35, when connected to power supply senses the temperature of surroundings and sends equivalent voltage in accordance with per degree rise in temperature through its output pin.

LM35 can sense any temp. between -50 degree to +150 degree Celsius and increases output by 10 millivolts with 1 degree rise in temperature. Thus maximum voltage it can give as output is 1.5 volts.


Arduino is required to change the analog value received from output pin of LM35 to digital value and sends the corresponding digital output (PWM) to the base of mosfet.

We will also use arduino commands to print temperature, corresponding analog value and digital output to mosfet on serial monitor of ARDUINO IDE.


This circuit will be of no use if it cannot run high current motor. Hence to run such motors power mosfet is used.


Diode is used to protect the mosfet from the back E.M.F generated by motor while running.


1. LM35




4. DIODE (1N4007)

DIODE (1N4007)

5. FAN (motor)



Arduino temperature dependent DC fan control

Make connections as shown in circuit diagram.

a) Connect vin pin of lm358 to 5v of arduino
b) Connect vout pin of lm358 to A0 of arduino
c) Connect ground pin of lm358 to GND of arduino
d) Connect base of mosfet to PWM pin 10 of arduino


float x;// initialise variables
int y;
int z;
void setup()
pinMode(A0,INPUT); //  initialize analog pin A0 as input pin
Serial.begin(9600); // begin serial communication
pinMode(10,OUTPUT); //  initialize digital pin 10 as output pin
void loop()
x=analogRead(A0) ; // read analog value from sensor's output pin connected to A0 pin
y=(500*x)/1023;// conversion of analog value received from sensor to corresponding degree Celsius (*formula explained in working section)
z=map(x,0,1023,0,255) ; // conversion of analog value to digital value
Serial.print("analog value    ");
Serial.print(  x) ; // print analog value from sensor's output pin connected to A0 pin on serial monitor( called "analog value")
Serial.print("    temperature    ");
Serial.print(  y) ; // print the temprature on serial monitor( called "temprature")
Serial.print("     mapped value     ");
Serial.print(      z*10) ; // multiply mapped value by 10 and print it ( called " mapped value " )
delay(1000) ; // 1 sec delay between each print.
{analogWrite(10,z*10)  ;  // when temp. rises above 25 deg, multiply digital value by 10 and write it on PWM pin 10 ( ** explained in working section)
{analogWrite(10,0) ; //  in any other case PWM on pin 10 must be 0

WORKING (understanding code):


This is simply the analog value which is received by pin no. A0 from the output pin of LM35.


Because of this variable only, our fan motor runs in accordance with the corresponding temperature. What this variable does is it changes the analog value i.e. variable x  to corresponding  temperature of surroundings.

Y = (500*x)/1023
1. First analog value must be changed to corresponding voltage i.e.
1023: 5v
Hence,         (5000 millivolt *x)/1023    V
2. Now we know that for each degree rise in temperature corresponding voltage output           increases by 10 mv i.e.
1 degree Celsius: 10 millivolts
Hence,         (5000 millivolt *x)/ (1023*10)   DEGREE


z=map(x, 0, 1023, 0,255)  ;
this variable changes the analog value to digital value for pwm output on pin 10.

NOTE:: We know that lm35 can provide maximum of 1.5 volt and that too when temp.  Is 150 deg. which is not practical.

This means for 40 degree Celsius we get 0.40 volts and for 25 degree we get 0.25 volts. Since these values are very low for proper pwm on mosfet, we need to multiply it by a factor.

Hence we multiply it by 10 and instead give this value as analog output to PWM pin 10 i.e.

**  analogWrite(10,z*10)

Now, for .25 volts mosfet gets 0.25*10 = 2.5 volts

For .40 volts mosfet gets 0.40*10 = 4 volts at which motor almost run at its full speed

CASE 1. When temp. Is less than 25 degree

In this case arduino sends 0 PWM voltage to pin 10 as in the last line of code

** else
{analogWrite(10,0);//in any other case PWM on pin 10 must be 0
} **

Since pwm voltage on base of mosfet is 0, it remains off and motor gets disconnected from the circuit.

See simulated circuit in this case.

Arduino fan control simulation

As you can see temperature is 20 degree hence

Analog value=41
Mapped value=100

But since temp is less than 25 degree hence mosfet gets 0 volt as show in fig( indicated by blue dot).
CASE 2. When temp. Is greater than 25 degree

When temperature reaches 25 degree, then as specified in the code pwm signal is sent to the base of mosfet and with each degree rise in temperature this PWM voltage also increases i.e.

} which is z* 10.

See simulated circuit in this case.

As you can see as temperature increases from 20 degree to all the way to  40 degree , all three value changes and at 40 degree Celsius

Analog value=82
Mapped value=200

Since temp is greater than 25 degree hence mosfet gets corresponding PWM voltage as show in fig( indicated by red dot).

Hence motor starts running at 25 degree and with corresponding rise in per degree temperature; pwm voltage from pin 10 to base of mosfet also increases. Hence motor speed increases linearly with the increase in temperature and becomes almost maximum for 40 degree Celsius.

If you have any further queries regarding the above explained automatic temperature controlled dc fan circuit using fan and Arduino, you can always use the comment box below and send your thoughts to us. We will try to get back at an earliest.


About the Author

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials. If you have any circuit related query, you may interact through comments, I'll be most happy to help!

5 thoughts on “2 Automatic Temperature Controlled DC Fan Circuits”

    • Thanks Sasa, I tried to send it to your email, but it seems your email ID is not correct or has problems. It was returned back to my email.

  1. Hi

    I have heater but I have to manually turn it on off when its cold. Can you suggest me a simple solution which will keep the room temperature warm throughout night. I intend to use this only in winter.


  2. This would be better design if it also included humidity as a variable. I want a circuit that will activate relay when humidity is at 45% or less and when outside temps drop below ambient temp. So when both conditions are met relay is activated

Leave a Comment