Simulation and Modelling of Electricity Usage Control and Monitoring System using Thing Speak

: Renewable energy technology is growing fast especially photovoltaic (PV) system to move the conventional electricity generation and distribution towards smart grid. However, similar to monthly electricity bill, the PV energy producers can only monitor their energy PV generation once a month. Any malfuntion in PV system components may reduce the performance of the system without notice. Thus, developing a real-time monitoring system of PV production is very crucial for early detection. In addition, electricity consumption is also important to be monitored more frequently to increase energy savings awareness among consumers. Hardware based Internet-of-Thing (IoT) monitoring and control system is widely used. However, the implementation of the actual smart grid system is high in cost. Thus, simulation and modelling of the system is important to see the capability of the actual system before being employed. Since the smart grid and its components are usually modeled using MATLAB/Simulink, the communication between MATLAB/Simulink, IoT platform such as ThingSpeak and mobile application is crucial to be explored to gain a better understanding of the features of the smart grid. To achieve the objectives, there are five main steps which are simulation of grid-connected photovoltaic (PV) system to generate data to be monitored and controlled using HOMER software, then, development of monitoring on ThingSpeak and mobile application using MIT App Inventor 2. Next, the control system is developed on mobile application and the communication on how data are transferred between all the softwares are set up. The results show that all the seletected parameters can be monitored in real-time successfully. The developed mobile application can be used to control the MATLAB/Simulink in two modes. During automatic mode, ThingSpeak controls the MATLAB/Simulink by giving a zero signal (OFF) if load demand is less than the power generated by PV and a one signal (ON) if the load demand is greater than PV power. During manual mode, consumer can send ON or OFF signal to MATLAB/Simulink via the mobile application unconditionally. It is hoped that the proposed system will bring many benefits in modeling a complete smart grid system in MATLAB/Simulink.


Introduction:
World electricty demand grow rapidly from 14,157.1 TWh in 2000 to 24,738.9TWh in 2018, in all sectors such as industry, residential, services, and transport, as reported in International Energy Agency 2019.It is predicted that the demand will further increase to up to 42,000 TWh in 2040 (1).Even though renewable energy (RE) technology is growing, the major contribution of electricity generation are still dominated by fuel, coal and gas using conventional grid.
The conventional power grid is simply the interconnection of different elements of power systems such as power transformers, synchronous machines, transmission substations, transmission lines, distribution lines, distribution substations and various types of loads.It is a centralized system where the power movements is only in one direction, from the generation of electricity through the transmission lines and distribution system before reaching the consumers.Generation sometimes is not be located in the same 908 geographical area as the load supplied, often requiring transmission from remote locations.This conventional method of electricity distribution is inefficiency, frequent supply interruption, and contributor to high CO 2 emission (2).This existing utility power grid may or may not include sensors, computing, and communications to monitor grid performance, depends on the application.Customer information is usually limited to a recurring invoice of products provided in a particular time or billing cycle.The user of conventional grid only can monitor but cannot control the usage of electricity.
To overcome the problems in conventional grid, smart grid is the best option.Smart grid technology is proposed to reduce the dependency on the grid by integrating the conventional grid with RE technologies, thus increasing the reliability of the power distribution.Smart devices, smart substations, smart meters, and advanced synchrophasor systems are key components of the smart grid.In this technology, the consumers are encouraged to generate their own electricity using RE sources for their own use.As a result, the generation of electricity is decentralized.For a large community such as campus environment, residential area, military base, commercial and industry, the small-scale power grid that can operate independently or in conjunction with the area's main electrical grid is called microgrid and connections between microgrids form a smart grid (3,4).
To implement the smart grid, which is high cost, many researchers try to understand the capability of smart grid by developing the model in a software and simulate the system virtually which is low cost and useful in providing guidance to actual installation.MATLAB/Simulink software is widely used among researchers to model smart grid and its components including photovoltaic (PV) system (5)(6)(7)(8)(9).In addition, MATLAB/Simulink provides ThingSpeak as a medium to connect to internet (10).Any data can be sent and stored in the cloud via ThingSpeak.Once the data are in the cloud, it can be accessed in any platform either computer or smart phone as long as the device has internet connection.Yet, ThingSpeak is commonly used to send data from sensors connected to microcontroller-based system to the cloud (11)(12)(13)(14).There is a limited number of researcher focus on transferring real-time data from MATLAB/Simulink-based model to ThingSpeak (15).Since the components of smart grid are modelled using MATLAB / Simulink, to complete the whole process of smart grid, the capability of sending data from MATLAB/Simulink simulation data to ThingSpeak and vice versa must be explored.
To bring the smart grid to reality, there are still lot of works to be done.The installation of RE system in Malaysia, especially the PV system, grew rapidly after Feed-in-Tariff (FiT) was introduced under the Renewable Energy Act in 2011 (16).The Feed-in Approval Holder (FiAH), specifically for residential area sector, is capable to monitor their installed PV production via online, similar to electricity bill.However, both data are only updated at the end of the month.The problem occurs when one of the installed components, normally the inverter malfunctions.As a result, the energy production of the system drops dramatically.There is no mechanism of alerting FiAH of this problem, except for when the small red LED on the inverter lights up.It is worse if the FiAH is not home for a long period of time.So, the real-time monitoring PV system is very important to alert the FiAH the status of their installed PV system.Similarly, the electricity usage also important to be monitored in real-time so that consumers will be thriftier.
Hence, this work is motivated to develop a monitoring system for PV energy production and electricity usage of FiAH.This monitoring system can be displayed on mobile application (app) developed using MIT App Inventor 2 (MIT AI2) software.The considered system in this study is based on the actual grid connected PV system installed on a rooftop of a residential building in Terengganu.The present works also adds some novel elements to the existing literature.It is based on the results published in (15).In Forcan and Maksimović, they setup real-time communication scheme used for simulation between MATLAB/Simulink and ThingSpeak (15).This paper extends the system by setting up communication between the developed mobile app to ThingSpeak to explore the possibility of sending signal from mobile app to MATLAB/Simulink.The idea is illustrated in the Figure 1 which is modified from the Figure 5 of (15).

Figure 1. A modified system from (15)
The rest of this paper is organized as follows.The next section discusses in details the background and related studies on smart grid, energy monitoring and control, and implementation of Internet-of-Thing (IoT) in smart grid.Then, step-by-step on how to achieve the objective is presented in the methodology.The results and discussion section presents the capability of the developed system when it is tested and discusses thoroughly the findings and contribution of this paper.The paper concludes the finding and highlight the future work that can be done.

Background and Related Studies:
This section examines the current research related to this work.Selected papers mainly related to smart grid technology, the enery monitoring and control system and the use of IoT technology in smart grid are presented.

Smart grid technology
Throughout the grid, multiple generation options allow power sources to be closer to consumers, reducing distribution and transmission cost, and lowering energy losses.A successful smart grid must have a few characteristics.Since it is integrated with microgrids and RE sources to meet the growing demand for electricity, thus it reduces greenhouses.The system must be highly reliable, measured by the success of the grid to meet customer demand.It has self-healing ability to discover the possible problem that may be triggered naturally or produced by human error.It has demand side management system which is used by the user to interact with the grid using two ways communication.Then, the demand for security is high because electrical data can be monitored and controlled remotely.So, it is normally equipped with a smart metering system to record power data from grid to user and vice versa.In addition, the smart grid also provides monitoring and control at all stages from generation, transmission, distribution network, and consumers consumptions where sensors, automatic switches, reclosers, and other devices are built into the system.As a results, the smart grid is capable of tracking all activities of the grid-connected network, consumer preferences for the use of power, and provides information on all events in real-time (4,17).

Energy monitoring and control in smart grid
Among RE sources used in the smart grid, this paper only focuses on PV system as it is the world's fastest growing energy technology due to factors such as the PV system utilizing the most abundant RE source on the planet, i.e. the sun, low maintenance, low solar PV prices compared to other RE technology and can be mounted in small or large scale (18).Ramakrishna and Singh have deliberated thoroughly on PV monitoring system (19).The system is used to provide information about the energy potential based on collected solar irradiance and ambient temperature, the actual energy generated, energy loss and analysis of different of faults that might occur.From the monitoring system, the data can used for early detection and warning forecasting the climatic changes.The PV monitoring system generally consists of PV system, smart sensors to detect the parameters, data transmission medium to transfer the data from sensors, data storage to store the collected data and graphical user interface (GUI) for monitoring and analysis.The parameters considered are solar irradiance, ambient temperature, PV voltage and current, and other parameters depending on the type of PV system either grid connected or stand-alone system.The computerbased data acquisition (DAQ) system is normally used to collect all data and display using any GUI such as LabView software.(20) suggested to use a wireless PV monitoring system, where the parameters current and voltage of PV system, irradiance and the cell temperature, were collected using the microcontroller-based DAQ board and transmitted to a computer via Bluetooth module.These data were displayed in MATLAB/Simulink environment and were used as input to PV model for simulation purposed.( 21) proposed a high security wireless monitoring and control systems for a smart home.The authors focused on the secure access gateway to ensure the data transfer between smart home managed devices and C-mobile such as smart phone as monitoring and control devices and can be delivered successfully and privately.
In addition to electricity generation monitoring system, electricity consumption should also be observed.The advantages of implementing the system are the hourly detailed characteristics of load demand can be provided, thus the consumption patterns can be defined to have a better view and get a better understanding of the load.This information can help consumers to identify which electrical appliance should be off to reduce the electricity bills (22).It is also used for better energy management.Consumers can manage their power consumption performance according to the energy data.They become more aware of energy usage and efficiency because of economic and environmental reasons (23).Detecting peak energy demand also allow users to manage their energy use more proficiently and plan the future scenarios (24).The use of IoT devices for monitoring and control of energy consumption can also consider a lot of other parameters such as event monitoring, building optimization and user favorites.
Recently, numbers of researchers proposed IoT-based household electricity energy monitoring and control system (23,(25)(26)(27).This system consists of a microcontroller, Wi-Fi module and sensors.It is used to measure, collect, store, analyze and use customer information to be displayed to the customers.(27) designed MATLAB app to serve as user interface for monitoring the energy consumption and temperature reading from pressing iron and hair dryer.The system also was able to control the electric bulb remotely via ThingSpeak cloud server.When the temperature and electricity consumed exceeds the set threshold, a notification was sent to the user's email.(28) proposed a real-time monitoring device of electrical energy consumption in the microbrewery.From the energy audit that was conducted based on the acquired data, the microbrewery start implementing energy saving activities by changing the use of heating and cooling appliances in order to reduce the peak load demands.(29) proposed a prototype of an energy management and monitoring system for a house using SCADA system that is based on the IoT and was designed to minimize electricity usage throught self-consumption.The implementation of their proposed system transformed the house into a smart house which eventually generates cost savings and promotes sustainable living.In addition, the collected electricity consumption data also can be used to forecast the future consumption as done in (24,30).( 30) proposed a forcasting model and algorithm of electricity usage for household.Their proposed model can be used to control operating parameters based on power consumption plans and considered the functionality of smart electricity meters.(24) predicted energy consumption plays an important role in the process of digital transformation and for understading the potential for energy savings.Their proposed method use different techniques in forcasting the energy consumption such as linear regression, dynamic regression, artificial and deep neural network.The forcast was done based on five buildings data from 2014 to 2019.It is proved in (25) that their proposed non-instrutive load monitoring technology can reduce approximately 14% of power consumption.They also mentioned that some studies have presented in literature that providing complete information of power consumption to consumers can save energy more than 20%.(31) implemented a real-time intelligent energy management system in college campus.The generated daily consumption displayed on a web page and a short message service (SMS) alert.The suggested system reduces energy consumption by 46.64% and reduce expenditure by 30.6%.

Internet-of-Thing in smart grid
The fast growing in Internet-of-Thing (IoT) technology in digital era has open wide opportunities real-time monitoring and control system.IoT is a new network which allows remote monitoring and control of all physical devices by embedding the devices with electronics, software, sensors, actuators and connectivity.(32) proposed monitoring and control system for cyber-physical layer.They introduced a game-theoretic approach to solve the problem of cyber-attack.Real-time Arduino-based monitoring and controlling system in smart grid has been proposed in (11).Their system consists two-sides of Arduino-based systems, the consumer and the grid side.At the consumer side, there is a power sensor to measure power used by consumer, and at the grid side, power quality monitor sensor is used to measure quality of the power.In addition to Arduino as a microcontroller at both side, a Global System for Mobile (GSM) module is used to send information between the two sides.and controlling big data in smart grid is discussed thoroughly in (33).Their proposed system suggested to use workstation as a cloud controller and local area network as connection medium.Meanwhile, ThingSpeak (34,15) is an IoT open data platform that allows users to collect data that is stored in the cloud, analyze and visualize data with MATLAB, and trigger a connected device reaction.ThingSpeak is widely used for monitoring system for different application such as a tank monitoring system as in (35), Arduino-based air monitoring system (36), temperature and humidity monitoring system (37), environmental monitoring system (38), ionosheric monitoring system (39), smart surveillance system (40), room's air condition monitoring system (41) and autonomous demand side management system of a microgrid in (42).From the literatures, the IoT based systems that used ThingSpeak are commonly developed using hardware that consists of sensors, microcontrollers, and wi-fi modules.There is a very limited numbers of literature focus on the IoT in simulaton and modeling as in (15).In their paper, they proposed a cloud For GUI part of monitoring and control in IoT-based system, MATLAB GUI, visual basic, LabView softwares are commonly used to display all the parameters on desktop (19).To develop GUI on smart phone, MIT AI2 is broadly used in literature.MIT AI2 is a visual programming tool for the design and development of mobile applications (43).One of the features of collaborating with MIT AI2 is that when designing, developers can see directly their designs (44,45).This helps users to incrementally create apps and encourages to check as they build (45).MIT AI2 is widely used by developers to develop mobile apps for different purposes.

Methodology:
This project focus on monitoring of two parameters which are real-time power load demand (  ) and generated PV power (  ), and controlling grid purchase ( ℎ ) and grid sales (  ) parameters that show how much shortage energy have been purchased from and excess PV energy generated sold to the grid, respectively, as shown in Figure 2.   is inverter loss that depends on the efficiency of the inverter as in Table 1.Since the focus of this paper is only on developing monitoring and controlling system and the communication between MATLAB/Simulink and MIT AI2 with ThingSpeak, the model of PV system is out of the scope.To get the desired parameters, HOMER is capable to generate synthetic required hourly data from monthly available collected data using V. A. Graham based algorithm (46), thus the second step is simulaton of the grid-connected PV system in HOMER, as shown in Figure 6.Generally, HOMER is used to predict energy and economic parameters based on the input data provided for a given project lifetime.The specification of inverter and PV panels used in the simulation are as shown in Table 1 and Table 2, respectively.The primary load is based on collected electricity usage.While the hourly electricity production from PV system can be generated from the hourly solar irrdiance and ambient temperature.HOMER also produces hourly grid purchase and grid sales power based on the availability of AC PV power and the electricity need by load demand as in the following equations:  914 The third step is to develop a monitoring system.All four parameters,   ,   ,   and  ℎ obtained from HOMER are then imported to MATLAB/Simulink so that the ThingSpeak can be used to store the parameters in the cloud.The hourly generated data from HOMER are sent to ThingSpeak every hour to create a real-time data after the channel of ThingSpeak and communication between ThingSpeak and MATLAB/Simulink was set up.
To display the data on mobile app, the MIT AI2 software is used to develop the the app.Then, the communication between ThingSpeak and smart phone is established.This is done in fourth step.The developed mobile app is not only capable to monitor the four parameters, but in the fifth step, three button ON, OFF, and AUTO are developed on mobile app to control the model in MATLAB/Simulink.The communication is set up between mobile app to ThingSpeak and MATLAB /Simulink so that the data from mobile app can be sent to MATLAB/Simulink without error.

Results and Discussion:
This section is divided into three.The first suptopic discusses the findings obtained from HOMER software.Then the developed monitoring and control system are discussed separately.

Data generation from HOMER
HOMER generates hourly data for a year based on monthly collected annual solar irradiance, ambient temperature and load profile.The hourly data for annual load demand is plotted in Figure 7. From the figure, the minimum load demand is 0.048 kWh on 21 st May at 5:00 AM and the maximum is 3.723 kWh on 4 th February at 6:00 AM.The total annual electricity used for this house is 6612 kWh with average 18.1 kWh/day.

Figure 7. Hourly AC primary load (𝑷 𝑳 ) for a year
However, due to limition of number of data can be stored in a free version of ThingSpeak, oneday data is considered, for example on 17 th January and plotted in Figure 8. Refer to the figure, it shows the daily trend of enegy consumption for the house.Low energy usage during early morning is contributed by refrigerator, lighting, and air-conditioning.The high electricity usage from 6:00 to 8:00 AM due to the use of electric water heater and kitchen appliances before going to work.From 8.00 AM to 7:00 PM, the owner is not at home, thus the electricity usage is low.It raises after that due to lighting, televison, phone charger, fan, home appliances and air-conditiong.

915
HOMER generates the PV energy based on the solar irradiance, ambient temperature and PV solar specification input parameters.The hourly annual   data is shown in Figure 9. From the figure, the highest energy production of the PV is 7.4 kWh on 14 th November due to the highest daily solar irradiance of the year at 1.19 kWh/m 2 at 11:00 AM as observed in Figure 10.The total annual energy production of the PV system is 12162 kWh with average 33.3 kWh per day.Figure 11 shows the solar energy production for the same selected date as the load demand which is 17 th January.The pattern of the energy production on the selected date is as in normal hot shiny day where the energy production starts at 7:00 AM to 7:00 PM.The highest energy production is 5.789 kWh occurred at 12:00 noon and there is a little drop at 2:00 PM follow the shape of solar irradiance of the day.Grid purchases is the output parameter that the HOMER calculate the needed power to cover the power demand or   .The insufficient of electricity was calculated using equation (2). Figure 12 and 13 show hourly grid purchase data for a year and the selected day, respectively.From Figure 12, the highest grid purchase is 3.43 kWh, at 6:00 AM due to highest load demand on the same day.The clearer trend of the daily grid purchase can be seen in Figure 13.The shape of the grid purchase during early morning follow the shape of load demand.
Once the energy production from PV system is available, the grid purchase drop to zero and back to supply the electricity to load demand again after low   after 6:00 PM.During this time, the shape of grid purchase again follow the load demand.Grid sales is the output parameter calculated by the HOMER that shows how much the surplus power generated by the PV is sold to the grid using equation (1). Figure 14 shows hourly annual grid sales.From the figure, the maximum grid sales is 6.23 kWh occurred on 3 rd October at 12:00 noon.
The total annual grid sale is 9769 kWh.The grid sale for the selected date can be seen in Figure 15.
From the figure, the trend of the grid sale follow the PV energy production as the load demand during 8:00 AM to 7:00 P.M is low and almost constant.The data for selected date are sent to MATLAB/Simulink so that they can be transferred to ThingSpeak in every hour, similar to the case of real-time system.

Monitoring System
To monitor the electricity usage, the data from MATLAB/Simulink is sent to ThingSpeak with time sampling 1 hour, and the output of the ThingSpeak is as shown in Figure 16.From the figure, the four data have been sent to ThingSpeak successfully based on the trend and values displayed.The data was sent to ThingSpeak on 9 th March 2020, so the ThingSpeak automatically dispalys 10 March at the end of the graph, waiting for the next day data to sent.Since the monitoring data are screenshot from the ThingSpeak channel, the data can't be edited.

Figure 16. The four parameters are sent to ThingSpeak individually and displayed separately
The same data are sent to the mobile app which can be depicted as in Figure 17 when the user pressed monitor button.Control buton is used in control mode which is discussed in the next section.In monitor mode, the data are displayed on realtime and updated every hour in kWh unit.As can be :00 AM (c).At 4:00 AM, there is no energy production from PV, thus, the value is 0 kWh.The power load obtained energy directly from the grid purchase.At 7:00 AM, the   is too low to supply to the load, thus the grid purchase is used to supply the shortage.From the result, the   is 0.006 kWh obtained from equation ( 2), thus the inverter input is equal to   and inverter output is 0.181 kWh.The efficiency of the inverter is then can be calculated to be 96.8% as in Table 1.For the case at 11:00 AM, the   is lower than   , thus the excess energy is sent back to the grid via grid sale at 4.467 kWh.
From equation (1), the   is 0.156 kWh.Similarly, to calculate the efficiency of the inverter, the inverter input is equal to   , and inverter output is 4.71 kWh, thus, the efficiency is 96.8%.These results verified that the data have been sent successfully.
(a) (b) (c) Figure 17.Monitoring on mobile app for 3 different cases

Control System
In control menu, the developed system can be used in two modes, auto and manual modes which has ON and OFF button as in Figure 18.The button are used to control the switch connection for grid sale and grid purchase as in Figure 2. If the OFF button is pressed, the pink color appears.Similarly, when the ON and AUTO button are pressed, the color changed to cyan and yellow, respectively.In manual mode, when the user press OFF or ON button on mobile app, the data 0 or 1 is sent to ThingSpeak to represent OFF or ON button has been pushed, respectively, as seen in Figure 19.
There are also the same color of LEDs light up on the ThingSpeak.The data from ThingSpeak is then sent to MATLAB / Simulink as shown in Figure 20.In manual mode, the user can press the OFF/ON button without any condition and totally user dependent.For example, if the user is not at home for a long time, the connection of   can be closed all the time by pressing the OFF button, which causes  ℎ to be opened at all times.So, no electricity from the grid will be used during this period.

Open Access
In auto mode, the system will make a decision either to send the ON or OFF signal to MATLAB/Simulink based on the value of   and   .If   <   , the OFF signal is sent to MATLAB/Simulink to connect the   connection so that the excess electricty can be bring back to the grid.Meanwhile, if   >   , the ON signal is sent to MATLAB/Simulink to close the connetion between load and the grid to purchase electricity.Based on the data on the selected date as in Figure 21, the mobile app sends OFF signal to MATLAB/Simulink from 8:00 AM to 6:00 PM to connect between the inverter and the grid.During early morning and at night, the mobile app sends the ON signal to purchase electricity from the grid.
If ten signals from 4:00 AM to 1:00 PM are used to test the control signal in manual mode, and the delay of the signal is set to be shorter in 5 minutes so that the delay would be not too long, the result on MATLAB/Simulink can be seen as in Figure 22.From the figure, the timestamps show the actual date and time this experiment was done.Refer to the figure, from 17:48:25 to 18:03:29 that represent 4:00 to 7:00 AM, during this time   >   , it can be seen clearly that the value of the state is 1 showing that the signal received by MATLAB/Simulink is to close the  ℎ connection.Similarly, the state is 0 during   <   to connect the   .From the results, the state is correctly determined by the developed system based on the value of   and   .

Conclusion:
From the results obtained, the communication between MATLAB/Simulink, ThingSpeak and smartphone has been successfully developed.In monitoring system, all the selected data from MATLAB/Simulink can be sent to ThingSpeak and displayed on smartphone.In control system, the user can send the control signal to MATLAB/Simulink from smartphone either ON/OFF or auto mode.Using auto mode, the ON or OFF grid is determined by the system based on the value of PV power and load power.While in ON/OFF mode, the user has authority to connect or disconnect to the grid without condition.This work can be extended by integrating the data received by the MATLAB/Simulink from mobile app to be used in smart grid model to see the effectiveness of the controller in controlling the smart grid.
The cloud-based monitoring for smart grid realtime monitoring developed in MATLAB/Simulink.The well-known IEEE test grid topology was modified to support real-time communication with open source IoT platform ThingSpeak used for cloud computing.

Figure 2 .
Figure 2. PV system model developed on MATLAB / Simulink based on smart grid

Figure 3 .
Figure 3. Algorithm of the controller in MATLAB / Simulink

Figure 4 .Figure 5 .
Figure 4. Average solar irradiance and ambient temperature of selected site in 2019

Figure 6 .
Figure 6.Simulation of grid-connected PV system in HOMER software

Figure 9 .FigureFigure 11 .
Figure 9. Hourly PV energy generated from the system for a year

Figure 18 .
Figure 18.The dashboard of control system on mobile app.

Figure 20 .
Manual workspace of MATLAB/Simulink for OFF signal