# Fuzzy Logic Temperature Controller

by Yunseop Kim

2001 .Physics 344 Project December 14.

. Membership functions transform crisp inputs (temperature) into fuzzy sets in the process of fuzzification and fuzzy sets back into crisp outputs (voltage) in the process of defuzzification.Construct an input sensor to measure temperature using a thermocouple. Hardware circuit design. For example. given that a measured temperature is 70 oF? One would hesitate to answer “true” or “false”. Performance of the FLC was evaluated and compared with a conventional PID controller. considering of “it is warm”. 5. because we are sure of the degree of temperature. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson FUZZY LOGIC TEMPERATURE CONTROLLER PU R P O S E The purpose of the project is to design a fuzzy logic controller (FLC) for temperature control. Thus. Construct an output actuator to provide a heating source . rather than being just “true” or “false”. Page 2/12 . A block diagram of fuzzy logic system for temperature control is illustrated in Figure 1. Fuzzy logic treats the true value of warmness is a number between 0 and 1. 1] as follows: :XF .Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. Software design in Lab View. 4. it is a case of vagueness or uncertainty about the meaning of the linguistic term “warm”. Rather. Design an amplifier to magnify input signal from the thermocouple. The FLC incorporates human knowledge into their Knowledge Base (KB) through fuzzy rules and fuzzy membership functions. The idea behind the use of the fuzzy logic was from the fact that temperature is not explicitly defined. It is also suitable for nonlinear multi-input and multi-output systems. rather prefer to say “sort of”. 2. 3. This is not a question of uncertainty about the external world. a fuzzy set F in a universe of discourse X is characterized by a membership function F that takes values within [0.Design an amplifier to magnify output signal from the computer. the FLC is described by a knowledge-based algorithm. the temperature (state variable) was determined by a heater in a form of output voltage (control variable). Temperature sensor calibration. BA C K G O U N D S A fuzzy logic was used to perform the temperature control. Performance evaluation with several set points & disturbance. is this true. Specific objectives of the project are listed as follows: 1. In this project. Tuning for both Fuzzy and PID controllers.1] While conventional controllers are analytically described by a set of equations. [0.

Physics 344 Fall 2001 Project Report Physics Department. University of Illinois at UrbanaChampaign Fuzzy Logic Temperature Controller By Yunseop Kim Instructor: Professor Ian Robinson Knowledge Base D a ta B a s e Membership Functions Rule Base Control Rules Page 3/12 .

University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson Page 3/12 .Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department.

A power ceramic resistor was used as an actuator to generate heat. Fuzzy logic controller was designed in the Lab View and compared with conventional PID controller. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson Figure 1 Block diagram of fuzzy logic system for temperature control. The signal from the sensor was amplified to increase measurement resolutions and fed back to A/D computer interface board.Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. Temperature was measured by using a thermocouple. MAT E R I A L S A N D ME T H O D S A temperature control system consisted of a sensor. Amplifier A/D Actuator S Amplifier Comput D/A er Figure 2 Schematic diagram of a temperature control system. Input signal detected from the thermocouple was read by a computer through A/D conversion of a DAQ interface board.000 so as to increase resolution of input signal to the computer from 0 ~ 5V. and computer (Fig. Hardware Circuit Design. Upon the software design of control algorithm in LabView. 2). Apparatus of a temperature control system is shown in Figure 3 (a). Thermocouple was connected to an on-amp to amplify the measurement signal with a gain of 1. The output signal was determined by control algorithm. LabView software was used to acquire the input signal and send output signal to an actuator. 1. output signal was sent to an actuator from the computer though D/A conversion of the DAQ board. actuator. Page 3/12 .

Right (b): Two identical temperature control circuits. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson (a) (b) Figure 3 Hardware design for a temperature control system.Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. Page 3/12 . Left (a): Overall picture of the system.

In order for effective comparison.1 5V and 4. 4. Since a 100 power resistor provided heat source with maximum 1 W or 10 V and the maximum DAQ output was 5 V.000 using an on-amp so as to increase resolution of input signal to the computer from 0 ~ 5V. Temperature Sensor Calibration. Two heat sources were used to provide reference temperature reading: one is ice water (4 oC) and the other is boiling water (100oC).090. 1 5 ) 1004 _____________ 4for PID.0)___________________________ 4 for 3 .75V with the thermocouple for FLC and 0. it was amplified with a gain of 1. there were two analog input signals from the thermocouples and two analog output signals to actuate the resistors. The output from the DAQ can source only 2 mA. Circuit diagram of the temperature control system is illustrated in Figure 4. Thus. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson Figure 4 Circuit diagram of a temperature control system. input range Page 5/12 .09V with that for PID for ice and boiling water.0 FLC. two identical circuits were made (Figure 3 (b)). regression equations were derived as following: 100 4 Temperatur e voltage reading (0. Thermocouple was calibrated to convert voltage signal to temperature. the output signal was connected to an op-amp and a transistor current booster in a feedback arrangement. 2. Accordingly. In order to drive the heater. Thus. Amplified voltage readings were 0V and 3.Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department.15 The analog voltage was digitized by a DAQ interface board with 12-bit resolution which produces a range of digital count 0~4095 for uni-polar analog input of 0~+5V. respectively. a gain of 2 was added. and Temperature voltage ( 0 reading .75 0. Since the input signal measured by the thermocouple had only a few millivoltage.

If a desired set point is Tset. where x is an input state variable representing difference between a set point and current temperature reading. If temperature is cold. Once reading the signal from the temperature sensor. If temperature is moderate. then the control (y) is negative small (B2). while E>0 indicates cold. If the error (x) is negative small (A2). then the error temperature (E) was defined as E=Tset–Tcurrent. If temperature is cool. then the control (y) is negative large (B1). change the heater to large increase. The corresponding temperature resolution was 100 oC/3277=0. Fuzzy Logic Controller A fuzzy rule-based system was characterized by a set of rules that were defined by antecedents and consequents. For simplification.22 [mV/count]. Inference rules were made by a simple logic to implement basic concept of the Fuzzy Logic as follows: If temperature is hot. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson from 0V to about 4. This resolution was high enough for the temperature control system. E<0 means hot. The linguistic rules can be presented in terms of fuzzy sets as follows: If the error (x) is negative large (A1). y is an output control variable representing output voltage to the heater. change the heater to small increase. Software Design in LabView. A 50% overlap in the membership functions of all fuzzy sets was used so that only two fuzzy sets have non-zero degree-of-membership functions at any point of the universe of discourse.023 [oC/count].Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. If the error (x) is nil (A3). then the output (y) is nil (B3).0V from the sensor corresponded to digital value from 0~3277 with resolution of 4. current temperature (Tcurrent)can be calculated through a calibration equation. change the heater to large decrease. 3. The fuzzification of two degree-of-membership functions for input variable (x) was defined as: xInputDomai n 1 F1 InputDomai n InputDomai n 2 1 and F2 1 F1 Page 6/12 . don’t change the heater. If the error (x) is positive large (A5). Ai are fuzzy input sets. For example. then the control (y) is positive large (B5). If the error (x) is positive small (A4).0V/3277=1. The system is aimed to control the temperature of the power resistor at a set point.3oC. and Bi are fuzzy output sets. If temperature is warm. the triangular membership function was chosen for both input and output. because acceptable control tolerance was assumed to be around 0. change the heater to small decrease. then the control (y) is positive small (B4).

The integration of the errors was calculated by Simpson’s one-third rule as follows: h Edt . the defuzzified output value that was applied to control variables was defined by: y OutputDomain 2 F1 OutputDomain 1 F 2 PID Controller As a conventional way. K I. and derivative controls. Page 7/12 . University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson Among many methods applied to the defuzzification stage. 3 (EE1 4 2 E ) 3 where h is elapsed time and E 1. PID control was used and its output was defined as follows: dE Output dt ofsetK K . and E reassigned as each sample is taken. respectively. Lab View Design 3 are the three consecutive error values that are Algorithms of Fuzzy Logic and PID control were implemented by using Lab View software. and K D are the control parameters for proportional.E d tP EKI D where K P. integral. E 2.Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. Figures 5 and 6 illustrate circuit diagram and front panel of the temperature control system.

Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson Figure 5 Circuit diagram of Lab View for Fuzzy and PID controllers. Figure 6 Front panel of Lab View consisting of tuning parameters for Fuzzy and PID controllers. Page 8/12 .

oscillation. it remained in further tuning process. Right (b): P-control tuning. Page 9/12 . PI-controller reduced the overshoot since accumulated errors were compensated by the integral control parameter (Figure 8 (a)). the steady state error remained. PID-controller improved the steady state response with smaller oscillation (Figure 8 (b)) due to predicting the slop of the response curve. (a) (b) Figure 7 Tuning for PID controller. otherwise the last output values after while loop were continuously sent to two analog output ports and thus may burn up the resistors. Left (a): Open-loop tuning. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson Upper multiple case-loops were to generate the set points as a ramp function. The temperature was monitored by showing set points. All data points including elapsed time were recorded to an output file for further analysis. A case-loop after a while-loop was needed to nullify the output signal with termination. A selected Once a control parameter was selected (marked in bold). and PID response in real-time mode. P-controller was much faster than open-loop controller. and KD) that were obtained by tuning process. Tuning for PID Controller. Fuzzy response. Following consisted of two parts: one for FLC on upper half screen and the other for PID on lower half screen. Optimal values for the parameters were selected based on minimum of overshooting. Open-loop controller showed slow and unstable response due to no output feedback (Figure 7 (a)). Output of the PID controller depends on the control parameters (KP. but had some overshoot and oscillation in steady state (Figure 7 (b)). But. The tuning process was illustrated in Figures 7 and 8. and steady state error. E X P E R I M E N T S A N D R E S U LT S 1.Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. KI.

Figure 9 Tuning for FLC with a ramp function as set points. 3.5.0.0}. Left (a): PI-control tuning. fourth. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson (a) (b) Figure 8 Tuning for PID controller. the tuning was made to find only the fourth element. Fuzzy membership functions were tuned with a ramp function as set points.0. The fuzzy input domain was empirically assigned to {-5. The fifth element was fixed to 5. because the maximum output voltage from the DAQ board was 5 V. With the fixed fuzzy input domain. Right (b): PID-control tuning. From comparison of the responses shown in Figure 9. the optimal values for the fuzzy output domain were selected to {-5. 0. and fifth elements) since the fuzzy sets for input and output were symmetrical on the middle value 0 (third element). 0. 2. Tuning for FLC. -3. 5. because temperature to be measured in this project ranged within 3 0 7 oC. fuzzy output domain was tuned for half elements of the set (third. –0. Page 9/12 . 0. Thus.0.5. 5.0}.Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department.0.0.0.

(a) (b) Figure 11 Responses of FLC and PID controller. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson Tuned fuzzy membership functions were illustrated in Figure 10. nil. P a g e 11/12 . The FLC was more robust for both disturbances than the PID. Left (a): with a set point (30oC). First evaluation was made with a fixed set point of 30 oC (Figure 11 (a)). The FLC showed faster response in transient state than PID and settled down without overshoot and oscillation in steady state. but had slight steady state error that was not seen in the PID controller. One of the most important factors in control is robustness of the system response against possible disturbances. The disturbance was made manually on both temperature sensors at the same time so as to produce same effect of disturbance. The evaluation was continued to observe the robustness against some disturbance (Figure 11 (b)). Right (b): with disturbance (additional heat and blowing). Evaluation of FLC and PID Controllers. negative small. Figure 10 Membership Functions for Fuzzy inputs and outputs. and positive large).Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. The performance of the FLC was evaluated and compared with that of the PID controller. 3. positive small. respectively. Over peaks and under peaks in figure 11 (b) represent the disturbance by applying an additional heat source (solder) and cooling source (blowing). The fuzzy sets of input and output were partitioned into five membership functions corresponding to five linguistic variables (negative large.

Since the cooling process of the heater took longer and out of controllable response range. Same trend was found with respect to the ramp function.Physics 344 Fall 2001 Project Report Fuzzy Logic Temperature Controller By Yunseop Kim Physics Department. (a) (b) Figure 12 Responses of FLC and PID controller. This was caused by the coarse tuning and small size of fuzzy set. The steady state error increased as the set point increased. University of Illinois at Urbana-Champaign Instructor: Professor Ian Robinson Further evaluations were made with varying set points: step function (Figure 12 (a)) and ramp function (Figure 12 (b)). showing faster transient response and less overshoot and oscillation. P a g e 12/12 . The performance of the FLC was evaluated and compared with that of PID controller. The FLC performed superior to the PID controller. The FLC followed the step function faster than the PID and less overshoot and oscillation. FLC was tuned with a ramp function to determine the membership function of input and output domains. But it had some steady state errors. but had some steady state errors as seen before. Improvement can be achieved by resizing the fuzzy sets and finer tuning for the membership functions. It was also more robust against disturbances than the PID controller. Left (a): with a step function. PID controller was tuned by stepwise determining the control parameters. CO N C L U S I O N S FLC was designed for temperature control. Right (b): with a ramp function. the responses were not effectively evaluated.