SUGISAKAMASANORI

Journal of Robotics, Networking and Artificial Life
Vol. 10(4); March (2024), pp. 313–317
ISSN (Online): 2352-6386; ISSN (Print): 2405-9021
https://alife-robotics.org/jrnal.html

Research Article

MCU Based Edge Computing Platform for Liquid Level
Measurement
Chung-Wen Hung1, Chun-Liang Liu1, Tai-Hsuan Wu1, Chau-Chung Song2

National Yunlin University of Science and Technology, Taiwan, 123 University Road, Section 3, Douliou, Yunlin 64002, Taiwan, R.O.C
National Formosa University, Taiwan, 64 Wenhua Road, Huwei Town, Yunlin County 632301, Taiwan, R.O.C

1
2

ARTICLE INFO
Article History
Received 15 November 2023
Accepted 31 July 2024
Keywords
Label smoothing
Edge computing
Audio process
Hyperparameter

ABSTRACTAn MCU(microcontroller unit)-based edge computing system for assessing the height of liquids
in containers in this paper. This system uses a solenoid valve to strike the bottle and a microphone
to capture sound waves. Signals are transformed from the time domain to the frequency domain
by FFT (Fast Fourier Transform) and used to predict the water level by using AI (artificial
intelligence) model. A dynamic label smoothing method enhances label correlation, and an ANN(Artificial Neural Network) model is employed on the MCU for classification. The systemaccurately predicts water levels from 200 to 250 milliliters at 1-milliliter intervals.
Hyperparameter optimization balances accuracy with MCU memory and computational
constraints. Experimental results show that the system achieves an accuracy of 81% under thelimits of edge computing, verifying its effectiveness in liquid level measurement applications.

© 2022 The Author. Published by Sugisaka Masanori at ALife Robotics Corporation Ltd.
This is an open access article distributed under the CC BY-NC 4.0 license(http://creativecommons.org/licenses/by-nc/4.0/).

Bayesian optimization stands out as an efficient method
for hyperparameter tuning.
The paper introduces an edge computing system
employing an MCU to measure liquid levels, employing
the Artery AT32F415 [7] consumer MCU for allcomputations and controls, including data acquisition.
By utilizing one-dimensional audio data, the proposed AI
model maps audio features to different groups throughmodel learning, effectively reducing memory footprint.
The system incorporates a data sampling function during
the training phase, transmitting collected information toa PC for hyperparameter optimization and model training.

1. Introduction
The rapid expansion of artificial intelligence has led toa multitude of applications across consumer andindustrial sectors [1]. Edge computing [2], [3], [4] has
become a critical focus area, with particular emphasis on
utilizing endpoints for model computation to minimize
network latency and expenses. In scenarios wheretraditional sensors are impractical or costly, exploringalternative AI-based measurement techniques becomes
essential.
One such application involves analysing the soundproduced by impacted containers, such as bottles, whereliquid levels influence vibration frequencies. As noted in[5], sound-based water level determination is dependent
on specific vessel geometries, making AI models a viable
solution for this measurement approach.
Considering the resource constraints of endpoint
platforms, it is crucial to select appropriate AI models
and optimize hyperparameters for edge computing. ANN
models are known for their simplicity and effectivenessin classification tasks, making them a promising
candidate model for this paper [6]. Furthermore,

Methodology
1.1. SYSTEM STRUCTURE
Fig. 1 presents the system diagram, which
incorporates two micro switches to initiate the process ofknocking, sampling, and edge computing. These
switches are crucial for maintaining consistent hitting
conditions, including distance and position.
The MCU serves as the core of the system,
orchestrating the entire operation and providing edge

Corresponding author E-mail: wenhung@yuntech.edu.tw, clliu@yuntech.edu.tw, m11112080@ yuntech.edu.tw, ccsong@nfu.edu.tw

313

For the classification task, an ANN model was
selected. The ANN, with its simplicity, classification
efficiency, and lower memory and computational
resource requirements, proves more suitable for
deployment on edge computing platforms such as MCU
compared to other AI models. This approach provides anefficient and resource-friendly solution for water levelclassification.
This paper employs an electromagnetic striking
device to generate sound samples from glass bottles
containing varying amounts of water. The water volume
ranges from 200 ml to 250 ml, with samples taken at 1
ml intervals. The collected sound data undergoes preprocessing before being used to train an artificial neuralnetwork model. Notably, the model training utilizes only
the sampling data from 200, 210, 220, 230, 240, and 250
ml volumes.

computing functionalities. For training purposes, thesystem utilizes UART (Universal Asynchronous
Receiver/Transmitter) protocol to transfer data between
the MCU and PC. This communication channel allows
for the transmission of sound samples from themicrocontroller to the computer for model training.

Fig. 1 The system diagram
An H-Bridge [8] is used to drive the knocking
mechanism (a solenoid electromagnet), enabling precise
control over its extension and retraction movements so it
can strike the water bottle. A microphone is used tocapture the knocking sound. The capacitive microphone
converts sound waves into voltage, which is thenamplified in amplitude. The voltage offset is calibratedusing an operational amplifier (OPA) circuit [9] to ensurecompatibility with the input range of the ADC (Analog
to Digital Converter).

Fig. 2 Audio time domain at different water levels

1.2. DATA ANALYSIS AND REPROPCESSING
Before modeling, data analysis is paramount. The
converted sampling data is transmitted to a PC via UART
for analysis and training. Audio voltage sampling occurs
at 10 kHz, with 2048 points collected per trigger. Fig. 2
displays time domain waveforms for various water levels,
showing no saturation or truncation, indicating
appropriate sampling rate and length for this application.
To facilitate algorithm development, Fouriertransform is applied to convert time domain data into thefrequency domain, as illustrated in Fig. 3. Notably, thefirst spike's frequency decreases as water volume
increases, aligning with auditory observations. The
analysis utilizes frequency information between 83 Hz
and 1464.8 Hz for water level identification.
This study utilizes FFT for data pre-processing. To
mitigate the impact of abnormal waveforms and optimize
system performance, each dataset undergoes min-max
normalization. This normalization technique scales thesound amplitude values to a range of 0 to 1 using theprovided Eq. (1). In the formula, 𝑋𝑋 represents theoriginal data, 𝑋𝑋𝑛𝑛𝑛𝑛𝑛𝑛 is the normalized result, and𝑋𝑋𝑚𝑚𝑚𝑚𝑚𝑚 and 𝑋𝑋𝑚𝑚𝑚𝑚𝑚𝑚 are the maximum and minimum values inthe dataset respectively.
𝑋𝑋 − 𝑋𝑋𝑚𝑚𝑚𝑚𝑚𝑚∈ [0,1]
𝑋𝑋𝑛𝑛𝑛𝑛𝑛𝑛 =𝑋𝑋𝑚𝑚𝑚𝑚𝑚𝑚 − 𝑋𝑋𝑚𝑚𝑚𝑚𝑚𝑚

Fig. 3 Frequency domain at different water levels
1.3. LABEL SMOOTHING
In the training of neural network models, one-hot
encoding is usually used to mark different samples forclassification purposes. One-hot encoding sets only thecorrect sample classification to 1, while otherclassifications are set to 0, as Eq. (2). 𝑖𝑖 is represented thetarget label to be annotated, and 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 denotes the true
category of the target label. The target label is set to 1,
and all others are set to 0.
1,
𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿[𝑖𝑖] = �
0

(1)

314

𝑤𝑤ℎ𝑒𝑒𝑒𝑒 𝑖𝑖 = 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡(2)

One-hot encoding causes the model to focus on
increasing the prediction probability of the true classduring training. However, it cannot represent any
relationship between categories and ignores theirsimilarities. In addition, for datasets with small amountsof data or large models, overfitting may occur as thenumber of training iterations increases.
In order to solve this problem, this paper uses labelsmoothing for annotation. Unlike traditional labelsmoothing shown in Eq. (3), which adjusts the original
definite true label from 1 to a value slightly less than 1
and distributes the reduced portion( 𝐾𝐾 ) to otherclasses( 𝑁𝑁 − 1 ), this paper proposes a dynamic labelsmoothing [10], [11], [12] method.
𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿[𝑖𝑖] = �

1 − 𝐾𝐾,
𝐾𝐾(𝑁𝑁 − 1)𝑤𝑤ℎ𝑒𝑒𝑒𝑒 𝑖𝑖 = 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡

value. This normalization preserves the original
proportional relationship between values while making
the sum of all label values equal to 1.
This approach prevents the model from becoming
overly confident in predicting a single class, thereby
improving its generalization ability. It also enables themodel to consider the potential correlations between
different classes, dynamically adjusting the label values
based on these correlations.
1.4. HYPERPARAMETER OPTIMIZATIONIn deep learning algorithms, the choice ofhyperparameters determines the size and performance of
the artificial intelligence model. These parameters, suchas the number of in each layer, hidden layers, andactivation functions directly affect the architecture of themodel and its ability to generalize to new data.
Traditionally, researchers prioritize the hyperparameter
combination that yields the highest accuracy for
implementation in MCU. However, in edge computing
systems, resource limitations become a crucial factor.
Therefore, it's essential to strike a balance between
meeting accuracy requirements and selecting parametersthat align with the available computational resources.
This approach ensures optimal performance within theconstraints of edge devices.
Bayesian optimization [13] is an effective method forsolving black-box optimization problems. Unlike
traditional approaches such as random search or gridsearch, Bayesian optimization constructs a GaussianProcess model of the objective function as a priordistribution. This Gaussian Process efficiently utilizes
past evaluation results and predicts uncertainties, guiding
subsequent search processes. By leveraging theprobabilistic model, Bayesian optimization caneffectively explore the parameter space and exploit
promising regions, leading to more efficient optimizationcompared to conventional methods.

(3)This method does not distribute the same label value
equally among all incorrect labels. Instead, it
dynamically assigns tag values based on the correlation
between each tag and the correct tag. The correct label isassigned the highest label value, while other categories
receive their respective label values based on how related
they are to the correct label, as shown in Eq. (4). Here, 𝐾𝐾
and 𝑆𝑆 are coefficients that need to be preset. The value of
𝐾𝐾 indicates how much the correct label will receive,
while 𝑆𝑆 affects the value at which the label values for theincorrect labels decrease. The variable 𝑛𝑛 represents the
distance from the correct label. In Fig. 4, the label
assignment scenarios under different K and S values canbe observed.
1 − 𝐾𝐾,𝑖𝑖𝑖𝑖(𝑖𝑖 = 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡)
𝐾𝐾
𝐿𝐿𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎[𝑖𝑖] = �, 𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒(𝑆𝑆 × 𝑛𝑛!)

(4)

Fig. 4 Label value distribution under different 𝑲𝑲 and 𝑺𝑺
coefficients
𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝑙𝑙𝑁𝑁𝑁𝑁𝑁𝑁 [𝑖𝑖] =𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿[𝑖𝑖]∑𝑁𝑁
𝑖𝑖=1 𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿[𝑖𝑖](5)

To ensure that the labels sum to 1, the overall labels
are normalized using Eq. (5). 𝑁𝑁 represents the number oflabel categories, and 𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝐿𝑙𝑙𝑁𝑁𝑁𝑁𝑁𝑁 is the modified label315

2. Results and Discussion𝑛𝑛

1^
𝑅𝑅𝑅𝑅𝑅𝑅𝑅𝑅 = � �(𝑦𝑦𝑖𝑖 − 𝑦𝑦𝑖𝑖 )2
𝑛𝑛

(7)

𝑖𝑖=1

Compared to MAE, RMSE is more sensitive toextreme errors as squaring errors amplifies the impact oflarge deviations, effectively penalizing large errors moreheavily.
These results indicate good overall predictive
performance of the model, but the presence of somelarger errors leads to a relatively high RMSE. This aligns
with the observations from the confusion matrix.
3. Conclusion
This paper presents an MCU-based edge computing
platform for liquid level measurement. The system
encompasses not only physical components such as the
MCU, audio signal pre-processing circuit and striking
mechanism but also provides a detailed explanation of
the development process. This includes thenormalization of sampled data, the introduction of labelsmoothing techniques, and the optimization of
hyperparameters.
In the experimental setup, glass bottles were utilized,
which resulted in more pronounced energy variations in
the impact sounds. This choice of container material
enhanced the system's ability to differentiate between
various liquid levels based on acoustic signatures.
After multiple tests, it was determined that using 200,
210, 220, 230, 240, and 250 ml as model inputs could
effectively predict results across the 200-250 ml range at
1 ml intervals. The experimental results yielded an
accuracy of 81%, while requiring only 76KB of MCU
memory. These findings demonstrate the system's
viability and confirm its satisfactory measurement
precision, highlighting the efficient use of limited
computational resources in edge computing applications.

Fig. 5 Confusion matrix smoothed by dynamic labels
The water level prediction model was trained using
dynamic label smoothing, with 200, 210, 220, 230, 240,
and 250 ml as the primary labels. After training, theconfidence scores of models for these six labels wereused to extend predictions to 1 ml intervals, achieving
finer water level predictions. Fig. 5, 4, 3 shows theconfusion matrix for this model. While some samples in
the red frame area deviate from their true label, most
predictions are clustered within ±5 ml of the actual label.
After hyperparameter optimization, the model accuracy
was 82%, indicating that the model performed well. The
entire model requires only 76KB of MCU memory.
Mean Absolute Error (MAE) calculates the averageabsolute difference between predicted and actual values,
as shown in Eq. (6)𝑛𝑛1^𝑀𝑀𝑀𝑀𝑀𝑀 = � | 𝑦𝑦𝑖𝑖 − 𝑦𝑦𝑖𝑖 |𝑛𝑛(6)References

𝑖𝑖=1

1.

Where 𝑛𝑛 is the number of samples, 𝑦𝑦𝑖𝑖 is the actual^

value of the 𝑖𝑖 -th sample, and 𝑦𝑦𝑖𝑖 is the predicted value ofthe 𝑖𝑖 -th sample. MAE is easily understood andinterpreted. It can directly reflect the average deviation
between predicted and actual values. A smaller MAE
indicates more accurate predictions. However, it weighs
all errors equally, failing to distinguish between large andsmall errors, which can lead to incomplete judgments in
scenarios with extreme errors.
To complement MAE, this experiment also calculated
the Root Mean Square Error (RMSE), which is the squareroot of the average of squared differences between
predicted and actual values. RMSE helps assess theimpact of extreme errors. Its formula follows Eq. (7),where the variables are defined as in the MAE equation.

2.

3.

4.

5.

316

C. W. Hung, S.X. Zeng, C.H. Lee, W.T. Li. End-to-End
Deep Learning by MCU Implementation: An Intelligent
Gripper for Shape Identification. Sensors, 2021, Volume21(3):891.
C. Hegde, et al. Autotriage-an open source edge
computing raspberry pi-based clinical screening system.
medRxiv [Internet], 2020, p. 2020.04.09.20059840.
Available from: medRxiv.
S. Deng, H. Zhao, W. Fang, J. Yin, S. Dustdar, A.Y.
Zomaya. Edge Intelligence: The Confluence of Edge
Computing and Artificial Intelligence. IEEE Internet ofThings Journal, 2020, Volume 7(8):7457-7469.
C. W. Hung, K. Hiroyuki, J.R. Wu, C.C. Song. Low-Cost
Indoor Localization Using Sound Spectrum of Light
Fingerprints. In: Proceedings of the 2021 International
Conference on Artificial Life and Robotics (ICAROB),
2021, pp. 89-94.
S. Birlasekaran, G. Ledwich. Use of FFT and ANN
techniques in monitoring of transformer fault gases. In:

6.

7.
8.

9.
10.
11.

12.

13.

Proceedings of 1998 International Symposium on
Electrical Insulating Materials. 1998 Asian International
Conference on Dielectrics and Electrical Insulation. 30th
Symposium on Electrical Insulating Materials. IEEE,
1998, pp. 75-78.
F. Foukalas, A. Tziouvaras. Edge artificial intelligence forindustrial internet of things applications: an industrial
edge intelligence solution. IEEE Industrial Electronics
Magazine, 2021, Volume 15(2):28-36.
ARTERY Technology. AT32F415S DATASHEET[Internet]. June 2022 [V2.01]. Available from: ARTERY
Technology.
Texas Instruments. OPA1612A DATASHEET [Internet].
March 2015 [Rev.c]. Available from: Texas Instruments.
ASIC. L9110H DATASHEET [Internet]. Available from:ASIC.
R. Müller, S. Kornblith, G.E. Hinton. When does labelsmoothing help? Advances in Neural Information
Processing Systems, 2019, Volume 32.
C. B. Zhang, P.T. Jiang, Q. Hou, Y. Wei, Q. Han, Z. Li,
M.M. Cheng. Delving deep into label smoothing. IEEE
Transactions on Image Processing, 2021, Volume
30:5984-5996.
T. Lukov, N. Zhao, G.H. Lee, S.N. Lim. Teaching with
soft label smoothing for mitigating noisy labels in facial
expressions. In: European Conference on Computer
Vision. Springer, 2022, pp. 648-663.
H. Alibrahim, S.A. Ludwig. Hyperparameter
optimization: Comparing genetic algorithm against gridsearch and bayesian optimization. In: 2021 IEEE
Congress on Evolutionary Computation (CEC). IEEE,
2021, pp. 1551-1559.

Dr. Chau-Chung SongHe received the Ph.D. degrees inElectrical Engineering from National
chiao tung university. Currently he is aDistinguished professor and Chair in
National Formosa University

Authors Introduction
Dr. Chung-Wen Hung
He was awarded a Ph.D. in ElectricalEngineering from National Taiwan
University in 2006. Currently, he holds
a professorship at National Yunlin
University of Science and Technology.
His research focuses on AI, IIoT, andIoT applications.
Dr. Chun-Liang Liu
He earned his Ph.D. in ElectricalEngineering from National Taiwan
University of Science and Technology.
He has since joined the faculty at
National Yunlin University of Scienceand Technology, where he currently
serves as an Assistant Professor
Mr. Tai-Hsuan Wu
He has obtained his bachelor's degree
and is currently pursuing a master's
degree in electrical engineering at
National Yunlin University of Scienceand Technology.

317