Article AL-QADISIYAH JOURNALFORENGINEERING SCIENCES 13 (2020) 055–060 Contents lists available athttp://qu.edu.iq Al-Qadisiyah Journal for Engineering Sciences Journal homepage: http://qu.edu.iq/journaleng/index.php/JQES * Corresponding author. E-mail address: Methaq.ali2006@gmail.com (Methaq A. Ali) https://doi.org/10.30772/qjes.v13i1.626 2411-7773/© 2019 University of Al-Qadisiyah. All rights reserved. Implementation of Intelligent Industrial Controller Based On Fuzzy Logic and PLC Methaq A. Ali a*, Abbas Hussein Miry b, Tariq M. Salman b aDepartment of electrical engineering, Faculty of Engineering, University of Al-mustansiriyah, Basrah, Iraq. bDepartment of electrical engineering, Faculty of Engineering, University of Al-mustansiriyah, Baghdad, Iraq. A R T I C L E I N F O Article history: Received 06 January 2020 Received in revised form 16 February 2020 Accepted 28 February 2020 Keywords: IoT OPC Server MQTT PLC Kayenne. A B S T R A C T The Internet of Things (IoT) makes designing a smart management system is real and easy. The concept of smart management system guarantees a person to monitor, control and manage the system without any waste. Water is a key resource and its management is a major issue. The proposed method is IOT with the fuzzy controller based system for managing tank water level in Rumaila power plant from gas (in southern Iraq). The existing system, designed with two electric motor pumps, supplies a storage tank with untreated water from the river for later use in (reverse Osmosis) R.O. This system is manual without efficient monitoring and control system. This paper includes two implemented control systems; the classic PID and Fuzzy logic with a comparison between them. Fuzzy control is simulated first using Matlab and then developed by Sugeno-based Fuzzy algorithm within the PLC (Programmable Logic Console) environment. The connection of PLC with OPC (Object Process Control) server used by the Modbus protocol while the sensors connected directly to Kayenne platform. Using the OPC and MQTT, the IoT system is built up to publish and subscribe the data from PLC and cloud. Node MCU- ESP8266 is used by wireless communication to link the sensors with router. © 2020 University of Al-Qadisiyah. All rights reserved. 1. Introduction The internet of Things is a smart method used in wide applications in monitoring of transport systems, environment, health, and other industrial and commercial areas. There are three major parts of IoT are objects, semantics, oriented vision and the Internet which developing communication systems. The IoT is a network that includes physical devices or sensors, that sharing software, storage, and Internet connectivity which allow these things to record, collection, exchange data and managing it [1]. There are several ways that are suitable to control and monitor industrial systems like SCADA, PLC, the Internet of Things, wireless sensor networks (WSN), etc. PLC employed in industries by various automation systems and applications to improve quality and reliability to decrease production cost. Recently, IoT is considered as a suitable method for monitoring industrial systems. This includes communication systems in embedded systems to allow devices and (WSN) wireless sensor networks to be linked via the Internet or industrial systems to be managed and monitored by mobile devices and laptops[2].IoT allows real objects such as sensors and actuators to be conveniently connected to the Internet. It provides an easy way to connect the real or physical objects with the gateway when applying wireless communication in the IoT system as illustrated in Fig.1. In addition, the use of wireless communication can http://qu.edu.iq/ mailto:Methaq.ali2006@gmail.com 56 METHAQ A. ALI ET AL. /AL-QADISIYAH JOURNALFOR ENGINEERING SCIENCES 13 (2020) 055–060 reduce a large number of wires and cables and thus reduces the possibility of faults, particularly in huge industrial networks. IoT could be performed by applying various communication methods such as ZigBee, Bluetooth, Node-MCU (ESP8266) and WAN. Controllers are regarded as necessary elements in IoT because they are used in two matters; the first one is with real things to change it from passive to active (the smart device has singular credentials) or can say it operates like an embedded system. The second one is to serve as the central controller to address the processing and computational of an assigned process and receiving the signals of objects in some of IoT arrangements. while in other IoT arrangements things or devices linked straight to the Internet and computing operations conducted in the cloud.Actually, depends on the complexity and importance of the process connecting the things either direct to the cloud or transmitting the datavia the local central controller.The stability and availability of internet services in the application region may be affecting the way of connecting the object to the cloud. This work obtainingthe novelty since it includes; the use of IoT infrastructure withPLC, which is one of the leading industrial controllers. The second is the use of wireless connection to transfer data from the sensor to the PLC. The third is the design of a fuzzy controller algorithm to evaluate the fuzzy within the PLC system and accurately control the water level of the tank. It is important to note that as a case study the water level was used to verify the system's operation. Thus, it is reasonable to use some changes to the settings to run with any other process such as temperature and pressure. 2. Previous Studies and Research Gaps Himanshu Singh,et. al.[5], developed a prototype for a smart home system to monitor and control some of the home appliances by using IoT. They succeed to send data of lighting, sunblind, gas bottle weight sensor and energy consumption meter to the cloud. NODMCU with Arduino are employed as hardware. While PHP programming is used to build the web interface. Felipe, et. al.[3], submitted IoT system including industrial temperature sensor attached to Arduino. The Xively platform was employed to monitor the sent data; PLC has been used to receive the downloaded data from the cloud platform via the OPC server, they also used HMI programmed by using the Lab View. Shinde, Bhgat [2], Many Common parameters of industry such as D.C-motor, electricity, liquid level based on PLC, speed control, and IoT color mixer based on PLC were monitored by the IoT network. In addition to PLC, NODMCU was used to relay sensor data to the cloud for wireless communication. Antonin Gavlas, et. al.[5] suggested IoT to monitor and control the manufacturing of a stack of pucks. They employed PLC to obtain sensor dataas the main controller. They used the MQTT protocol and (Node-red) to connect to two platforms (IBM and Ubidots) and then performed a latency comparison. Joshi, et. al.[4], IoT used to monitor the ICRH DAC system. They use the (EPICS) which is the abbreviation of Experimental- Physical-Industrial-Control-System as an interface between device and PLC, they use the graphical user interface (GUI) and HTML5 & CSS to create a web page, and they use the browser OPI and CSSBOY OPI to connect the local server with the web page. We were capable of performing IoT for the "R.O water" in our paper 3. Proposed Method The planned structure of device layers consists of five layers; 1- Sensors Layer: This is the first layer in the network representing the things, or in other words, the IoT population, and is intended to be the basic level of the IoT system. In an industrial IoT network, there are some many actuators and sensors that communicate with the machines. That machine usually has different sensors in the industry to track the main parameters related to the output and its healthy condition. The actuator and sensor, each with a microcontroller, are liable for receiving data or managing switches through a predetermined system. The sensor node is a radio-powered microcontroller connected to sensors. They deploying and a self-contained unit that publishes the sensor-generated data. The sensor node has not treated the data locally because it does not have sufficient memory and processing ability. A lower energy wireless communications arrangement is used to send sensor data to the main controller by using the ESP8266[6]. In this project, three types of sensors have been applied; these sensors are critical to the prototype development, based on technical requirements and site survey. The electrical motor is the key part of this project in which we need to attach sensors to monitor and control it in order to ensure the system's stability and continuous operation. The practical variables chosen for use are the water level of the tank, the current of the motor and the river water level. The PLC-based fluid level control system has been used to maintain and track the water level of the tank and provides real-time indications of the tank and river water level. There are two types of water level sensors used in the project; VL53LOX and HC-SR04. Two pails of water were added, one for simulating the R.O storage reservoir and the other for simulating the river. For the interlocking of motor activity, the water level sensor of the river is required, due to the lack of this sensor; DC motor can remain in service, although the water level of the river is low or very small. If the water level of the river is very low, it will contribute to the critical activity, as it will decrease the cooling of the electrical motor impeller. This sensor was used to simulate switches, and its controller can adjust the ultrasonic distance sensorHC-SR04 setting. As a result of the low river water level, it is used to turn off the motor and prevent the mixing of water with air bubbles entering the motor pump. Actuality, this sensor's failure can result in motor pump vibration, overheating, and mechanical problems. The sensitivity of the ultrasonic sensor is about 1 cm, due to no need for high precision for these measures; it is regarded as adequate sensitivity. The benefit of using Figure 1:General layout of proposed system METHAQ A. ALI ET AL. /AL-QADISIYAH JOURNALFOR ENGINEERING SCIENCES 13 (2020) 055–060 57 an ultrasonic sensor is that it measures the river's water level and can allow it to assess the low water level duration during the year and take appropriate preparations using the data collected for a long time. The other pail is R.O collecting reservoir tank because its output value is used for the Fuzzy Logic algorithm, so the selected sensor needs more accuracy. That is the case; it relies on its output values for error change (CE) and error (E), that's the reason for choosing time of flight distance sensor (T.O.F-VL53LOX). The VL53LOX's sensitivity is about 3 mm. In this project, the DC current sensor is necessary to allow the operator to monitoring the motor current. It may also be cloud monitoring and warning or trip composing if its value meets the threshold value. This sensor protects an electrical motor coil from the damage caused by the increased current, which leads the coil heat to rise. For this problem, the current sensor INA219 is appropriate for the Arduino controller and has the capability to supply power and voltage in addition to the current measurement. The use of the current sensor has another advantage in the issue of fault analysis where it is possible to use the reserved history of the current motor to define the circumstances of faults and to obtain the precautions to limit future faults. 2- Network Layer is essential for the IoT system because it is the layer liable for connecting physical objects employing MODBUS TCP/IP which is the leading IoT protocol. TCP / IP (Transmission— Control— Protocol / Internet—Protocol) started a long time ago, but its position as the predominant communication protocol up to date has persisted. This is because of its wonderful capability to ensure reliable data communication across various media. TCP / IP protocol package that makes IP data to cross-unsecured networks such as traditional dial-ups and serial long- distance connections with a reasonable degree of reliability. TCP/IP submits IP with the lost packets detection task by make sequence for each packet—likewise to allow the recipient to re-order the streams packet according to packet sequence numbers. This is an example to explain the operation of IP is a web client transmitting a URL request to a web server. The client searches first to find the IP address for the given URL via DNS (dynamic-name-server) and then contact the server utilizes the registered IP address, which matches to the URL [7]. The topology or structure of the IoT system submitted is a star topology. The IoT device in this topology is directly linked to a convenient gateway that upstream transfers the information from the associated devices. The standard for wireless Wi-Fi network used is IEEE 802.11a / b / g / n. The communication classification used for devices of proposed IoT system is 802.11g and for power consumption causes, the low-cost Wi-Fi microchip with full TCP/IP stack ESP8266 chip has been adopted. 3- Processing Layer: There are two processing parts; one in the main local controller, or the programmable logic control (PLC), that looks at the complicated processing described by Fuzzy control. The other one of processing is doing using the cloud platforms that represent the complete system's monitoring, data collection and control, including saving events and alarms by cloud computing using the Cayenne platforms. The Fuzzy control method is used to manage the presented process as the classic control system such as PID has a lower efficiency than the Fuzzy system for several reasons such as overshot, increased settling time, and a higher steady-state error as described in the following section. Moreover, the use of conventional controllers leads to higher energy consumption [8]. There are two ways to store events and alarms, first in OPC Server (KEP Server EX) by using the OPC Server events and alarm software. The database was stored on the local computer's hard disk using My SQL. The other way is to use the cloud using Cayenne 's dashboard. Events and alarms play a necessary role for analysis. It can be used as historian information for maintenance engineers to investigate the defects that happen in the working system. 4- Gateway Layer: It can be described as a software application or a real device that operates with the cloud as the point of contact between controllers, sensors and smart devices. The advantage of IoT's gateway is that it can provide extra security between IoT and local devices for the transported data. In this situation, setting up the network based on current devices is a major challenge because devices from various companies and at different technical rates do not communicate with the same language. Usually the solution takes a long time. A smart gate way is defined that combines communications between different information sources and passes data to the proper recipients. The IoT Gateway, which able to receive and process information from a PLC, and then store the processed data in the cloud platform. The individual devices are remotely controlled by web applications. OPC requirements define the communication and interfaces of OPC servers as a standard for the interoperability of industrial machine applications. The specification released by OPC Framework for access to data describes costume frameworks for control and other information that the main issue is to attempt to deliver data from local devices in real-time. The costume interfaces are included in the OPC server, while the GUI is optional. So long as device interfacing and customers agree with the specifications correctly, high-efficiency data transmission can be ensured [3]. MQTT is a very simple and lightweight message protocol. It is based on a publish-subscribe to be accessible and easy to run with a single server capable of serving hundreds of remote clients. [9]. 5- Cloud Layer: In this sense, cloud means a large number of network-connected devices that are highly dependent on virtual computing when providing their service where any of these computers is interconnected with multiple virtual machine tasks to achieve cost-minimization. Cloud computing solves issues related to remote storage of data, such as the expense and ability to record large amounts of data. Cloud companies also implementing and offering analytical applications capable of handling huge amounts of data. Such techniques are growing and being increasingly available, and this seems to be the main point. [10]. Cayenne is the first IoT application creator to drag and drop in the world to enable developers, engineers and designers to easily test and upload their created connected device. Cayenne is aimed at helping users create designs for the Internet of Things and then put them into operation. The Cayenne platform has several major components: Mobile Apps – monitoring and controlling your IoT projects remotely from Android or iOS applications. Online Dashboard – Use adjustable widgets for displaying info, setting rules, arranging activities, etc. 4. System Implementation The water intake is considered an industrial system so that more care is needed to provide proper devices for this task. More interesting things to be found in the chosen products are reliability and accuracy. The central controller selected for the framework is from LSIS manufacture, PLC with 12 digital outputs and 16 digital inputs and 2 analog outputs as well as a communication module. As this work would operate in practice, the condition of the analog input or output element can be used for current or voltage, and we make the necessary work arrangement for the industrial facility to protect it from moisture and dust, such as including the instruments in the correct PVC frame. Local control was introduced as shown in Fig. 2 by incorporating a selector switch to switch between auto and manual operation and push-buttons. For the implementation of this control, four digital inputs and three digital outputs and finally, one analog output are used. 58 METHAQ A. ALI ET AL. /AL-QADISIYAH JOURNALFOR ENGINEERING SCIENCES 13 (2020) 055–060 The selector switch location on "Auto" actually means the level of IoT controlling where the IoT was used for remote control in addition to computation and monitoring. There are two 24V power supplies in the panel one for DC motor 24V and the other for PLC. The process in the system is designed by fuzzy control method. The DC-to-DC convertor working as an interface between PLC process output and electrical motor. Fig. 3 represents the flow chart of the water level control algorithm. The output of PLC (0~5V) is supplied to Arduino analog input A0 which processed by Arduino to obtain PWM at the output. The PWM signal is supplied to DC drive that in turn produce scaled output (0-24V) capable to control the speed of DC motor. This was done by using the mapping statement in C++ code; Input= Map (ARD Input, 0, 1023,0, 255); DC drive the signal of PWM applies directly to the MOSFETs electronic circuit with a maximum capacity of 4A and an output DC voltage of 0 to 24V. For reliable wireless data transmission between sensors and PLC, the MCU-ESP8266 chip node is used. To secure the Ethernet connection to the PLC and provide the devices with the internet, a router device is mounted at the edge of the panel. The PLC is connected to a router and all local sensors using the MODBUS protocol. To design PID controller a PID auto-tuning and PID function blocks have been created in the PLC ladder diagram according to the following setting that obtained by using auto-tuning facility available in the PLC: Set point=20cm, Cyclic time= 100mSec The PID parameters are; Kp=187, Ti= 1183, Td=295. A fuzzy algorithm with Sugeno rules was developed using (Structure Text) ST to execute the process of fuzzy within the PLC. Seven memberships were selected for both Error (E) and ChangeofError (CE) in order to get an accurate and high-performance fuzzy system see Table 1. The rising and falling edges of a timer have been used for taking the sample of water level and producing the E and CE as a result. The ultrasonic water level output is used to get the error signal in real-time as below: E:=Set_Value - Water_Level Fig.4 illustratethe marking of memberships, Error memberships and change of Error (CE). ENB[1]:=-10.8; ENB[0]:=-7.2; ENM[0]:=-10.8; ENM[1]:=-7.2; ENM[2]:=-3.6; The above two statements are an example for defining of two membership (NB&NM) of Error. The used fuzzy rules based onthe Sugeno approach. As a result of the membership functions of the rule, Sugeno utilized the singleton. A singleton, or merely a fuzzy singleton, is a fuzzy collection as a membership form that is zero everywhere excluding that unity will be at a specific point in the universe of discourse. [11]. The Fuzzy logic output consists of "11" single spikes from (-1) to (1) increase by 0.2. The following statements are an example of Sugeno rule programmed in (Structure Text) ST; Figure 2: Prototype control panel Figure Error! No text of specified style in document.3: Fuzzy process flow chart Figure 4: (a) Error (b) Change of Error (CE) memberships (c) Sugeno Output singleton METHAQ A. ALI ET AL. /AL-QADISIYAH JOURNALFOR ENGINEERING SCIENCES 13 (2020) 055–060 59 Wi(0,0):=-1; Wi(0,1):=-1; Wi(0,2):=-0.8; Wi(0,3):=-0.6; Wi(0,4):=-0.4; Wi(0,5):=-0.2; Wi(0,6):=0; Wi' is a matrix abbreviated form named WEIGHT matrix that is assigned to the matrix of two-dimension of the WEIGHT for the inference level. We must write 49 sentences to accommodate all rules as shown in Table.1, which includes 49 rules. Table (1) Sugino rules E CE NB(0) NM(1) NS(2) Z(3) PS(4) PM(5) PB(6) NB(0) -1 -1 -0.8 -0.6 -0.4 -0.2 0 NM(1) -1 -0.8 -0.6 -0.4 -0.2 0 0.2 NS(2) -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 Z(3) -0.6 -0.4 -0.2 0 0.2 0.4 0.6 PS(4) -0.4 -0.2 0 0.2 0.4 0.6 0.8 PM(5) -0.2 0 0.2 0.4 0.6 0.8 1 PB(6) 0 0.2 0.4 0.6 0.8 1 1 Although the signal of error changes over time, it is assumed that "E" will be on any of the member ships of error, so it is important to check the existence of error signal on each member ship and precise value within the member ship. Actually, there is one problem that needs to be addressed in particular before the system operates in the real world. The pump is worked within 24VDC and the passing current is increased if the applied voltage begins from zero. When the voltage applied to the driver is less than 6.0 V, the problem appears; the pump cannot be started correctly. To solve this problem, the fuzzy controller should be designed in such a way that it does not supply less than 6.0V. The controller should inspect the error value if the DC drive output is less than 6V (fuzzy output 1250mV as a scaled output sent as input to D / A converter), it will consider the output to zero and the system reaches the desired set point. Such action was taken to protect the pump against any damage. 5. RESULTS AND ANALYSIS Using the MAT LAB fuzzy tool, this method is simulated and delivers the result shown in Fig.5. The figure explains that the maximum value of the Fuzzy output is set to 20 cm if the error is 10.8 cm and the CE is 1. Table 2 reveals that the efficiency of Fuzzy is higher than the conventional PID controller. Whereas Fuzzy's transient time, settling time, and Fuzzy's Integral Time Absolute Error (ITAE) in Fuzzyis less than PID, irrespective of the slight change (IAE) Integral Absolute Error that has no substantial impact on performance. Therefore, the Fuzzy controller alternative is the correct choice. The system test was done; it yields results in real-time. However, the comparison between the results of the PLC output in real- time and MAT LAB shows that the outcomes of the Fuzzy system applied are similar to MAT LAB outcomes as displayed in Fig.6, which means that the suggested working algorithm is correct. Monitoring and controlling from the Cayenne platform is carried out successfully with some delay in reading from PLC to cloud. It delays because the Cayenne platform sets the data update refresh rate about 10Sec and with some latency in that platform's server. A real time comparison curves for both PID and Fuzzy is combined in a same sketch as shown in Fig. 7 A simple dashboard has been performed to Visual representation of network interface control. In fact, as shown in Fig. 8, this interface can be utilized to control the electrical motor. The variations in system values have been observed if a certain value exceeds or below a defined threshold, a warning signal is sent to an e-mail or a Text message is sent to a mobile device. In fact, this feature represents the computational in the cloud. Through moving data to Cayenne's cloud platform, the data recovery can be accomplished. From the above scenario, it is best to use a business network from a security perspective, as well as to reduce data processing's slow latency. Eventually, the plan runs well and performs all the necessary functions in the design. Figure 7: Comparison between PID and Fuzzy Figure 6: Comparison between PLC and MATLABat CE=0, 1, -1 Figure 5: E and CE output for the Fuzzy 3D surface plot 60 METHAQ A. ALI ET AL. /AL-QADISIYAH JOURNALFOR ENGINEERING SCIENCES 13 (2020) 055–060 6. CONCLUSION This work provided a simulation of the industrial water intake process of the PLC-controlled R.O type, which could also be monitored and managed using the IoT. Wireless communication has been used in the industry with many benefits, such as reducing the Amount of cables, reducing the risk of accidents and simply carrying out repairs. IoT may serve as a supplement to existing control systems in order to achieve ideality for industrial systems. At any time and from anywhere in the world, it has a major role to play in remote controlling the working systems, and this will improve system stability. A contrast of classical (PID) and Fuzzy (artificial intelligence) control systems reveals that Fuzzy's performance is better than the classic PID controller. In addition, Fuzzy provides a more efficient, precise and reliable control system and led to power-saving. Events and alarms history is using the Cayenne API to back up, SMS and Email messages have been practically received by mobile and Email when an alarm signal occurs. IoT is important to support the maintenance where experts viewing the events, alarms, and tracking the data trends remotely by using the cloud services to utilize them in faults analytics and give proper solutions. This research has the innovation of combining three important issues: using wireless technology to send sensor data to the PLC, using IoT technology with PLC, and designing an algorithm to run the fuzzy controller in the PLC system. The specification submitted was entirely flexible to allow for more or less I / O commands according to the needs of the industry. ACKNOWLEDGEMENT The authors greatly acknowledge the Electricity Production for South region/Al-Rumaila Gas Power Plant, for the help and support in finishing this research paper. REFERENCES [1] J. Rezazadeh, K. Sandrasegaran, and X. Kong, “A location-based smart shopping system with IoT technology,” IEEE World Forum Internet Things, WF-IoT 2018 - Proc., vol. 2018-Janua, pp. 748–753, 2018. [2] K. S. Shinde and P. H. Bhagat, “Industrial process monitoring using loT,” Proc. Int. Conf. IoT Soc. Mobile, Anal. Cloud, I-SMAC 2017, pp. 38–42, 2016. [3] F. Corso, Y. Camargo, and L. Ramirez, “Wireless sensor system according to the concept of IoT -internet of things-,” Proc. - 2014 Int. Conf. Comput. Sci. Comput. Intell. CSCI 2014, vol. 1, pp. 52–58, 2014. [4] R. Joshi, H. M. Jadav, A. Mali, and S. V. Kulkarni, “IOT application for real-time monitor of PLC data using EPICS,” 2016 Int. Conf. Internet Things Appl. IOTA 2016, pp. 68–72, 2016. [5] H. Singh, V. Pallagani, V. Khandelwal, and U. Venkanna, “IoT based smart home automation system using sensor node,” Proc. 4th IEEE Int. Conf. Recent Adv. Inf. Technol. RAIT 2018, pp. 1–5, 2018. [6] A. Al-Fuqaha, “AL-FA-Internet of Things: A Survey on Enabling Technologies, Protocols, and Applications,” IEEE Commun. Surv. Tutorials (Accepted Publ., vol. 1, no. 2, pp. 2347–2376, 2013. [7] M. B. Community, “Modbus Application Protocol,” Berlin, 1, 2012. [8] L. De Microinformatique and J. Godjevac, “Comparison between PID and fuzzy control,” p. 23, 2007. [9] C. Yoon, M. Huh, S. G. Kang, J. Park, and C. Lee, “Implement smart farm with IoT technology,” Int. Conf. Adv. Commun. Technol. ICACT, vol. 2018-Febru, pp. 749–752, 2018. [10] Zhihao Ling, Weibin Chen, and Jinshou Yu, “Research and implementation of OPC server based on data access specification,” pp. 1475–1478, 2004. [11] J. R. Mahmood, R. S. Ali, H. Migdadi, R. A. Abd-Alhameed, and E. M. Ibrahim, “Development of educational Fuzzy control laboratory using PLC and HMI,” 2015 Internet Technol. Appl. ITA 2015 - Proc. 6th Int. Conf., no. September, pp. 383–387, 2015. Figure 8: Kayenne designed dashboard