Automatic Temperature Control with Fan Motor and Arduino

The project discussed here automatically senses the ambient temperature and adjusts the 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

OUR OBJECTIVE:

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

TEMPERATURE SENSOR LM35:

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.

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.

WHY ARDUINO FOR THIS TEMPERATURE CONTROLLER PROJECT? 

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.

WHAT IS THE ROLE OF POWER MOSFET? 

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

WHY DIODE IS USED? 

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

PARTS LIST FOR THE PROJECT: 

1. LM35

2. ARDUINO

3. POWER MOSFET ( IRF1010E)

4. DIODE (1N4007)

5. FAN (motor)

6. FAN POWER SUPPLY

CIRCUIT DIAGRAM: 

Automatic Temperature Control with Fan Motor and Arduino

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

CODE:

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 " )
  Serial.println();
  delay(1000) ; // 1 sec delay between each print.
 
   if(y>25)
   {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)
   }
  else
  {analogWrite(10,0) ; //  in any other case PWM on pin 10 must be 0
   }

}

WORKING (understanding code):

A). VARIABLE X-

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

B). VARIABLE Y-

Because of this variable only, our 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

C). VARIABLE Z-

  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.

As you can see temperature is 20 degree hence

Analog value=41
Temperature=20
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.

           if(y>25)
         {analogWrite(10,z*10)
} 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
Temperature=40
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 controller 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.



3 thoughts on “Automatic Temperature Control with Fan Motor and Arduino

  1. Have questions? Please feel free to post them through comments! Comments will be moderated and solved ASAP.
  2. Hi Ankit/Swag,
    I was wondering what Circuit Simulator you are using in pics above so I can try to achieve exact results before actually building the circuit? Can you share the URL where I can buy/download the software?
    Thanks
    BJ



Leave a Comment