ESP32 Microcontroller Based Smart Power Meter System Design and Implementation

Every house and workplaces should install electricity energy meter to evaluate the electricity consumption. Finally of consistently, a large number of us get stressed over the high power bill and it is need to check the energy meter once in a while. In this work a smart electricity energy meter using ESP32 microcontroller which monitor energy through the PZEM-004T at any time and send to the office. Where this PZEM -004T is used for voltage and current measurements. Then the records will send to the office and store in the SQL database and also web page which is used specific IP. The results have been generated using MYSQL and the curves of the values with the time are also plotted using Microsoft Excel 2010.


INTRODUCTION
Currently, the monitoring using intelligent techniques is important topic in our life [1].Analog mechanical meters have been changed to digital meters in smart grid, where the digital meters record use in real state of affairs.In smart meters, the human errors and ponder errors can be brought down by utilizing these devices [2].In order to communicate data for charging customers, smart meters are used which are an electronics measurement instruments [3].Different methods have been utilized for monitoring the photovoltaic (PV) system using various kinds of wireless sensor networks (Wi-Fi, ZigBee) [4].PV system are connected to the grid, where in smart grid foundation , the smart meter workspaces are an essential parts as far as communications and the accumulation of the information [5].Also, in the smart meter methods, two fundamentals groups are found according to their local area network.They are radio frequency and power line carrier.The collection node will gather the measurements of smart meter and other data which are transmitted by wireless radio.In order to manage the data at a main location, this data will send by various methods to the utility systems of data.The utility billing, outage management and other frameworks utilize the information for operational objectives [6].Two kinds of radio frequency techniques are given, mesh method and point to point method.In the technology of mesh, the smart meters speak one to another in order to shape a local area network cloud to a collector.The smart meters speak straightway to a collector, generally a tower.The tower collector transfers the data utilizing different techniques to the utility central position for processing.By using the utility power lines, smart meter requirements and other information could be transferred from the meter to a collection point, commonly in the distribution substation feeding the meter.After collecting the data locally by the smart meters, then it will send this data through the local area network to a data collector.The collector takes back the data and may or may not perform any treatment for the data.By using of a wide area network, the data will be sent to the utility central collection point for processing and utilizing by business applications.Since the communications route is two-way, signals or commands can be transmitted straightforwardly to the meters, people premise or distribution device [3].The conventional electricity transmission and distribution system have been amended to an interactive service network or a smart grid with the growing of power demand and growing use of energy.In the smart grid, one of the suggested solutions are the smart meters.One of the complete parts of smart grid is a wireless smart metering, which is used to recognize real-time data acquisition, meter reading analysis, real time monitoring, decision making, and etc.In order to construct and implement a ZigBee based smart power meter for reading power consumption and connects this data to the utility server for power data treatment, Kalaivani and Kaaviya [7] used new wireless communication methods.ZigBee protocol is utilized for wireless transmissions.Also, it designed a smart meter depend on energy consumption budget setting.It can be used the mobile phones and SMS to send the monthly budget of power and billing data to the user, where power monitoring method is utilized in this system.In this case it can manage the power consumption of the power system and this will lead to an overall decreasing in consumption and costs.A singular merit of power theft connotation is designed and customer can also ON and OFF the specific devices based on the power requirement.ARM cortex M4 microcontroller is utilized for controlling the smart meter.Simulation is performed utilizing embedded C Proteus software along with CCS compiler.This paper presents an intelligent energy meter which replaces the traditional one in order to reduce the dis advantages such as the accuracy.The rest of the paper is arranged accordingly as follows: Section 2 , introduces the ESP32 controller; while section 3 illustrates the PZEM-004T; proposed system structure is given in section 4; simulation results are showed in section 5, finally, the conclusion are in section 6.

ESP32 MICROCONTROLLER
In 2016, Espressif systems sent out a new device QFN48 named ESP32 in the work.This device used instead of the last microcontroller ESP8266.Therefore, in our study ESP32 has been used which is a cheap device, with low power consumption on a chip arrangement of microcontrollers.This controller also has different capabilities such as built-in Wi-Fi and Bluetooth property.It has a profoundly incorporated module powered by a double-core Tensilica Xtensa LX6 microprocessor and it is a little part having a size of only 25.5x18x2.8mm [8].It is implemented to be a very good solution for IoT devices [9].The ESP32 system structure is shown in Fig. 1.

System and memory
The proposed controller is a two core framework and with Harvard Architecture Xtensa LX6 central processing units.In the CPUs, the external , embedded memories, and peripherals are placed which are on the data and or the instruction buses .Two cores have been implemented in this microcontroller-PRO_CPU for protocol and APP_CPU for application.Then the space of the address for instruction and data bus is 4 GB and the peripheral address space is 512 KB.Besides, different embedded memories are also used like 520 KB SRAM, 448 KB ROM, and two 8 KB RTC memory.Finally, The outside memory bolsters up to four times 16MB Flash [10].

Clock and timer
Here, an oscillating circuit has been used as a clock supply at 2-40 MHz in order to produce the master clock CPU_CLK for the two central processing unit cores.In order to decrease the power consumption, it can be used 160 MHz for maximum rendering or lower for the clock.Master clock is driven the other clocks such as the APB_CLK for peripherals.Besides, different low power clocks such as the internal RTC_CLK with a default frequency of 150 KHz and the option to arrange it for deep sleep modes.For generic aims, four 64-bit timers with 16-bit prescalers are used with a range 2-65536.APB clock, generally at 80 MHz has been used in these timers.Also, up or down count can be done in those timers.PWM controller is driven by four generic timers.There are 16 pulse width modulation (PWM) channels which are divided to eight with high speed and

PZEM-004T
The better device to evaluate current , voltage and power when we utilizing ESP32 which is like open source platform [12].The designer normally deals with measurements in different electrical projects with little fundamental requirements such as : 1-Display of parameter.
2-High galvanic isolation 3-It can be stored with next sight or copying to the computer as well the use of data acquisition.
4-The connection with computer is direct.
This module avail whole these fundamental demands of gauge this chip as a split up board.The materialistic measures of the board is 3.1x7.4cm.The current transformer coil of 33mm is used with the PZEM-004T module as one package.The SD3004 chip is considered as a basic section of the PZEM-004T which is from the SDIC Microelectronics Co., Ltd.Also, a 2K bit serial electrically erasable PROM (EEPROM) from Atmel 24C02C found in the board.Two optocouplers PC817, supplying galvanic isolation of the serial interface.However, there are different merits for the PZEM such as: 5V supply voltage; It contains UART interface serially having 9600 speed; By PZEM the consumed electricity can be measured; LCD or LED displays can be connected to the panel.A built-in button on the board, utilized in order to make an electricity clear function.The method of clear the electricity is as follow: For 5 sec.the zero key should be pressed after that it should be released and then press second time to erase it, the data is erased and end charge erased.In addition, the structure can be compacted by interface communication of serial data of TTL and read by using of a serial port, then the parameters can be set.In case the job wants equipment with RS232 or USB for connection, thereafter, different panel of TTL hardware adapter should be superimposed with (RS232 needs with TTL to RS232 adapter while USB wants TTL to USB adapter).Lastly, the proposed structure used for internal and not external application, where the load that will be used should not be larger than predestined power ; The wiring can't be incorrect.Table 1 illustrates the fundamental requirements of the PZEM-004T.

PROPOSED SYSTEM STRUCTURE 4.1. Sender part (customer)
In this side the currents and the voltages of the load will be measured.First, using PZEM wattmeter which is composed of a current sensor and voltage sensor.In the current sensor, the The data is transferred in machine language in order to treated by microcontroller (ESP32) through the TTL serial data communication interface of the PZEM-004T as shown in Fig. 4. Fig. 4 PZEM-004T.The microcontroller will process the data when receive from the sensor, then will send by Wi-Fi technology.

Receiver Part (office)
When the system is received the readings which are V, I, P, and E, it should be stored in the database to process and also displays in the panel as shown in the full wiring connections Fig. 5. Fig. 5 The circuit of the system.Also to clarify the work and the procedures of the system a flowchart is given in Fig. 6.

SIMULATION RESULTS
Smart meter design with SQL database have been suggested in this paper.All the results have been simulated on a PC with Linux operating system, Intel Core i5 processor, 1 TB hard disk, and 8 Gbyte RAM.The followings tests are done to prove the proposed implementation.

Test one : Freezer as a load
The first test is applied on freezer device where the ratings of this device are, the current is 1.8A ,and the voltage is 220V, the practical implementation of this test is shown in Fig. 7 which is done on 10-11-2018.While Figs 8-12 present all the values required for the test such as voltage, current, active power , apparent power, and the energy.They are done on 10-11-2018 from 15:48:45 until 16:13:19 in the time axis.

Test two: Computer laptop as a load
The second test is suggested for a laptop device with the charger ratings of 220V , and 1.5 A as an input and 20V , and 4.5A as an output, the real time design of the test is in Fig. 13, as well as all responses of this test are given in Figs.

Test three: Soldering iron as a load
Soldering iron is third test given in this paper where the ratings of the voltage is 220V, while the power is 60W and the test is connected in Fig. 19.Figures 20-24 are the voltage, current, active power, apparent power, and energy of this test on 11-11-2018 at 17:52:12 to 18:07 In addition records are list in table 2 for all the tests.However, from the table there are some errors in the values of active power which may be because of the current transformer or because of some changes in the power factors due to the instability of the source.Hence, the values of the apparent power are accurate.Sample of MySQL results is illustrated in Fig. 25 for test 1

CONCLUSION
In conventional method of electricity billing, the responsibility of billing for each consumer is a time consuming job for the distribution grid.This paper presents a smart energy meter for an automatic metering and billing system .The main concept of this project is to design and implement the smart energy meter system in houses and in many public places based on the ESP32 microcontroller.Voltage, current, active power, apparent power , power factor, and energy, are measured with use of the PZEM-004T.Also, it can be concluded from the results that even if the freezer draw higher current than the other loads, but it is about to be constant during the time especially when compared with the second load.The current of the labtop depends on the processing and sometimes the heat of the CPU which may increase and need the cooling fan to turn on.The soldering iron is a resistive load with voltage and current which should be constant if the source is fixed.The final results show that, the proposed structure is appropriate to use our billing systems with less cost and easy maintenance and accurate measurements.As a future work, the project can be improved to use cloud computing in order to save the data and increases the transfer distance between the two terminals.

Fig. 2
Fig. 2 Functional diagram of ESP32.eight with low speed where each of them has four timers [11].The block diagram is shown in Fig. 2.

Fig. 14
Fig. 14 The voltage of test 2

Table 2 :
Record values of all test.