Fuzzy Logic Control Implementation On Pic Microcontroller Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Conventional PID controllers were used as a control strategy for various industrial processes from many years due to their simplicity in operation. They used mathematical models to control the plant for different process control applications. Fuzzy logic based control systems were introduced by Lotfi Zadeh to optimize the process control parameters in better way. In this paper, we have implemented a DC motor control strategy with the help of PID controller.Then we will optimize it with the help of fuzzy logic controller. The fuzzy logic control strategy shows the improvement in various control parameters like maximum overshoot, settling time for the DC motor control as compared with PID control strategy. This shows the superiority of fuzzy logic controller over proportional integral derivative controller.


PID (proportional integral derivative) control is one of the earlier control strategies. Its early implementation was in pneumatic devices, followed by vacuum and solid state analog electronics, before arriving at today's digital implementation of microprocessors. It has a simple control structure which was understood by plant operators and which they found relatively easy to tune. Since many control systems using PID control have proved satisfactory, it still has a wide range of applications in industrial control. PID control has been an active research topic for many years. Since many process plants controlled by PID controllers have similar dynamics it has been found possible to set satisfactory controller parameters from less plant information than a complete mathematical model. Fuzzy logic is a method of rule-based decision making used for expert systems and process control that emulates the rule-of-thumb thought process used by human beings. Due to these properties, fuzzy logic can be used to control a process that a human can control manually with expertise gained from experience. The linguistic control rules that a human expert can describe in an intuitive and general manner can be directly translated to a rule base for a fuzzy logic controller. In this paper DC motor is first tuned using fuzzy logic controller and then we will be using fuzzy logic controller to improve the various process parameters follow.



The PID controller is the most common form of feedback. It was an essential element of early governors and it became the standard tool when process control emerged in the 1940s. In process control, more than 95% of the control loops are of PID type, most loops are actually PI control. PID controllers are today found in all areas where control is used. The controllers come in many different forms. There are standalone systems in boxes for one or a few loops, which are manufactured by the hundred thousands yearly. PID control is an important ingredient of a distributed control system. The controllers are also embedded in many special purpose control systems. PID control is often combined with logic, sequential functions, selectors, and simple function blocks to build the complicated automation systems used for energy production, transportation, and manufacturing. Many sophisticated control strategies, such as model predictive control, are also organized hierarchically. PID control is used at the lowest level; the multivariable controller gives the setpoints to the controllers at the lower level. It is an important component in every control engineer's tool box. PID controllers have survived many changes in technology, from mechanics and pneumatics to microprocessors via electronic tubes, transistors, integrated circuits. The microprocessor has had a dramatic influence on the PID controller. Practically all PID controllers made today are based on microprocessors. This has given opportunities to provide additional features like automatic tuning, gain scheduling, and continuous adaptation.

Controllers are designed to eliminate the need for continuous operator attention. Cruise control in a car and a house thermostat are common examples of how controllers are used to automatically adjust some variable to hold the measurement (or process variable) at the set-point. The set-point is where you would like the measurement to be. Error is defined as the difference between set-point and measurement.

error = set-point - measurement

The variable being adjusted is called the manipulated variable which usually is equal to the output of the controller. The output of PID controllers will change in response to a change in measurement or set-point. Manufacturers of PID controllers use different names to identify the three modes. These equations show the relationships:

P (Proportional) = 100/gain

I (Integral) = 1/reset (units of time)

D (Derivative) = rate = pre-act (units of time)

Depending on the manufacturer, integral or reset action is set in either time/repeat or repeat/time. One is just the reciprocal of the other. Note that manufacturers are not consistent and often use reset in units of time/repeat or integral in units of repeats/time. Derivative and rate are the same. Choosing the proper values for P, I, and D is known as PID Tuning.

A feedback control system measures the output variable and sends the control signal to the controller. The controller compares the value of the output signal with a reference value and gives the control signal to the final control element.

The equation of ideal PID controller is

$$ C(s) = K_{p} + \frac {K_{i}} {s} + K_{d}s = \frac{K_{d}s^2 + K_{p}s + K_{i}} {s} $$


Fuzzy logic is a method of rule-based decision making used for expert systems and process control that emulates the rule-of-thumb thought process used by human beings. The basis of fuzzy logic is fuzzy set theory which was developed by Lotfi Zadeh in the 1960s. Fuzzy set theory differs from traditional Boolean (or two-valued) set theory in that partial membership in a set is allowed. Traditional Boolean set theory is two-valued in the sense that a member belongs to a set or does not and is represented by 1 or 0, respectively. Fuzzy set theory allows for partial membership, or a degree of membership, which might be any value along the continuum of 0 to 1. A linguistic term can be defined quantitatively by a type of fuzzy set known as a membership function. The membership function specifically defines degrees of membership based on a property such as temperature or pressure. With membership functions defined for controller or expert system inputs and outputs, the formulation of a rule base of IF-THEN type conditional rules is done. Such a rule base and the corresponding membership functions are employed to analyze controller inputs and determine controller outputs by the process of fuzzy logic inference. By defining such a fuzzy controller, process control can be implemented quickly and easily. Many such systems are difficult or impossible to model mathematically, which is required for the design of most traditional control algorithms. In addition, many processes that might or might not be modeled mathematically are too complex or nonlinear to be controlled with traditional strategies. However, if a control strategy can be described qualitatively by an expert, fuzzy logic can be used to define a controller that emulates the heuristic rule-of-thumb strategies of the expert. Therefore, fuzzy logic can be used to control a process that a human can control manually with expertise gained from experience. The linguistic control rules that a human expert can describe in an intuitive and general manner can be directly translated to a rule base for a fuzzy logic controller.


A DC motor is taken as a case study and the control is achieved using conventional PID controller and intelligent fuzzy logic based controller. The comparison of both the controller performance is analyzed.After analyzing,implement it on microcontrollers.


In classical control techniques PID controller was used as a standard control structure.

Due to nonlinearities in the process the performance of the industrial machinery is greatly distorted and the efficiency is reduced. The new technique which uses fuzzy and PID controllers is considered as the extension of the conventional technique, because it preserves the linear structure of PID controller. These controllers are designed using the basic principle of fuzzy logic control to obtain a new controller that possesses analytical formulas similar to digital PID controllers. Fuzzy PID controllers have variable control gains in their linear structure. These variable gains are nonlinear function of the errors and changing rates of error signals. These variable gains help in improving the overall performance due to their characteristics features like self-tuned mechanism which can adapt to rapid changes of the errors and rate of change of error caused by time delay effects, nonlinearities and uncertainties of the process.

Figure 1: Architecture of fuzzy control

Simulation using SIMULINK

Figure 2: Simulation model

Figure 3: Step response of process with feedback PID


Implementation using microcontroller

After simulating the controller on simulink,we started with implementation using PIC 18F4520 microcontroller but yet not done with it.


Figure 4: State diagram

Figure 5: Schematic

VI. Comparison of Maximum overshoot and settling time for PID and FLC controllers


Maximum Overshoot

Settling Time

PID Controller


11.42 sec

Fuzzy logic controller


7.78 sec


In this paper a DC motor is controlled using fuzzy logic and PID controller. A mathematical model to control the DC motor is developed and the motor is controlled using conventional PID controller. The simulation results so obtained show that the PID controller gives high overshoot and settling time. Hence, fuzzy logic controller design was proposed and implemented using the principles of artificial intelligence. The fuzzy logic control will be implemented and the response will be compared with conventional PID controller. The fuzzy logic control shows a better control of motor parameters as compared with the conventional PID controller


It gives us immense pleasure to express our gratitude to each individual associated directly or indirectly with the successful completion of the report. We would like to express our thanks towards our project Guide Prof. Dr. R.B.Ghongade for his invaluable cooperation and guidance that he gave us throughout our project. We would also like to thank our Head of Department, Prof.P.D.Khandekar for inspiring us and providing us all the lab facilities with the internet, which made the project work very convenient.


[1] Erdal Kayacan and Okyay kaynak, "An Adaptive Grey Fuzzy PID Controller With Variable Prediction Horizon," SCIS&ISIS2006 @ Tokyo, Japan (September 20-24, 2006); 760-765

[2] B.G. Hu, G.K.I Mann and R.G Gosine, "New methodology for analytical and optimal design of fuzzy PID controllers," IEEE Transaction of fuzzy systems, vol. 7, no. 5, pp. 521-539, 1999

[3] Awang N.I. Wardana, "PID-Fuzzy Controller for Grate Cooler in Cement Plant," IEEE transaction of fuzzy system, no.7, vol. 32, 2005, 1345-1351.

[4] Han-Xiong Li,Lei Zhang, Kai-Yuan Cai, And Guanrong Chen," An Improved Robust Fuzzy-PID Controller With Optimal Fuzzy Reasoning," IEEE Transactions On Systems, Man, And Cybernetics Part B: Cybernetics, Vol. 35, No. 6, December 2005; 1283-1292

[5] Isin Erenoglu, Ibrahim Eksin, Engin Yesil and Mujde Guzelkaya, "An intelligent hybrid fuzzy PID controller," in Proceedings of 20th European Conference on Modeling and Simulation, 2006.

[6] [6] Leehter Yao and Chin-Chin Lin, "Design of Gain Scheduled Fuzzy PID Controller," World Academy of Science, Engineering and Technology 1 2005, 152-156