You are on page 1of 6

For More Products Visit Our Website: www.amateurworld.

in

ATMEGA8 TEMPERATURE CONTROLLER


Basic object of this project is to control one Heater and one Fan to maintain constant temperature in an environment. For this we are using ATMEGA8L microcontroller as the main controller and LM35 for Temperature Sensor. One 16X2 LCD is attached with the microcontroller to display the Set Temperature Value and Present Temperature Value. LCD will also to display the status of Heater and FAN. For Heater we are using one Relay to control 230VAC Heater Element and we have attached on 12VDC Brushless DC FAN directly with the board. Working Principal: Whenever the system is switched ON, LCD will display SV (for SET Temperature Value) and PV (for Present Temperature Value) at the left side of the display. On the right side we will display the status of FAN (as FN) and Heater (as HT). We have interfaced three switches with the microcontroller. Now to change the SV, we have used two switches as UP switch and DWON switch. One another switch is left unused for further development of this project. Now on pressing UP switch, value of SV will increase and DOWN switch, value of SV will decrease. To do the main function of the project, i.e. controlling of FAN and HEATER, we use three compare functions in our software. To overcome the problem of frequently ON/OFF of HEATER and FAN, we assume Hysteresis of 10C, i.e. HEATER or FAN status will be changed if PV is out of +_ 10C. So, if PV is greater than +_ 10C of SV then FAN will be on to cool down the environment and if PV is bellow +_ 10C of SV then HEATER will be ON to increase the temperature of the environment. And when PV is within +_ 10C of SV, HEATER and FAN will be OFF. This is to note that in a moment either HEATER or FAN will be ON.

Page 1 of 6

AMATEUR WORLD

world of amateur electronics

www.amateurworld.in

For More Products Visit Our Website: www.amateurworld.in

SCHEMATIC DIAGRAM:

SOFTWARE: Software is written in BASCOM AVR, Basic language. It is just plain English like language and easy to understand and easy to write. Bellow is the complete code. 'ATMEGA8 TEMPARATURE CONTROLLER PROJECT 'FOR B.TECH STUDENTS 'CONTROLLER: ATMEGA8 'Dated 20/03/2012 'MAIN OBJECTIVE OF THIS PROJECT IS TO MEASURE AND DISPLAY TEMPERATURE 'AND CONTROL HEATER & FAN TO MAINTAIN SET TEMPERATURE 'FOR TEMPERATURE, LM35 TEMPERATURE SENSOR IS USED '********************************************************* '$sim $regfile = "m8def.dat" $crystal = 8000000 ' 8 MHz crystal $swstack = 40 $hwstack = 32 $framesize = 32 '********************************************************* ' CONFIGURE 16X2 LCD '********************************************************* Config Lcd = 16 * 2

Page 2 of 6

AMATEUR WORLD

world of amateur electronics

www.amateurworld.in

For More Products Visit Our Website: www.amateurworld.in


Config Lcdpin = Pin , Db4 = Portb.3 , Db5 = Portb.2 , Db6 = Portb.1 , Db7 = Portb.0 , E = Portb.4 , Rs = Portb.5 Cursor Off 'MAKE CURSOR OFF '********************************************************* ' CONFIGURE ADC FOR MEASUREMENT OF LM35 '********************************************************* Config Adc = Single , Prescaler = Auto , Reference = Avcc Start Adc '********************************************************* ' DECLARATION OF I/0 '********************************************************* Config Pind.5 = Input Config Pind.6 = Input Config Pind.7 = Input Menu Alias Pind.5 Up Alias Pind.6 Down Alias Pind.7 Config Portd.3 = Output Config Portd.4 = Output Fan Alias Portd.3 Heater Alias Portd.4 Fan = 0 'MAKE FAN OFF Heater = 0 'MAKE HEATER OFF '********************************************************* ' DECLARATION OF VARIABLES '********************************************************* Dim W As Word , W_single As Single , W_avg As Single Dim Pv As Integer Dim Gp As Byte Dim Sv As Integer , Sv_s As Eram Integer Dim Hv_h As Integer , Hv_l As Integer '********************************************************* Deflcdchar 0 , 4 , 14 , 31 , 14 , 4 , 32 , 32 , 32 ' replace [x] with number (0-7) Cls 'CLEAR DISPLAY Lcd "PV=" ; Spc(3) ; Chr(0) ; "C" ; Spc(2) ; "HT=" Lowerline Lcd "SV=" ; Spc(3) ; Chr(0) ; "C" ; Spc(2) ; "FN=" Sv = Sv_s Main: Gosub Measure_lm35 Gosub Check_temp Debounce Up , 0 , Sv_up Debounce Down , 0 , Sv_down Goto Main '******************************************************** 'HEAR WE MEASURE TEMPERATURE FROM LM35 SENSOR 'FIRST WE MEASURE THE ADC COUNT AT 'W' 'AS WE KNOW ADC WILL COUNT MAXIMUM VALUE(1024) AT 5V 'WE CAN PER COUNT VALUE BY THE FORMULA, Page 3 of 6 AMATEUR WORLD world of amateur electronics www.amateurworld.in

For More Products Visit Our Website: www.amateurworld.in


'W_SINGLE=(WX5)/1024=WX0.005 'I.E. EACH COUNT IS EQUAL TO 5mV 'NOW FROM DATA SHEET OF LM35 WE KNOW THAT LM35 WILL 'OUTPUT 10mV PER DEGREE CENTRIGATE 'SO EACH COUNT=W_SINGLE/2 DEGREE CENTRIGATE 'FOR ACCURACY WE TAKE 100 SAMPLE AND THEN TAKE AVARAGE '******************************************************** Measure_lm35: W_avg = 0 For Gp = 1 To 100 W = Getadc(0) 'W_single = W * 5 'CHECK MATH FOR LM35 'W_single = W_single / 1024 'W_single = W_single / 2 If W <> 0 Then W_single = W / 2 Else W_single = 0 End If W_avg = W_avg + W_single Next Gp If W_avg <> 0 Then W_avg = W_avg / 100 'MAKE AVAGARE OF DISPLAY Else W_avg = 0 End If Pv = W_avg 'TO IGNORE THE FRACTION Locate 1 , 4 'LOCATE THE DISPALY VALUE LOCATION Lcd Spc(3) 'ERASE OLD VALUE Locate 1 , 4 'LOCATE THE DISPLAY VALUE LOCATION Lcd Pv 'DISPLAY THE CURRENT VALUE Locate 2 , 4 Lcd Spc(3) Locate 2 , 4 Lcd Sv 'DISPLAY THE SET VALUE Return '******************************************************** 'HERE WE INCREASE SET TEMPERATURE VALUE BY 1 '******************************************************** Sv_up: Incr Sv 'INCREMENT SV BY 1 If Sv > 110 Then Sv = 0 End If Sv_s = Sv 'SAVE SV AT EEPROM Locate 2 , 4 Lcd Spc(3) Locate 2 , 4 Lcd Sv Goto Main Page 4 of 6 AMATEUR WORLD world of amateur electronics www.amateurworld.in

For More Products Visit Our Website: www.amateurworld.in


'******************************************************** 'HERE WE DECREASE SET TEMPERATURE VALUE BY 1 '******************************************************** Sv_down: If Sv <> 0 Then Decr Sv 'DECREASE SV BY 1 Else Sv = 110 End If Sv_s = Sv 'SAVE SV AT EEPROM Locate 2 , 4 Lcd Spc(3) Locate 2 , 4 Lcd Sv Goto Main '******************************************************* Check_temp: Hv_h = Sv + 1 'HYSTERISYS=1 If Pv >= Hv_h Then Fan = 1 'TURN ON THE FAN Heater = 0 'TURN OFF HEATER Locate 1 , 14 Lcd Spc(3) Locate 1 , 14 Lcd "OFF" Locate 2 , 14 Lcd Spc(3) Locate 2 , 14 Lcd "ON" End If Hv_l = Sv - 1 'HYSTERISYS=1 If Pv <= Hv_l Then Fan = 0 'TURN OFF FAN Heater = 1 'TURN ON HEATER Locate 1 , 14 Lcd Spc(3) Locate 1 , 14 Lcd "ON" Locate 2 , 14 Lcd Spc(3) Locate 2 , 14 Lcd "OFF" End If If Pv > Hv_l And Pv < Hv_h Then Fan = 0 'TURN OFF FAN Heater = 0 'TURN OFF HEATER Locate 1 , 14 Lcd Spc(3) Locate 1 , 14 Lcd "OFF" Page 5 of 6 AMATEUR WORLD world of amateur electronics www.amateurworld.in

For More Products Visit Our Website: www.amateurworld.in


Locate 2 , 14 Lcd Spc(3) Locate 2 , 14 Lcd "OFF" End If Return '************************************************************ End 'end program

Page 6 of 6

AMATEUR WORLD

world of amateur electronics

www.amateurworld.in

You might also like