You are on page 1of 23

Microcontroller based Fan speed controller by measuring Temperature

1.

Introduction

Measuring the impact of environmental constraints is analysis and control. Different types of data loggers and data acquisition system are available in the market to perform this task well.

Temperature measurement is today more common. The ambient temperature keeps varying during different times of the day and night at different places. Temperature measurement can be done for weather forecast or for automation in electronics devices and industries.

Here we describe a temperature measurement device which controls the speed of the FAN using microcontroller AT89S52, temperature sensor and other components. The temperature is measured at a user defined interval. Each time the current temperature goes above ie increase or decrease corespondigly the FAN speed will vary .

1 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

2. Block Diagram

The above Block diagram consist of the following Functional Blocks 1. Temperature sensor 2. Analogue to digital converter ADC 3. Micro controller 4. Power supply 5. Lcd module 6. Motor Driver & DC motor FAN 1. Temperature sensor:This section has a temperature sensor which measures the temp and gives particular analog output. And gives output to the ADC.
2 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

2.

Analogue to digital converter adc Analog to digital converter which takes input from the temperature sensor and Converts it into digital signals, these signals are send to the processor.

3.

Microcontroller:Microcontroller is the heart of the circuit which receives the digital signals from the ADC and converts it into the ASCII code and gives the measured temperature on the Display. 4. Power supply:The most of the Digital ICs Microcontrollers, diplays, etc are work only in +5V so power supply circuit it must needed with some typical components. The relay requires unregulated DC supply so the power supply for the relay section is unregulated 12 V. 5. LCD module:The LCD is used for display the temperature measured. And it also displays the fan speed mposition . 6. Motor Driver: This driver circuit uses L293D IC for controlling speed of the DC motor FAN and the speed of the DC motor can be controlled by inputting the PWM signals from the micro controller. And the direction of the motor is also can be controlled by alternating the inputs to the IC.

3 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

3. Parts List IC1 IC2 IC3 IC4 IC5 BR1 AT 89S52 microcontroller ADC 0804 analogue-to digital converter LM35 temperature sensor 7805 5v regulator L293D motor driver Bridge rectifier 1A Resistors (all of watt, +/- 5 % carbon) R1,R4 R2,R3,R5-R8 RNW1 VR1 VR2 330-ohm 10 kilo-ohm 10kilo-ohm resistor network 10 kilo-ohm variable 1 kilo-ohm variable Capacitors C1 C2 C3 C4,C5 C6 1000uF,25v electrolytic 0.1 uF ceramic disk 10uF,16V electrolytic 33 pF, ceramic disk 150pF, ceramic disk

Miscellaneous X1 Xtal S1-S4 PZ1 LCD module FAN 230V AC Primary to 12V, 500mA secondary transformer X1 12Mhz Push-to-on switch Piezo Buzzer 16 character x 2 line LCD module 12 V DC motor

4 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

4. Circuit diagram

5 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

5. Hard ware Description Micro-controller at89s52 Features compatible with mcs-51 products 8k bytes of in-system programmable (isp) endurance: 10,000 write/erase cycles 4.0v to 5.5v operating range fully static operation: 0 hz to 33 mhz three-level program memory lock 256 x 8-bit internal ram 32 programmable i/o lines three 16-bit timer/counters eight interrupt sources full duplex uart serial channel low-power idle and power-down modes interrupt recovery from power-down mode watchdog timer dual data pointer power-off flag fast programming time flexibleisp programming (byte and page mode) green (pb/halide-free) packaging option description The at89s52 is a low-power, high-performance cmos 8-bit microcontroller with 8k bytes of in-system programmable flash memory. The device is manufactured using atmels high-density nonvolatile memory technology and is compatible with the industry-standard 80c51 instruction set and pinout. The on-chip flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory pro6 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

grammer. By combining a versatile 8-bit cpu with in-system programmable flash on a monolithic chip, the atmel at89s52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. The at89s52 provides the following standard features: 8k bytes of flash, 256 bytes of ram, 32 i/o lines, watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the at89s52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The idle mode stops the cpu while allowing the ram, timer/counters, serial port, and interrupt system to continue functioning. The power-down mode saves the ram con-tents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset. Oscillator Xlt1 and xlt2 are the input and output of an inverting amplifier, which is used as a crystal oscillator, in the pierce configuration by connecting an external crystal. A 11.0592mhz crystal is selected which provides a internal cycle timing of 1sec (1mhz) which is 1/12 of the oscillator frequency. The clock generator divides the oscillator frequency by 2, and provides a twophase clock signal to the chip. The phase1 signal is active during the first half of each clock period, and phase2 signal is active during the second half of each clock period. Reset circuit Reset of the micro-controller chip is accomplished by holding the reset pin high for at least two machine cycles (24 oscillator periods) while oscillator is running. The cpu responds by executing an internal reset. The internal reset is executed during the second cycle in which reset is high and is repeated every cycle until reset goes low. An automated reset can be obtained when vcc is turned on by connecting the reset pin to a 10k resistor and 1f capacitor
7 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

When power comes on, the current through the resistor commences to charge the capacitor. The voltage at reset is the difference between vcc and the capacitor voltage, and decreases from vcc as the capacitor charges. The larger the capacitor is, the more slowly the voltage at the reset pin falls. The time required is the oscillator start up time plus 2 machine cycles. If the vcc rise-time is less than 1msec and the oscillator startup time does not exceed 10msec, a 1f capacitor will provide a reliable power on reset. IC LM35 (IC3) is a three-terminal precision temperature sensor whose output voltage is linearly proportional to the Celsius temperature with +/- 10.0 mV/ C scale factor. It thus has an advantage over linear temperature sensors calibrated in degree Kelvin, and the user is not required to subtract large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies. It is rated for full -55 C to 150 C ranges and operates off 4V-30V input. It gives 0V output for 0oC temperature .The analog output (Vout) at pin 2 of LM35 is fed to Vin (+) pin 6 of analog-to-digital converter ADC0804,whose Vin (-) pin is connected to ground .Pin 1 of LM35 is connected to 5V supply and pin 3 is grounded.

ADC0804 (IC2) is a CMOS, 8-bit single channel analog-to-digital converter .It features conversion time of less than 100ms , differential analog input voltage, TTLcompatible inputs and outputs, on-chip clock generator , analog voltage input range from 0V to 5V , and no zero adjustment . The conversion time depends on resister R3 and capacitor C6. The conversion rate in free running mode is 640 kHz. Digital and analog ground should be separated in ADC0804 to avoid any interference in the circuit. The resolution of 8-bit ADC0804 is 19.53 mV, which doesnt match with the scale factor cf LM35 and therefore can cause error. To avoid this error, the full-scale range of ADC0804 is made 0-2.56V by adjusting the voltage at pin 9 (Vref/2) to 1.28V through 1-

8 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

kilo-ohm preset VR2. In ADC0804, the input analog voltage is divided by its step size to give digital output. For each 10 mV rise and fall of the analog input at Vin (+), digital outputs at DB0 through DB7 increase and decrease, respectively. The maximum input voltage that can be converted by the ADC is 2.55v (10mV * 255), giving full-scale output of FF hex value in this system. The 8-bit digital output of ADC0804 (DB0 through DB7) is connected to 8-bit port P0 of the microcontroller. Signals signals with microcontroller IC1. is the output pin. Through , and and of the ADC are connected to P2.7, are the input pins of the ADC, while signal, the microcontroller gets to know P2.6 and P2.5 of the microcontroller. These signals of the ADC act as handshaking

when the conversion from analog into digital is completed by the ADC. The microcontroller makes WR pin low RD and pin high to start the conversion. Pin INTR goes high for the end oh conversion. A transition from high to low on INTR indicates end of conversion. Then the microcontroller makes RD low and WR high to read the 8-bit data at DB0 through DB7 through microcontroller port P0. Through its firmware, the microcontroller multiplies the digital input at port 0 with the steps size value of ADC0804 and then divides with the temperature / volt scale factor of LM35 to give the measured and calibrated oC temperature. The measured temperature is instantaneously displayed on the LCD. Port P1 of the microcontroller is connected to data port as well as The handshake signals of the LCD (RS, R/W and Enable) , respectively. All the data is sent to the LCD in ASCII form to display. Only the commands are sent in hex form to the LCD. RS signal is used to distinguish between data (RS=1) and command (RS=0). Use Present VR1 to control the contrast of the LCD. The motor driver circuit is connected to Port 3 which needs 3 pins i.e enable, Input 1 & input 2 of L293D IC5. By enabeling pin we can run the FAN. Rotating the FAN by giving input 1 is high & input 2 is low & by giving pulse or PWM (pulse width

9 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

modulation) signals the enable pin we can control the speed of the FAN. The speed is depends up on the on period of the enable signal. For proper measurement, adjust preset VR2 to give 1.28V at pin 9 of the ADC. Initially, using preset VR1set the contrast level for display on LCD.

Power supply: -

The 230V, 50Hz AC mains power supply is stepped down by transformer X1 to deliver a secondary output of 12V at 500mA. The transformer output is rectified by a full-wave bridge rectifier BR1, filtered by Capacitor C1, and regulated by IC 7805. The output of IC 7805 which is 5V used for operation of the circuit. The ripple in the regulator output is filtered by capacitor C2. For the DC motor the supply is taken before the regulator.

10 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

6.Software section Software operation flow chart

INITIALISE SP AND LCD

CONVERT ADC OUT TO TEMPERATURE ASCII VALUE

DISPLAY WELCOME MESSAGE

INCREASE NUMBER OF SAMPLES BY ONE

Start the temerature measuring

DISPLAY TEMPERATURE AND NUMBER OF SAMPLES

INITIALISE NUMBER OF SAMPLES TO ZERO

ZZZAZERO
START ADC WR=0>1 INTR=1

YES

TEMP>

NO

increase speed

Decrease speed

YES
INTR=1 ?

DELAY ACCORDING TO MEASURING INTERVAL

READ ADC RD=0

NO

11 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

Source code: The software is well commented and easy to understand. Written in C-language and assembled using Keil uvision -3, it works as per the flowchart shown in Fig. The hex code generated by the keil is burnt into the microcontroller using a suitable programmer. The value of the measured temperature and the number of samples taken until power-on are displayed on the LCD screen. The number of samples is updated according to the measuring interval. Each port of the microcontroller is made input through software by putting high on the respective pin or port. By default, all the ports act as output. Instead of using timer, nested loops are used to provide delay at various locations of the software. The values for the loop are calculated according to the crystal frequency and the machine cycles taken by the used instructions. Program: #include "lcd.h" #define adc_input P1 #define sec 100 sbit wr= P3^1; sbit rd= P3^0; sbit intr= P3^2; sbit m1= P3^3; sbit m2= P3^4; sbit en1=P3^5;

12 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

int s,temp_new; unsigned char i,j; int test_intermediate3=0,

test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};

void delay(unsigned int msec ) { int i ,j ; for(i=0;i<msec;i++) for(j=0; j<1275; j++); }

void shape() { lcd_cmd(64); lcd_data(2); lcd_data(5); lcd_data(2); lcd_data(0); lcd_data(0);

// Function to make the shape of degree symbol

13 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

lcd_data(0); lcd_data(0); lcd_data(0); }

void convert() to LCD {

// Function to convert the values of ADC into numeric value to be sent

lcd_cmd(0x80); lcd_str("Temp Base FAN SC"); delay(2); test_final=(((9*test_intermediate3)/5)+32); s=test_final/100; test_final=test_final%100; lcd_cmd(0x88); test_final=test_intermediate3; lcd_cmd(0xc1); delay(2); lcd_str("TEMP:"); s=test_final/100;
14 Government Polytechnic Tumkur

//Setting cursor to first position of first line

Microcontroller based Fan speed controller by measuring Temperature

test_final=test_final%100; lcd_cmd(0xc8); if(s!=0) lcd_data(s+48); else lcd_cmd(0x06); s=test_final/10; test_final=test_final%10; lcd_data(s+48); lcd_data(test_final+48); lcd_data(0); lcd_data('c'); lcd_data(' '); delay(2);

} void delaym(unsigned int value) { unsigned char y; for (y=0; y<value; y++) }
15 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

void main1() {

adc_input=0xff; delay(2); lcd_init(); delay(2); m1=1; m2=0; en1=0;

for(j=0;j<3;j++) { for(i=0;i<10;i++) { delay(2); delay(1); rd=1; wr=0; delay(1);


16 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

wr=1; while(intr==1); rd=0; lcd_cmd(0x88); test_intermediate1[i]=adc_input/10; delay(1); intr=1; } for(i=0;i<10;i++) test_intermediate2[j]=test_intermediate1[i]+test_intermediate2[j];

test_intermediate2[0]=test_intermediate2[0]/3; test_intermediate2[1]=test_intermediate2[1]/3; test_intermediate2[2]=test_intermediate2[2]/3;

test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2 ]; shape(); convert();

17 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

temp_new=s*10+test_final;

} void delayms2(int usec) { for (i=0;i<usec;i++); } void delayms1(int msec) { for (i=0;i<msec;i++) for (j=0;j<1275;j++); } void main() { m1=1; m2=0; while(1) {
18 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

main1(); while(j<20000) { en1=1; delayms2(150-temp_new); en1=0; delayms2(150-temp_new); } } }

19 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

7.PCB layouts 7.1 Bottom Side of PCB

7.1 Top Layer of PCB

20 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

7.2 3D view of PCB layout

21 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

8.Conclusion This project is an effort to demonstrate the worthiness of Atmel 89S52 IC for the operation of measuring temperature. It has own limitations which are very common in any of the project works from junior level technicians. The maximum temperature can measured by this project is 1500c and minimum is -550c only. With these draw backs this project is only used for areas such as 1. Measuring temperature in home or room. 2. Whre the power consumption is the main issur there by using our project the power can be saved like places Mobile towers. Although this project is just a simple of the capabilities of At 89S52 from Atmel corporation. With the forthcoming series of Atmel ICs from the company one can expect larger storing of system software and high operating speeds.

22 Government Polytechnic Tumkur

Microcontroller based Fan speed controller by measuring Temperature

9. Bibliography

1. Electronics For You of month September 2008 2.www.rickyworlds.info 3.www.8051projects.info 4. www.scienceprog.in 5. www.circuittoday.com 6. The 8051 microcontroller and embedded systems Mazdi & Mazdi 5. www.alldatasheet.com 6. www.8051projects.net 7. www.microcontrollerprojects.com 8. From the book hobby circuit.

Please add datasheets how much you want After read this, delete these two lines.
23 Government Polytechnic Tumkur

You might also like