Lora Network and Esp32 Microprocessor AP
Lora Network and Esp32 Microprocessor AP
ABSTRACT
The objective of this article was to discuss the application of LoRa network and ESP32 microprocessor in a
prototype of a polyphase electronic electric energy meter. The application was developed for a company in the
Manaus Industrial Complex. The article is considered exploratory, applied and qualitative under the aspects of
bibliographic research and case study. Data collected through meetings, technical visits and research on the
theme. The evolution of smart meters generates innovation to the energy network and optimizes the reading and
data recorded by electronic meters. Results showed the capability of long-distance remote communication and
efficiency in energy consumption data recording.
Keywords - LoRa Network, ESP32, Smart Meters, Remote Communication.
---------------------------------------------------------------------------------------------------------------------------------------
Date of Submission: 04-09-2022 Date of Acceptance: 19-09-2022
---------------------------------------------------------------------------------------------------------------------------------------
networks, with low cost, security and bidirectional
I. INTRODUCTION communication [4]. It has communication range of
The Smart Grid is a technological up to 20 km in rural areas and 4 km in urban areas
innovation, an alternative for supplying electric and support for redundant operation technologies,
power distribution needs. It has been acquiring space free localization, low power consumption, and
in other countries as well as in Brazil, in view of energy harvesting to support future network needs,
events in the electrical sector with constant failures
enabling mobility of use features [5]. A LoRaWAN
and surges. The term Smart Grid refers to an electric
power system that uses information technology to network uses unlicensed bands and open and free
make the system more efficient, reliable and protocols, making it easy to deploy [6]. LoRaWAN
sustainable [1]. has been used in REI applications mainly for remote
The Smart Grid is a new, interactive model metering infrastructure.
for both power generation sources and loads. The
old central and vertical model is replaced by a II. LITERATURE REVIEW
distributed and disaggregated one in which different 2.1 Electronic Meter
customers emphasize different aspects of the new Electronic meters have distinct classes of
power grid according to their perspective [2]. accuracy that can reach levels of 0.2%, when active
In this system, it involves the application of
energy measurement is performed, besides having
processors, in order to perform tasks on the
microsecond scale, intelligent applications, demand great facility in the implementation of new
management, to optimize generation costs and functionalities and lower production costs when
energy utilization, sensors, to identify abnormalities compared to their predecessors [7][8].
in the system. In short, it is a modern and inter The technological advance in embedded
connected system [3]. systems has made further improvements in
LoRa is a communication protocol for measurement systems feasible, thus emerging smart
LPWAN (Low Power Wide Area Network) meters [9], which not only have characteristics in
performing readings of energy and electrical require licensing, such as 433, 868 and 915 MHz
quantities, but also offer the possibility of local and [19][20], for example. It is a type of network that is
remote communication, addition of power quality being used for connection between devices for low-
indicators, cut-off and reconnection via internal power, long-distance applications, given that in open
relay, alarms, and anti-fraud events [10]. field it is possible to achieve up to 15 km of range
[21][22]. In a simplified way, the LoRa system is a
2.2 Smart meters module placed in end devices and also in gateways,
Smart meters are increasingly being deployed in which are able to get data out of a LoRa network and
many global markets. New elements integrated into through an IP connection reach local and/or remote
the meter give it the ability to capture, process, servers [23]. The modules send and receive data
respond, and communicate new information from gateways in a similar way to Wi-Fi networks,
[11][12]. The sharing of this information with other but with much greater range. Their main applications
members of the electrical system, such as power are IoT systems such as remote sensors and
generation units or even transmission and control monitors, especially those that are battery operated
system elements, provides, among other things, and in some cases in remote locations [24].
greater agility in identifying and solving operational
problems and more efficient management of the 2.5 Raspberry Pi Pico
flow of energy, which starts to be directed through From the Raspberry Pi family of single board
more reliable routes to the points that have demand computers, Raspberry Pi Pico is the first high-
to be met [12]. performance, low-cost microcontroller board
The Smart Grid is a technological innovation, an product built on RP2040 chip. The Pico features a
alternative to supply the needs of electric power Dual-core cortex M0+ processor with phase-
distribution. It has been acquiring space in other controlled loop chip to adjust the core frequency.
countries as well as in Brazil, in view of events in With a clock speed of 133 MHz, the Pico has a 264-
the electrical sector with constant failures and surges byte SRAM and 16-byte on-chip cache. Sixteen
[13]. The term Smart Grid refers to an electric power PWM channels, real-time counter, 12-bit analog to
system that uses information technology to make the digital converter, thirty multi-function I/Os, and an
system more efficient, reliable and sustainable [14]. integrated USB 1.1 add to the Raspberry Pi Pico's
features. Pi Pico runs on MicroPython, an
2.3 Hall Effect Current Sensor implementation of Python Programming [25] [26].
Linear current sensors based on the Hall Effect
are devices capable of monitoring direct and III. MATERIALS AND METHODS
alternating currents without the need for physical 3.1 Solution Architecture
interaction between the monitoring circuit and the For the development process of the polyphase
power circuit to be monitored, called galvanic LoRa meter, the embedded software was separated
isolation [15]. into 3 distinct parts, which act on different
The Hall effect is about a potential difference in microcontrollers and different platforms:
an electrical conductor, transverse to the current
flow subjected to a perpendicular magnetic field [16] 1. LoRa Transmission Interface;
[17]. Its output voltage is proportional to the 2. Arduino Nano;
magnetic field to which the sensor is exposed. This 3. Receiving LoRa Interface.
voltage may be positive or negative according to the
displacement in space of the magnetic field Each of these parts has a specific function to not
generator or the direction of the current if it is the overload the processing, and to improve the
generator of the magnetic field [18]. performance of the consumption measurement in
(kWh) by the prototype meter. This division of
2.4 ESP32 LoRa
function alities can be seen in Figure 1.
The name LoRa is short for the words Long
Range. LoRa network is a wireless solution in
networks below GHz, in frequencies that do not
The Arduino Uno was responsible for treating the relationship between voltage and current, P = V
the signal measured by the current sensor, as well as x I, and the consumption that is the calculation of
acting in relays to control the passage of current in power over time.
the three phases, this through the digital ports of the However, this measured current is in the form of
Arduino. However, in addition to these a sinusoid, at 60Hz, and to calculate consumption
functionalities, it was responsible for sending and the Root-Mean-Square (RMS) current was used. In
receiving the commands from the Nextion display order to perform this calculation we used the library
through the library of the same name "Nextion.h", Emonlib (energy measurement library), which is an
which was done serially. Open Source library that receives the values from
As the Arduino Nano has only one pair of UART the ADC and calculates from several samples the
ports (RX/TX), and this is used to communicate the RMS value of the current through the function
microcontroller with the Nextion display, it was "emon1.calcIrms(number of samples)".
necessary to use a library called "SoftwareSerial.h",
which emulates more pairs of UART ports through 3.4 Receiving LoRa Interface
the Arduino's digital ports, to communicate with the
Similar to the transmitting ESP32 LoRa, the
ESP32 LoRa and send the collected information.
receiving one has the same form of configuration, as
The current measurement made by the sensors is
both must have the same specifications in order for
returned to the microcontroller through a voltage
communication to be established. The difference
proportional to the measured current, and this is
between these is the reading of the data from the
interpreted by the analog inputs of the Arduino
LoRa network.
through a 10-bit ADC (Analog-to-Digital-
This reading was done through the
Converter), and this is treated to eliminate noise
"receivePacket()" function, which checked every
through a digital filter in the function
cycle the "parsePacket()", which is nothing more
"filtroDaMedia()", and a calculation of the ratio of
than a function that checks the packet size, if any,
the ADC from 0 to 1024 for current from -30 to 30
and if so, starts assigning the received values to the
Amperes is made through the function
variables that will be shown on the OLED display.
"calculatesCurrent()".
The power consumption was calculated through
3.5 Analog Digital ADC - Raspberry Pi Pico
the current and voltage measured according to the
NBR 5410 that addresses the "Low Voltage The Raspberry Pi Pico's internal ADC analog-to-
Electrical Installations", calculating the power that is digital converter has a 12-bit resolution, but it is
possible through SARS technology to optimize the
ADC for a 16-bit readout, transforming a signal read is done through a coupling circuit that is shown in
from 0 to 3.3 V into a digital value between 0 and Figure 3.
65536. To read AC values at the microcontroller
input it is necessary to condition the signal, and this
With the voltage and current conditioned for For the development of the LoRa meter, the
reading in the ADC, C++ programming is used to ACS712 current sensor was used, an integrated
perform the reading of the two magnitudes almost sensor that uses the Hall effect to obtain the
simultaneously, this is possible through the internal measured current in a linear fashion. From this
CLOCK of 48 MHz, where to perform a reading of a microchip, it was possible to use its module
sample of the ADC it takes 96 cycles of CLOCK, evidenced in Figure 4, to measure currents both in
indicating a maximum speed of 125 kHz for each of direct and alternating form, with an isolation of up to
the four channels, but we used a default value of 2.1 kVRMS.
61.55 kHz:
- Channel 1 (ADC0) = Voltage
- Channel 2 (ADC1) = Phase A current
- Channel 3 (ADC2) = Phase B current
- Channel 4 (ADC3) = C Phase current
In this research, due to the requirement of shown in Table 1, is capable of measuring between -
measuring a high current, the model 30A and +30A, and has a sensitivity of 66 mV/A.
ACS712ELCTR-30A-T was chosen. This model, as
Table 1 - ACS712 chip models.
Optimized Range, Ip Sensitivity, Sens
Part Number Packing TA (ºC)
(A) (Typ) (mV/A)
ACS712ELCTR- Tape and reel, 3000 -40 to
+/-5 185
05B-T pieces/reel 85
ACS712ELCTR- Tape and reel, 3000 -40 to
+/-20 100
20A-T pieces/reel 85
ACS712ELCTR- Tape and reel, 3000 -40 to
+/-30 66
30A-T pieces/reel 85
Source: Adapted by authors, (2022).
The sensor datasheet indicates, from Figure 5, operation is done by feeding the module through the
the definition of each pin of the module, and its VCC and GND ports, applying a voltage of 5V.
The sensor was then placed in series with the With this connection, and being powered by the
circuit where you want to measure the current, as Arduino Nano, the module was connected to one of
pointed in Figure 6, passing through the internal the microcontroller's analog outputs to perform the
resistor (Shunt) of 1.2 mΩ that generates a magnetic analog to digital conversion, using the Arduino's
field measured by the chip through the Hall effect. internal A/D that has a 10-bit resolution.
The shunt circuit is composed of two stirrups, Arduino, as shown in. To measure the current in
made of steel and a mangaline plate, in which the polyphase form, three current sensors were used, one
wires were soldered and installed in the terminals of in each phase of the meter, each connected to a
the current sensor. Through this connection, the channel of the relay module. The wiring diagram of
circuit for simulating the current measurement was the current measurement can be seen in Figure 7,
obtained. In order to control the operation of the indicating all the sensors and the control through the
phases and automatically turn the power grid on and switches with relay, being necessary 2 modules of 2
off, a 30A relay module was used, which is channels due to the necessity of the control of the 3
controlled by the Arduino's digital ports. phases.
The connection of this relay module, which has
two channels and can be triggered either by logic
level 5V or 3V3, connected to the digital ports of the
Nano, where the firmware responsible for output This project used the ESP32 LoRa
commands and sensor readings was embedded. microcontrollers to communicate the information
collected from the meter through the Arduino Nano
3.7 ESP32 LoRa and trigger commands over long distances, this
through a division between a LoRa Master (Master)
In order to send the information from the
meter which sends requests and commands, and a
electronic polyphase LoRa meter, as well as receive
LoRa Slave (Slave) meter which returns the
commands in places with low internet connectivity,
requested information and carries out the requested
over long distances, we used the ESP32 LoRa
commands.
SX1276 868/915 Mhz module with OLED 0.92'' V2,
This idea was conceived so that the ESP32 LoRa
which has as microcontroller the ESP32 from
(Master) could connect to several electronic meters
Espressif, which has a high performance for
serving as a Gateway, and in this way could collect
applications involving WiFi, with very low power
the consumption measurements, monitored currents
consumption.
of each phase and store this in a database, or on a
In addition to the ESP32's high performance, it
local disk. The first step was to perform a unit test
features the semtech LoRa chip, which is
and perform a communication between the two
characterized by a connection through the LoRa
ESP32s through the LoRa network, initially using
network, with an SMA antenna (U. FL 2 mm),
the Slave to send a standard data packet, in the form
which is one of the newest radio frequency
of a counter, as can be seen in Figure 9 and Figure
technologies, characterized by low power
10.
consumption and communication over long
distances, thus being suitable for the most varied
projects involving WiFi and IoT networks. It has a
frequency of 868/915 MHz and can reach distances.
Figure 10 - Information being sent via LoRa. Figure 11 - Data reception test with LoRa.
Source: Authors, (2022). Source: Authors, (2022).
To receive this packet of data sent, another
To complete this test, the microcontrollers were
ESP32 LoRa was used, with the sole function of
separated at various distances in order to verify that
receiving the data sent and showing it on the OLED
the information was being sent and received
display screen, and while no data was received,
properly, and by sending a consecutive counter that
showing the text "Awaiting Data..." on the screen, as
increased the value every 1 second, it was possible
can be seen in Figure 11.
to validate the operation of sending information over
the LoRa network. Figure 12 evidences this data Figure 12 - Emission and reception via LoRa.
passage, but to facilitate the simultaneous Source: Authors, (2022).
visualization, the picture was taken with the two
ESP32s close together, where it is possible to see the With the full operation of sending and receiving
number 29 being transmitted. data via LoRa, we started to capture the data
provided by the Arduino, since it is responsible for
capturing the measurements of the current sensors,
and calculate consumption, as well as the RMS
value (Root Mean Square). This communication is
made through a UART communication, i.e., RX/TX,
but as the Arduino Nano has only one RX/TX serial
input, the "Software Serial" library was used to
emulate a UART output programmed in digital ports
of the Nano, through ports D02 and D03, as shown
in the diagram of Figure 13.
Putting together all the isolated connections from 14. The main terminal block has been omitted (for
each part of the development, a large diagram was better representation), where the phase currents are
assembled to illustrate the electronic connections of measured.
the LoRa Polyphase meter, as can be seen in Figure
IV. RESULTS AND DISCUSSION storage program was developed. This is done
through a mechanism called DMA (direct memory
4.1 Signal Sampling (MATLAB)
access), where a reading configuration is sent, and
To validate the operation of the microcontroller the microcontroller takes care of reading a sample
readout, and verify that the measurement is within from each of the channels, at a defined speed, and a
an acceptable range where voltage and current defined sample size. This mechanism can be seen in
control can be applied, a voltage and current sample Figure 15.
This comparison measurement was performed with an Agilent DSO3102A oscilloscope (Digital Storage
Oscilloscope), which performs measurements up to 100 MHz, with a sampling rate of 1 GSa/s, compared to the
Raspberry Pi Pico which has a sampling rate of 61.44 kSa/s.
Figure 16 shows the entire circuit of the LoRa distance simulation of the sending and capturing of
polyphase electronic meter, as well as a short data, the visualization through the Nextion display,
After the meter was fully operational, the small 170-hole protoboard to fix the Arduino Nano,
mechanical assembly of the housing was used to fix as well as the other modules, all parts were attached
the electronic components and modules. Using a inside, as shown in Figure 17.
4.2 Simulation of long distance transmission to an external artificial power supply was moved
away until the interruption of the data transfer was
To validate the operation of the meter, in relation
noticed, which was verified at the location indicated
to transmission over long distances, a fixed position
in Figure 18, and was obtained through Google
was identified for ESP32 LoRa reception to read the
Maps, using the "Measure distances" tool.
data, which was at the Wasion da Amazônia
company itself, and the electronic meter connected
This distance was captured in a sparsely stretch between the locations. In addition, the
populated region, it is an industrial region, where altitude of the two locations was also different, as
there are no large buildings, facilitating data according to the topographical map, seen in Figure
transmission. However, in a deeper analysis of the 19, which indicates that the data reception location is
route between emission and reception, it was noted approximately 85 meters above sea level, and the
the various characteristics of the relief and obstacles, transmission location is approximately 66 meters
such as the existence of a small neighborhood in the above sea level.
To check the maximum distances for the the receiver until the signal was interrupted, as can
communication to remain between sender and be seen in Figure 20.
receiver, the meter was moved gradually away from
At the maximum distance between the two the same value is seen in both screens of 89 (kWh),
microcontrollers, the consumption and current and 1.1 (A) in the current of phase A. This was
values were noted to validate the correct sending of possible by using an external source to simulate the
the information, as can be seen in Figure 21 where current consumption.
As shown in Figure 21, on the left side being 1A in phase A, 0.10A in phase B, and 0.20A
there is the prototype meter, the display shows the in phase C.
consumption of 89 kWh, and on the right side there
is the ESP32 receiving data from the prototype. On V. CONCLUSION
its display it is possible to identify the receipt of Electronic electrical energy meters, are
consumption, registering the same 89 kWh sent by static meters in which current and voltage act on
the prototype, in addition to the data of the phases, solid state elements (Electronic Components) to
produce an output information proportional to the
amount of electrical energy measured. These meters [3]. SOUSA, Jeovane Vicente de. Computação
are basically composed of transducers, multipliers, em nuvem no contexto das smart grids:
integrators, and recorders. With the evolution of the uma aplicação para auxílio à localização de
electrical grid, the so-called Smart Grids are faltas em sistemas de distribuição. 2018.
Tese de Doutorado. Universidade de São
emerging in large poles and have the potential to
Paulo.
modernize the Electrical Grid, with the use of IoT. [4]. ZYRIANOFF, Ivan et al. Impacto de
This system involves the application of processors, LoRaWAN no Desempenho de Plataformas
with the purpose of performing tasks on the de IoT baseadas em Nuvem e Névoa
microsecond scale, intelligent applications, demand Computacional. In: Anais do XVII
management, to optimize generation costs and Workshop em Clouds e Aplicações. SBC,
energy use, and sensors, to identify abnormalities in 2019. p. 43-56.
the system. In short, it is a modern, interconnected [5]. SALMAN, Tara. Internet of things
protocols and standards. Affairs, M. Of
system.
END, 2015.
LoRa refers to the communication protocol [6]. BARRO, Pape Abdoulaye; ZENNARO,
for LPWAN (Low Power Wide Area Network) Marco; PIETROSEMOLI, Ermanno. LTN–
networks, with low cost, security, and bidirectional The local things network: on the design of
communication. It has a communication range of up a LoRaWAN gateway with autonomous
to 20 km in rural areas and 4 km in urban areas, and servers for disconnected communities. 2019
support for redundant operation technologies, free Wireless Days (WD). IEEE, 2019. p. 1-4.
localization, low power consumption, and energy Disponível em:
harvesting to support future network needs, while https://ieeexplore.ieee.org/document/8734239
. Acesso em: 10 Jan. 2022.
enabling mobility usage features. LoRaWAN has
[7]. PINTO FILHO, Tito Livio de Miranda.
been used in Smart Grid applications mainly for Medidor eletrônico de energia elétrica
remote metering infrastructure. bidirecional não invasivo. 2019.
In view of this, this paper presented a [8]. INMETRO. Regulamento Técnico
proposal for the application of LoRaWAN and the Metrológico – RTM. Portaria INMETRO
ESP32 microprocessor in a prototype of an electric N.º 587 2012.
energy electronic meter, creating the possibility of [9]. MENDONÇA, Rodrigo Nagy. Metodologia
communicating the consumption data of each user de teste de sistemas embarcados aplicada a
medidores inteligentes e sistemas de
remotely. The electronic application was referenced
medição centralizada. 2019. 62 f.
using micro controllers, embedded systems, sensors Monografia (Graduação em Engenharia
and shunt circuits. Elétrica) – Universidade Federal do Ceará,
Fortaleza, 2019.
ACKNOWLEDGEMENTS [10]. FURLAN, Enzo Gabriel Belloto. Solução
To the Institute of Technology and automatizada de testes de validação em
Education Galileo from Amazonia (ITEGAM) and medidores eletrônicos de energia elétrica.
Wasion Amazonia Industry of Electronic 2018.
[11]. MEGIER, Guilherme Rucks. Transação de
Instruments Ltda. Law 6.008/1991 with resources of
energia elétrica PEER-TO-PEER em
RD&I Project (SUFRAMA/CAPDA) to finance and Redes Elétricas Inteligentes.
support the research. [12]. KOENDJBIHARIE-CRISIS, Josmela
Shantal. Projeto conceitual de plataforma
REFERÊNCIAS
laboratorial de micro rede inteligente para
[1]. SHAHINZADEH, Hossein et al. IoT campus universitário. 2016.
architecture for smart grids. In: 2019 [13]. TOLEDO, Fabio. Desvendando as Redes
International Conference on Protection and Elétricas Inteligentes-Smart Grid
Automation of Power System (IPAPS). IEEE, Handbook. Brasport, 2012.
2019. p. 22-30. [14]. SANTOS, Mauricio de Carvalho; NUNES,
[2]. SCHOENUNG, Susan M. et al. Energy Rafael Policarpo. Redes inteligentes de
storage for a competitive power market. energia. 2018.
Annual review of energy and the [15]. FORTES, Márcio Zamboti et al. Análise da
environment, v. 21, n. 1, p. 347-370, 1996. adoção de medidores inteligentes como
instrumento da política pública de