You are on page 1of 54

AUTOMATIC TEMPERATURE CONTROL SYSTEM

A PROJECT REPORT
Submitted by
JYOTHIS JOSE

K. NEERAJLAL

K.C JISHNU

In partial fulfillment for the award of the degree

Of

B.TECH
IN

ELECTRONICS AND COMMUNICATION

SREE NARAYANA GURUKULAM COLLEGE OF ENGINEERING

MG UNIVERSITY: KOTTAYAM
MAY 2011

1
Department of Electronics and communication Engineering

MINI PROJECT REPORT 2011

BONAFIDE CERTIFICATE

Certified that this project report “AUTOMATIC TEMPERATURE CONTROL


SYSTEM” is the bonafide work of “JYOTHIS JOSE, K.NEERAJLAL AND
K.C.JISHNU” who carried out the project work under my supervision.

SIGNATURE SIGNATURE

PROF. ARUMUGAM SWAMY Mr. DEEPAK.P

HEAD OF THE DEPARTMENT STAFF IN CHARGE

ELECTRONICS AND COMMUNICATION ENGINEERING DEPT. OF ECE

SREE NARAYANA GURUKULAM COLLEGE OF ENGINEERING S.N.G.C.E.

KADAYIRUPPU. KADAYIRUPPU.

KOLENCHERY KOLENCHERY

2
ACKNOWLEDGEMENT

Dedicating this project to the God Almighty whose abundant grace and mercies
enabled its successful completion, we would like to express our profound gratitude to
all the people who had inspired and motivated us to make this project a success.

We wish to express our sincere thanks to our Principal, Dr.C.E.KRISHNAN, for


providing an opportunity to undertake this project. We are deeply indebted to our
project coordinator Prof.ARUMUGHA SAMY Head of the Department of
Electronics and Communication Engineering for providing us with valuable advice
during the course of the study.

We would like to extend our heartfelt gratitude to our guides Mr.DEEPAK.P, Mr.
VISHNU and Mr. MAHESH for helps extended to us during the completion of the
project. We extend our deep sense of gratitude to our Lecturers of Electronics and
Communication Engineering Department for their valuable guidance as well as
timely advice, which helped us a lot in completing the project successfully. Finally
we would like to express my gratitude to Sree Narayana Gurukulam College of
Engineering for providing us with all the facilities without which the project would
not been possible.

3
ABSTRACT

The objective is to design and implement an automated Temperature control system


using embedded system design in order to control the temperature of a system. As
such, it is vital that those in engineering fields understand the technologies associated
with this area. My project will include the design and construction of a
microcontroller-based automated Temperature control system along with a
temperature display using LCD. A working system will ultimately be demonstrated to
validate the design. The system made is only a prototype. A larger system can be
made using this prototype as a model.

4
TABLE OF CONTENTS

CHAPTER NO TITLE PAGE NO

LIST OF FIGURES 6

1 INTRODUCTION 7

2 BLOCK DIAGRAM 8

3 BLOCK DIAGRAM EXPLANATION 9

3.1 LM35 10

3.2 LCD [JHD162A] 11

3.3 MICROCONTROLLER [16F873] 13

3.4 L293D 23

4 CIRCUIT DIAGRAM 24

4.1 WORKING 25

4.2 POWER SUPPLY 26

5 ALGORITHM 27

6 PROGRAM 29

6.1 PROGRAM BASED WORKING 41

7 PCB LAYOUT 43

7.1 PCB FABRICATION 44

8 FUTURE MODIFICATION 51

9 CONCLUSION 52

10 REFERENCE 53

11 APPENDICES 54

5
LIST OF FIGURES

1. BLOCK DIAGRAM

2. LM 35 PINOUT

3. LCD JHD162A

4. PIC 16F873 PINOUT

5. L293D PINOUT

6. CIRCUIT DIAGRAM

7. POWER SUPPLY

8. 7805 PINOUT

9. PCB LAYOUT

6
1. INTRODUCTION
The concept of this project is to create an Automatic Temperature Control System to
control the temperature of a system. The circuit maintains the temperature of the
system in a particular range. The fan RPM increases with increase in temperature and
vice versa. For the circuit, it consists of Temperature Sensing Unit, PIC 16F873A µC,
LCD Module, Switching Device, Driver, PWM generator, a Fan and a Heater. It will
operate based on the values or ranges of temperature in the system which is detected
by the Temperature Sensor.

The Temperature Sensor detects the temperature of the system. The


Temperature Sensor consists of an LM35 IC. The temperature sensor is connected to
the ADC input of the PIC µC. It converts the analog input to a digital value. The PIC
is connected to a switching device relay. It is used to switch on the heater. The PIC
generates PWM according to the temperature sensor value. The PWM generated
output control signals are sent to the Motor Driver IC L293D. Motor Driver IC
L293D is fed with the PWM generated output from PIC. By using the L293D, two dc
motors can be connected. The speed of the fan is controlled by the ON time of the
PWM generated by the controller. With increasing ON time, the speed of the fan or
the heater increases reducing the temperature of the system. The LCD module is also
connected to the PIC microcontroller. The LCD module displays the current
temperature. The LCD display used is a 16x2 Alphanumeric Display with code
LM016L. It is a parallel LCD which is connected to the microcontroller I/O ports
using 4 data lines and 3 control lines.

7
2. BLOCK DIAGRAM

Figure 1

8
3. BLOCK DIAGRAM EXPLANATION

The basic blocks of the System include the following blocks; Temperature Sensing
circuit, PIC 16F873A µC, LCD Display, Switching and Drivers, Fan and Heater. The
Temperature Sensor detects the temperature of the system. The Temperature Sensor
consists of an LM35 IC. It has the measuring range of -55°C to 150 °C. The
temperature sensor is connected to an ADC of PIC µC. The LCD module is also
connected to the PIC microcontroller. The LCD module displays the current
temperature. The LCD display used is a 16x2 Alphanumeric Display. The PIC µC
switches on the heater using a relay. The PIC µC generates PWM signal according to
the temperature. The PWM generated output control signals are sent to the Driver IC.
Driver IC L293D is fed with the PWM generated output. The speed of the fan is
controlled by the ON time of the PWM generated. With increasing ON time, the
speed of the fan or the heater increases, thus controlling the temperature of the
system.

9
3.1 LM35

The LM35 series are precision integrated-circuit temperature sensors, whose output
voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35
thus has an advantage over linear temperature sensors calibrated in° Kelvin, as the
user is not required to subtract a 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 of ±1⁄4°C at room temperature and ±3⁄4°C
over a full −55 to +150°C temperature range. Low cost is assured by trimming and
calibration at the wafer level. The LM35’s low output impedance, linear output, and
precise inherent calibration make Interfacing to readout or control circuitry especially
easy. It can be used with single power supplies, or with plus and minus supplies. As it
draws only 60 µA from its supply, it has very low self-heating, less than 0.1°C in still
air. The LM35 is rated to operate over a −55° to +150°C temperature range, while the
LM35C is rated for a −40° to +110°C range (−10°with improved accuracy).

LM 35 PINOUT

Figure 2

10
3.2 LCD (JHD162A)

Figure 3

11
Pin 1 and 2 are the power supply pins. They need to be connected to the negative rail
and the positive rail of a +5v power supply respectively. To get a stable +5v Power
supply, we can use a7805 voltage regulator.

Pin 3 is the contrast setting pin. It must be connected to a potentiometer to control the
contrast. The lower the resistance, the greater the contrast Pins 4, 5 and 6 are control
pins of the LCD. I’ll explain about them later on in the post.

Pins 7 to 14 are the Data pins of the LCD. Pin 7 is the Least Significant Bit
(LSB) and pin 14 is the Most Significant Bit (MSB) of the data inputs. If we want to
display some number or letter on the display, we have to input the appropriate
‘codes’ for that character on these pins. These pins are also used for giving certain
commands to the display like clearing the display or moving the cursor to a different
location. Upon giving the correct signals to the 3 control pins, the character codes or
the commands that you have given to the Data pins will be written to the display or
executed by the LCD respectively.

12
3.3 MICROCONTROLLER [PIC 16F873A]

The microcontroller used in the project is PIC16F873A. It is a 28 pin IC. PIC µC’s
are manufactured by Microchip Technology. It has 4 KB of CMOS Flash Program
Memory, 128 bytes of Data EEPROM Data Memory and 192 bytes of RAM
memory. It works at clock frequency of 4 MHz It has operating voltage range of 2-
5.5V.It has 3 I/O ports namely, Port A (6 pins), Port B (8 pins) & Port C (8 pins).

PORT A is a 6-bit wide, bi-directional port. The corresponding data direction register
is TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an
input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a
TRISA bit (= 0) will make the corresponding PORTA pin an output (i.e., put the
contents of the output latch on the selected pin).Reading the PORTA register reads
the status of the pins, whereas writing to it will write to the port latch. All Write
operations are read-modify-write operations. Therefore, a write to a port implies that
the port pins are read; the value is modified and then written to the port
Data latch. Pin RA4 is multiplexed with the Timer0 module clock input to become
the RA4/T0CKI pin. The RA4/T0CKIpin is a Schmitt Trigger input and an open
drain output. All other PORTA pins have TTL input levels and full CMOS output
drivers. Other PORTA pins are multiplexed with analog inputs and analog VREF
input. The operation of each pin is selected by clearing/setting the control bits in
theADCON1 register (A/D Control Register1).The TRISA register controls the
direction of the RA pins, even when they are being used as analog inputs. The user
must ensure the bits in the TRISA register are maintained set when using them as
analog inputs.

PORT B is an 8-bit wide, bi-directional port. The corresponding data direction


register is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin
13
an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing
a TRISB bit (= 0) will make the corresponding PORTB pin an output (i.e., put the
contents of the output latch on the selected pin).Three pins of PORTB are
multiplexed with the Low Voltage Programming function: RB3/PGM, RB6/PGC and
RB7/PGD. The alternate functions of these pins are described in the Special Features
Section. Each of the PORTB pins has a weak internal pull-up. A single control bit
can turn on all the pull-ups. This is performed by clearing bit RBPU
(OPTION_REG<7>). The weak pull-up is automatically turned off when the port pin
is configured as an output. The pull-ups are disabled on a Power-on Reset.
Four of the PORTB pins, RB7:RB4, have an interruption-change feature. Only pins
configured as inputs can cause this interrupt to occur (i.e., any RB7:RB4 pin
Configured as an output is excluded from the interruption-change comparison). The
input pins (of RB7:RB4) are compared with the old value latched on the last read of
PORTB. The “mismatch” outputs of RB7:RB4are OR’ ed together to generate the
RB Port Change Interrupt with flag bit RBIF (INTCON<0>).

PORT C is an 8-bit wide, bi-directional port. The corresponding data direction


register is TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin
an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing
a TRISC bit (= 0) will make the corresponding PORTC pin an output (i.e., put the
contents of the output latch on the selected pin).
PORTC is multiplexed with several peripheral functions. PORTC pins have Schmitt
Trigger input buffers. When the I2C module is enabled, the PORTC<4:3> pins can be
configured with normal I2C levels or with SM Bus levels by using the CKE bit
(SSPSTAT<6>). When enabling peripheral functions, care should be taken in
defining TRIS bits for each PORTC pin. Some peripherals override the TRIS bit to
make a pin an output, while other peripherals override the TRIS bit to make a pin an
14
input. Since the TRIS bit override is in effect while the peripheral is enabled, read-
modify write instructions (BSF, BCF, XORWF) with TRISC as destination, should
be avoided. The user should refer to the corresponding peripheral section for the
correct TRIS bit settings.

Two 8 bit Timers, Timer 0, Timer 2 & a 16 bit Timer, Timer 1.

TIMER0 MODULE

The Timer0 module timer/counter has the following features:

• 8-bit timer/counter
• Readable and writable
• 8-bit software programmable prescaler
• Internal or external clock select
• Interrupt on overflow from FFh to 00h
• Edge select for external clock

Timer mode is selected by clearing bit T0CS (OPTION_REG<5>). In Timer mode,


the Timer0 module will increment every instruction cycle (without prescaler). If the
TMR0 register is written, the increment is inhibited for the following two instruction
cycles. The user can work around this by writing an adjusted value to the TMR0
register. Counter mode is selected by setting bit T0CS (OPTION_REG<5>). In
Counter mode, Timer0 will increment either on every rising, or falling edge of pin
RA4/T0CKI. The incrementing edge is determined by the Timer0 Source Edge Select

15
bit, T0SE (OPTION_REG<4>). Clearing bit T0SE selects the rising edge. The
prescaler is mutually exclusively shared between the Timer0 module and the
Watchdog Timer. The prescaler is not readable or writable.

TIMER0 INTERRUPT

The TMR0 interrupt is generated when the TMR0 register overflows from FFh to
00h. This overflow sets bit T0IF (INTCON<2>). The interrupt can be masked by
clearing bit T0IE (INTCON<5>). Bit T0IF must be cleared in software by the Timer0
module Interrupt Service Routine before re-enabling this interrupt. The TMR0
interrupt cannot awaken the processor from SLEEP, since the timer is shut-off during
SLEEP.

TIMER1 MODULE

The Timer1 module is a 16-bit timer/counter consisting of two 8-bit registers


(TMR1H and TMR1L), which are readable and writable. The TMR1 Register pair
(TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. The
TMR1 Interrupt, if enabled, is generated on overflow, which is latched in interrupt
flag bit TMR1IF (PIR1<0>). This interrupt can be enabled/disabled by
setting/clearing TMR1 interrupt enable bit TMR1IE (PIE1<0>). Timer1 can operate
in one of two modes:
• As a timer
• As a counter
The operating mode is determined by the clock select bit, TMR1CS (T1CON<1>).

16
In Timer mode, Timer1 increments every instruction cycle. In Counter mode, it
increments on every rising edge of the external clock input. Timer1 can be
enabled/disabled by setting/clearing control bit TMR1ON (T1CON<0>). Timer1 also
has an internal “RESET input”. This RESET can be generated by either of the two
CCP modules (Section 8.0). Register 6-1 shows the Timer1control register. When the
Timer1 oscillator is enabled (T1OSCEN is set), the RC1/T1OSI/CCP2 and
RC0/T1OSO/T1CKI pins become inputs. That is, the TRISC<1:0> value is ignored,
and these pins read as ‘0’.

TIMER2 MODULE

Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be used as the PWM
time-base for the PWM mode of the CCP module(s). The TMR2 register
is readable and writable, and is cleared on any device RESET. The input clock
(FOSC/4) has a prescale option of 1:1, 1:4, or 1:16, selected by control bits
T2CKPS1:T2CKPS0 (T2CON<1:0>). The Timer2 module has an 8-bit period
register, PR2. Timer2 increments from 00h until it match PR2 and then resets to 00h
on the next increment cycle. PR2 is a readable and writable register. The PR2 register
is initialized to FFh upon RESET. The match output of TMR2 goes through a 4-bit
postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a TMR2 interrupt
(latched in flag bit TMR2IF, (PIR1<1>)). Timer2 can be shut-off by clearing control
bit TMR2ON (T2CON<2>), to minimize power consumption.

17
INTERRUPTS

PIC 16873A has up to 14 sources of interrupts. The interrupt control register


(INTCON) records individual interrupt requests in flag bits. It also has individual and
global interrupt enable bits. A global interrupt enable bit, GIE (INTCON7) enables (if
set) all unmasked interrupts, or disables (if cleared) all interrupts. When bit GIE is
enabled, and an interrupt’s flag bit and mask bit are set, the interrupt will vector
immediately. Individual interrupts can be disabled through their corresponding enable
bits in various registers. Individual interrupt bits are set, regardless of the status of the
GIE bit. The GIE bit is cleared on RESET. The “return from interrupt” instruction,
RETFIE, exits the interrupt routine, as well as sets the GIE bit, which re-enables
interrupts. The RB0/INT pin interrupt, the RB port change interrupt, and the TMR0
overflow interrupt flags are contained in the INTCON register.

The peripheral interrupt flags are contained in the special function registers, PIR1 and
PIR2. The corresponding interrupt enable bits are contained in special function
registers, PIE1 and PIE2, and the peripheral interrupt enable bit is contained in
special function register INTCON. When an interrupt is responded to, the GIE bit is
cleared to disable any further interrupt, the return address is pushed onto the stack
and the PC is loaded with 0004h. Once in the Interrupt Service Routine, the source(s)
of the interrupt can be determined by polling the interrupt flag bits.

INT INTERRUPT

External interrupt on the RB0/INT pin is edge triggered, either rising, if bit INTEDG
(OPTION_REG<6>) is set, or falling, if the INTEDG bit is clear. When a valid edge
appears on the RB0/INT pin, flag bit INTF (INTCON<1>) is set. This interrupt can
be disabled by clearing enable bit INTE (INTCON<4>). Flag bit INTF must be
18
cleared in software in the Interrupt Service Routine before re-enabling this interrupt.
The INT interrupt can wake-up the processor from SLEEP, if bit INTE was set prior
to going into SLEEP. The status of global interrupt enable bit, GIE, decides whether
or not the processor branches to the interrupt vector following wake-up. See Section
12.13 for details on SLEEP mode.

TMR0 INTERRUPT

An overflow (FFh → 00h) in the TMR0 register will set flag bit T0IF (INTCON<2>).
The interrupt can be enabled/disabled by setting/clearing enable bit T0IE
(INTCON<5>).

PORTB INTCON CHANGE

An input change on PORTB<7:4> sets flag bit RBIF (INTCON<0>). The interrupt
can be enabled/disabled by setting/clearing enable bit RBIE (INTCON<4>).

DATA EEPROM AND FLASH PROGRAM MEMORY

The Data EEPROM and FLASH Program Memory are readable and writable during
normal operation over the entire VDD range. These operations take place on a single
byte for Data EEPROM memory and a single word for Program memory. A write
operation causes an erase-then-write operation to take place on the specified byte or
word. A bulk erase operation may not be issued from user code (which includes
removing code protection). Access to program memory allows for checksum
calculation. The values written to program memory do not need to be valid
instructions. Therefore, up to 14-bit numbers can be stored in memory for use as
calibration parameters, serial numbers, packed 7-bit ASCII, etc. Executing a program

19
memory location containing data that form an invalid instruction, results in the
execution of a NOP instruction. The EEPROM Data memory is rated for high erase/
writes cycles (specification D120). The FLASH program memory is rated much
lower (specification D130), because EEPROM data memory can be used to store
frequently updated values. An on-chip timer controls the write time and it will vary
with voltage and temperature, as well as from chip to chip. Please refer to the
specifications for exact limits (specifications D122 and D133). A byte or word write
automatically erases the location and writes the new value (erase before write).
Writing to EEPROM data memory does not impact the operation of the device.
Writing to program memory will cease the execution of instructions until the write is
complete. The program memory cannot be accessed during the write. During the
write operation, the oscillator continues to run, the peripherals continue to function
and interrupt events will be detected and essentially “queued” until the write is
complete. When the write completes, the next instruction in the pipeline is executed
and the branch to the interrupt vector will take place, if the interrupt is enabled and
occurred during the write. Read and write access to both memories take place
indirectly through a set of Special Function Registers
(SFR). The six SFRs used are:
• EEDATA
• EEDATH
• EEADR
• EEADRH
• EECON1
• EECON2
The EEPROM data memory allows byte read and writes operations without
interfering with the normal operation of the microcontroller. When interfacing to
EEPROM data memory, the EEADR register holds the address to be accessed.
20
Depending on the operation, the EEDATA register holds the data to be written, or the
data read, at the address in EEADR. The PIC16F873/874 devices have 128 bytes of
EEPROM data memory and therefore, require that the MSb of EEADR remain clear.
The EEPROM data memory on these devices does not wrap around to 0, i.e., 0x80 in
the EEADR does not map to 0x00. The PIC16F876/877 devices have 256 bytes of
EEPROM data memory and therefore, use all 8-bits of the EEADR. The FLASH
program memory allows non-intrusive read access, but writes operations cause the
device to stop executing instructions, until the write completes. When interfacing to
the program memory, the EEADRH: EEADR registers form a two-byte word, which
holds the 13-bit address of the memory location being accessed. The register
combination of EEDATH: EEDATA holds the 14-bit data for writes, or reflects the
value of program memory after a read operation. Just as in EEPROM data memory
accesses, the value of the EEADRH: EEADR registers must be within the valid range
of program memory, depending on the device: 0000h to 1FFFh for the
PIC16F873/874, or 0000h to 3FFFh for the PIC16F876/877. Addresses outside of
this range do not wrap around to 0000h (i.e., 4000h does not map to 0000h on the
PIC16F877).

21
PIN OUT OF 16F873

Figure 4

22
3.4 L293D [MOTOR DRIVER IC]

PINOUT

Figure 5

Pinout shows that L293D consists of four inputs (A), which accepts TTL logic
voltage level and four outputs (Y) that gives VCC2 Voltage. That allows L293D to be
used as two "reversible" output or four "one-way" outputs. There are two more TTL
inputs (EN), which stands for enable. This means that pin 1 (1,2EN) enables outputs
1Y and 2Y. Without pin 1 set to logical 1, the outputs will remain inactive.
The enable inputs are usually hooked to +5V to be set still. In "motor driving"
applications, enable inputs are called slow stop and it's used for speed control.
Switching from logical 1 to logical 0 causes motor to rotate accordingly to the
switching interval.

23
4. CIRCUIT DIAGRAM

Figure 6

24
4.1. WORKING

The circuit maintains the temperature of the system in a particular range. A fan and a
heater are used for controlling the temperature of the system. The fan RPM increases
with increase in temperature and vice versa. The working of the heater is also the
same. The current temperature within the server room is measured by using a
temperature sensor. When the current temperature is below the lower limit of the
desired range, the system must be heated by using a heating element, air heater.
When the current temperature is below the lower limit of the desired range, the
system must be cooled by using a fan. When the current temperature is within or
successfully turned back to the required range, no control action is needed. The
current temperature of the room must be continuously displayed on the LCD. The
controller should use LEDs as backup display to indicate the current state of
temperature .This makes user is easily to know current temperature of the system.

The Temperature Sensor detects the temperature of the system. The


Temperature Sensor consists of an LM35 IC. The temperature sensor is connected to
the ADC input of the PIC µC. It converts the analog input to a digital value. The PIC
is connected to a switching device relay. It is used to switch on the heater. The PIC
generates PWM according to the temperature sensor value. The PWM generated
output control signals are sent to the Motor Driver IC L293D. Motor Driver IC
L293D is fed with the PWM generated output from PIC. By using the L293D, two dc
motors can be connected. The speed of the fan is controlled by the ON time of the
PWM generated by the controller. With increasing ON time, the speed of the fan or
the heater increases reducing the temperature of the system. The LCD module is also
connected to the PIC microcontroller. The LCD module displays the current
temperature.

25
4.2 POWER SUPPLY

Figure 7

The PIC16F873 requires a regulated 5 volt supply voltage. The 7805 voltage
regulator is used to provide for that. The 7805 takes in a voltage between 7 and 30
volts and regulates it down to exactly 5 volts. The first capacitor takes out any ripple
coming from the transformer so that the 7805 is receiving a smooth input voltage,
and the second capacitor acts as a load balancer to ensure consistent output from
the 7805. The 7805 has three leads. If we look at the 7805 from the front (the side
with printing on it), the three leads are, from left to right, input voltage (7 to 30
volts), ground, and output voltage (5 volts).

Figure 8

26
5. ALGORITHM
1. Initialize Ports, LCD and Motor Driver IC Input.

2. Display project name on LCD.

3. Clear LCD.

4. Display set temperature range on LCD.

5. Read Analog Voltage Value from Temperature Sensor on AN0 of PIC.

6. Temperature = Voltage / 10

7. If Temperature < Lower Temperature Range then

7.1. Switch ON Heater


7.2. Switch OFF FAN

8. If Temperature >= Lower Temperature Range & Temperature <= Upper


Temperature then

8.1. Switch OFF Heater


8.2. Switch OFF FAN

9. If Temperature > Upper Temperature Range then

27
9.1. Switch OFF Heater
9.2. Switch ON FAN and control its speed using PWM generation

10.Display Current Temperature range on LCD.

11.Repeat Steps 5 to 11 infinitely.

28
6. PROGRAM

main.c

/*
AUTOMATIC TEMPERATURE CONTROL SYSTEM
PIC 16F873A
*/

#include <pic.h>
#include <stdio.h>
#include "lcd.h"
#include "delay.h"

#define lower 36.0


#define upper 38.0

#define HEATER RA1


#define ON 1
#define OFF 0

#define PWMOUT RC1


#define MOTORINPUT4 RC7
#define MOTORINPUT3 RC6

29
// ***************************************************
// Function Definitions
void IntToStr(int volt)
{
int h1,h2,h3,d1,d2,d3;

h1=(volt/100);
d1=h1+0x30;
DelayMs(1);
LCD_data(d1);

h2=volt/10;
h2=h2%10;
d2=h2+0x30;
DelayMs(1);
LCD_data(d2);
LCD_data(0x2E);

h3=volt%10;
d3=h3+0x30;
DelayMs(1);
LCD_data(d3);
}

// ADC Function
unsigned int ADC()
{
30
TRISC2 = 0;
ADCON1=0x8E;
ADCON0 = 0x01;
DelayMs(1);
ADCON0 = 0x05;

ADGO = 1;
while(ADGO == 1);

return ( ( ADRESH << 8 ) | ADRESL );


}

// PWM Function
void PWM_Gen(float volt)
{
float error;

CCP2CON=0x0F; // PWM Mode


PR2=0xFF;
T2CON=0x05; // Timer2 ON

error = volt - upper;

MOTORINPUT4=1;
MOTORINPUT3=0;

if(error<=1.0)
31
{
CCP2CON=0x2F;
CCPR2L=0x24;
}
else if(error>1.0 && error<=2.0)
{
CCP2CON=0x3F;
CCPR2L=0x7F;
}
else if(error>2.0 && error<=3.0)
{
CCP2CON=0x0F;
CCPR2L=0xB3;
}
else
{
CCP2CON=0x3F;
CCPR2L=0xFF;
}
}

// ***************************************************
// Main Function
void main()
{
unsigned char str[20]={0};
int i;
32
float volt, avg;

TRISA = 0x01;

lcd_init();

MOTORINPUT4=0;
MOTORINPUT3=0;

LCD_cmd(0x82);
LCD_string("TEMPERATURE");
LCD_cmd(0xC1);
LCD_string("CONTROL SYSTEM");

for(i=0; i<5; i++)


DelayMs(250);

LCD_cmd(0x01);
LCD_cmd(0x02);

sprintf(str, "SET TEMP:%d-%d", lower, upper);


LCD_string(&str[0]);
LCD_data(0xDF);
LCD_string("C");

LCD_cmd(0xC0);
LCD_string("TEMP: ");
33
LCD_cmd(0xCA);
LCD_data(0xDF);
LCD_string("C");

while(1) // Loop Infinitely


{
volt = ADC(); // Read voltage on AN0
volt *= 4.88;
avg = avg/10;
volt = volt/10; // Temperature = Sensor Output Voltage / 10

if(volt<lower)
{
MOTORINPUT3 = MOTORINPUT4 = OFF; // Motor is OFF
CCP2CON=0x00;
HEATER = ON; // Heater is ON
}
else if((volt>=lower)&&(volt<=upper))
{
MOTORINPUT3 = MOTORINPUT4 = OFF; // Motor is OFF
CCP2CON=0x00;
HEATER = OFF; // Heater is OFF
}
else if(volt>upper)
{
HEATER = OFF; // Heater is OFF
PWM_Gen(volt); // Motor is ON
34
}

LCD_cmd(0xC6);
IntToStr(avg);

for(i=0; i<4; i++)


DelayMs(250);
}
}

lcd.h

void lcd_init();
void LCD_cmd(char);
void LCD_data(char);
void LCD_string(const char *DATA);

lcd.c

#include <pic.h>
#include "delay.h"
#include "lcd.h"
35
#define RS RC3
#define RW RC4
#define E RC6

void lcd_init()
{
TRISB=0x00; // Data Lines
TRISC=0x00; // Control Lines

DelayMs(15); // Power on delay

LCD_cmd(0x28); // 4 bit mode, 5x7 font


LCD_cmd(0x28);
LCD_cmd(0x28);

LCD_cmd(0x08); // Cursor blink off


LCD_cmd(0x06); // Entry mode
LCD_cmd(0x01); // Clear display
LCD_cmd (0x80); // Force Cursor to first row first column
}

void LCD_cmd(char a)
{
PORTB = a & 0xF0;
RS=0;
RW=0;
36
E=1;
DelayUs(5);
E=0;
DelayUs(1);

PORTB = ( a & 0x0F ) << 4;


RS=0;
RW=0;
E=1;
DelayUs(5);
E=0;
DelayMs(15);
}

void LCD_data(char a)
{
PORTB = a & 0xF0);
RS=1;
RW=0;
E=1;
DelayUs(5);
E=0;
DelayUs(1);

PORTB = ( a & 0x0F ) << 4;


RS=1;
37
RW=0;
E=1;
DelayUs(5);
E=0;
DelayMs(15);
}

void LCD_string(const char *DATA)


{
while(*DATA)
LCD_data(*DATA++);
}

38
delay.h

#ifndef XTAL_FREQ
#define XTAL_FREQ 4MHZ /* Crystal frequency in MHz */
#endif
#define MHZ *1000L /* number of kHz in a MHz */
#define KHZ *1 /* number of kHz in a kHz */

#if XTAL_FREQ >= 12MHZ


#define DelayUs(x) { unsigned char _dcnt; _dcnt =
(x)*((XTAL_FREQ)/(12MHZ)); \
while(--_dcnt != 0) continue; }
#else

#define DelayUs(x) { unsigned char _dcnt; _dcnt =


(x)/((12MHZ)/(XTAL_FREQ))|1; \
while(--_dcnt != 0) continue; }
#endif

extern void DelayMs(unsigned char);

delay.c
#include "delay.h"
Void DelayMs(unsigned char cnt)
{
39
#if XTAL_FREQ <= 2MHZ
do {
DelayUs(996);
} while(--cnt);
#endif
#if XTAL_FREQ > 2MHZ
unsigned char i;
do {
i = 4;
do {
DelayUs(250);
} while(--i);
} while(--cnt);
#endif
}

40
6.1 PROGRAM BASED WORKING

First the ports to be used are initialized through the program. The output from the
Temperature Sensor is connected to an analog pin RA0 of PORTA of the PIC
16F873A. So this pin is set as input. The pin RA1 is used for switching on and off the
heater. So this port is set as output. This is done by using the TRISA register. If
TRISA0 is set as a ‘1’ it means RA0 is set as input, else output. All other pins on
PORTA are unused. PORTB is used as data lines to the LCD module. Only four lines
are used for this. So PORTB is set as output using the TRISB register. Pin RC1 is
used for PWM generation for the speed control of the DC Motor on the fan. RC1 is
connected to Enable pin[pin 9] of L293D. Pins RC3, RC4 and RC5 are control lines
to the LCD module. RC3 is connected to RS pin of LCD, RC4 to RW pin and RC5 to
Enable pin of LCD. So they are set as output. Pins RC6 and RC7 are used to control
the direction of rotation of the DC motor. They are connected to INPUT3 [pin 10]
and INPUT4 [pin 15] of the Motor Driver IC L293D.

Now the 16x2 Alphanumeric LCD Module is to be initialized. Four bit high
communication is used to communicate with the LCD Module, i.e, pins RB4 – RB7
are connected to data lines D4 – D7 on the LCD Module. For this first 0x28
command is send to it. This command initializes it in 4-bit mode with 5x7 font size.
Next 0x06 is send. This sets the entry mode as left entry. Next 0x01 is send. This
clears the Display. Next 0x80 is send. This sets the DDRAM Address to 0, so that
cursor is set to first row first column. Now the LCD is initialized and ready for
operation.

The name of the project “TEMPERATURE CONTROL SYSTEM” is displayed on


the LCD. This is cleared after a delay of a few seconds. Then the preset temperature
range is displayed. Next the ADC Module is initialized by setting value 0x0E to
ADCON1 and 0x05 to ADCON0. Now the conversion of the analog temperature
41
value to digital value starts. The 10 bit result is stored in ADRESH and ADSESL
registers. This value is multiplied with the resolution of the ADC, 4.88. Now the
value obtained is the voltage that appears at the pin RA0. On dividing this value by
10 we get the temperature of the system. This value is compared with the upper and
lower preset temperature ranges. If the value is less than the range, the heater is
switched on by setting RA1 to 1. If the value is in range, both heater and fan are
switched off. The fan is switched off by setting the value of RC6, RC7 and
CCP2CON as 0. If the temperature is greater than the upper limit, then the fan is
switched on by setting RC7 as 1, RC6 as 0 and generating PWM signals and giving it
to Enable pin of L293D. For PWM generation, Period register PR2 is set as 0xFF,
then depending on the deviation of current temperature from the upper range
CCP2CON and CCPR2L are loaded with preset values. CCP2CON is set as 0x0F
first to select PWM operation. Timer2 is switched on by setting T2CON as 0x05.
Now PWM generation starts.

42
7. PCB LAYOUT

Figure 9

43
7.1. PCB FABRICATION

Printed Circuit Board (PCB) is piece of art. The performance of an electronic circuit
depends on the layout and the design of PCB. A PCB mechanically supports and
connects components by conductive pathways, etched from copper sheets laminated
on to insulated substrate. PCB ape used to rotate electrical currents and signals
through copper tracts which are firmly bonded to an insulating base.

PCB Fabrication involves the following steps:

1. Drawing the layout of the PCB in the paper. The track layout of the Electronic
circuit should be made in such manner that the paths are in easy routes. It is
then transferred to a Mylar sheet. The sheet is then touched with black ink.
2. The solder side of the Mylar sheet is placed on the shiny side of the five- Star
sheet and is placed in a frame. Then it is exposed to sunlight with Mylar sheet
facing the sunlight.
3. The exposed five- star sheet is put in Hydrogen Peroxide solution. Then it is
put in hot water and shook till unexposed region becomes transparent.
4. This is put in cold water and then the rough side is stuck on to the silk screen.
This is then pressed and dried well.
5. The plastic sheet of the five- star sheet is removed leaving the pattern on the
screen.
6. A copper clad sheet is cut to the size and cleaned. This is placed under screen.
7. As it resistant ink if spread on the screen so that a pattern of tracks and a pad is
obtained on a copper clad sheet. It is then dried.

44
8. The dried sheet is then etched using Ferric chloride solution (32Baume) till all
the unwanted Copper is etched away. Swish the board to keep the each fluid
moving. Lift up the PCB and check whether all the unwanted Copper is
removed. Etching is done by immersing the marked copper clad in Ferric
Chloride solution. After that the etched sheet is dried.
9. The unwanted resist ink is removed using Sodium Hydroxide solution Holes
are them dried.

45
PCB PARAMETERS

Copper thickness - 72mil (1mm=39.37 mils)

Track width - 60mil

Clearance - 60mil

Pad width - 86mil

Pad height -86mil

Pad shape -Oval

Pad whole size -25mil

On board -Through

Hole size -0.9mm (36mil)

Base -Paper phenol, Hylam

PCB Quality -FRC4

SOLDERING

Soldering is the process of joining metals by using lower melting point to weld
or alloy with joining surface.

46
SOLDER

Solder is the joining material that melts below 427 degree connections between
components. The popularly used solders are alloys of tin (Sn) and lead (Pb) that melts
below the melting point of tin.

Types:

1. Rosin core: - 60/40 Sn/Pb solders are the most common types used for
electronics assembly. These solders are available in various diameters and are
most appropriate for small electronics work (0.02’’-0.05” dia is
recommended)

2. Lead free: - lead free solders are used as more environmental-friendly


substitutes for leaded solder, but they are typically not as easy to use mainly
because of their higher melting point and poorer wetting properties.

3. Silver: - Silver solders are typically used for low resistance connections but
they have a higher melting point and are expensive than Sn/ Pb solders.

4. Acid –core: - Acid-core solders should not be used for electronics. They are
intended for plumbing or non-electronics assembly work. The acid-core flux
will cause corrosion of circuitry and can damage components.

5. Other special solders :-

47
• Various melting point eutectics: These special solders are
typically used for non-electronic assembly of difficult to construct
mechanical items that must be assembled in a particular sequence.

• Paste solders: These solders are used in the field application or in


specialized manufacturing application.

FLUX

In order to make the surface accept the solder readily, the components terminals
should be free oxides and other obstructing films. The lead should be cleaned
chemically or by abrasion using blades or knives.

Small amount of lead coating can be done on the portion of the leads using
soldering iron. This process is called thinning. Zinc chloride or ammonium chloride
separately or in combination is mostly used as fluxes. These are available in
petroleum jelly as paste flux.

Flux medium used to remove the degree of wetting. The desirable properties of flux
are:-

48
• It should provide a liquid cover over the materials and exclude air
gap up to the soldering temperature.
• It should dissolve any Oxide on the metal surface.
• It should be easily replaced from the metal by the molten
soldering operation

• Residue should be removable after completing soldering


operation.

The most common flux used in hand soldering of electronic components is rosin, a
combination of mild organic acids extracted from pine tree.

SOLDERING IRON

It is a tool used to melt the solder and apply it at the joints in the circuit. It
operates in 230V supply. The iron at the tip gets heated while few minutes. The 50W
and 25W soldering irons are commonly used for soldering of electronics circuit.

49
SOLDERING STEPS

1. Make the layout of the component in the circuit. Plug in the chord of the
soldering iron the mains to get heated.
2. Straighten and clean the component leads using a blade or a knife.
3. Mount the components on the PCB by bending the leads of the components.
Use nose pliers.
4. Apply flux on the joints and solder the joints. Soldering must be in
minimum time to avoid dry soldering and heating up of the components.
5. Wash the residue using water and brush.
6. Solder joins should be inspected when completed to determine if they have
been properly made.

50
8. FUTURE MODIFICATIONS
The goals of this project were purposely kept within what was believed to be
attainable within the allotted timeline. As such, many improvements can be made
upon this initial design. That being said, it is felt that this design represents a
functioning miniature scale model which could be replicated to a much larger scale.
The following recommendations are provided as ideas for future expansion of this
project:

• Changeable temperature limits can be applied by adding a matrix


keypad.

• High precision sensors such as Platinum Wire can be used. This makes it
possible to measure more range of temperature.

51
9. CONCLUSION

Here by we come to the end of our mini project “AUTOMATIC


TEMPERATURE CONTROL SYSTEM”. This paper has presented a means of
controlling the temperature of a system. This system helps to maintain the
temperature within a limit. This system is very marketable because of its simplicity,
low cost, low power consumption and small size. It can be used in various industrial
applications such as to control the temperature in boilers, refrigerator, AC,
Computers and Laboratories.

52
10. REFERENCE

• PIC Microcontroller and Embedded Systems –Muhammad Ali Mazidi


• Wilmshurst, Tim. (2007). Designing Embedded Systems with PIC
Microcontrollers, Ch. 3, pg 62. Elsevier
• [5] Microchip Inc., “PIC16F87X Datasheet,” www.microchip.com, 2001.
• PIC Microcontroller An Introduction To Software and Hardware Interfacing –
Han-Way Huang

53
APPENDICES

54

You might also like