In this article we are going to construct a couple of simple Arduino based automatic temperature regulator circuits which will turn on the 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: Girish Radhakrishnan

Overview

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



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



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 diagrams 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
pinMode(p,OUTPUT);
pinMode(n,OUTPUT);
pinMode(op,OUTPUT);
digitalWrite(op,LOW);
}
void loop()
{
digitalWrite(p,1);
digitalWrite(n,0);
ack=0;
int chk = DHT.read11(DHTxxPIN);
switch (chk)
{
case DHTLIB_ERROR_CONNECT:
ack=1;
break;
}
if(ack==0)
{
// you may remove these lines after testing, from here
Serial.print("Temperature(°C) = ");
Serial.println(DHT.temperature);
Serial.print("Humidity(%) = ");
Serial.println(DHT.humidity);
Serial.print("\n");
// To here
if (DHT.temperature>=th)
{
delay(3000);
if(DHT.temperature>=th) digitalWrite(op,HIGH);
}
if(DHT.temperature<th)
{
delay(3000);
if(DHT.temperature<th)digitalWrite(op,LOW);
}
}
if(ack==1)
{
// may be removed after testing from here
Serial.print("NO DATA");
Serial.print("\n\n");
// To here
digitalWrite(op,LOW);
delay(500);
}
}
//-------------------------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 similar project discussed below 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: 




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.

Need Help? Please send your queries through Comments for quick replies!