Machine Learning-Based Position Detection Using Hall-Effect Sensor Arrays on Resource-Constrained Microcontroller
Abstract
1. Introduction
- A detailed design and implementation of a Hall-effect sensor-based position detection system integrated with TinyML on microcontrollers.
- Development of a quantized and non-quantized machine learning algorithm optimized for microcontroller deployment.
- Experimental validation demonstrating high accuracy, low latency, and robust performance across diverse scenarios.
2. Overview of the Proposed System
3. Hardware Design
4. Software Development
4.1. Position Detection
4.1.1. Creating the Dataset
4.1.2. Neural Network
4.1.3. Training and Testing
4.1.4. Optimizing for Low-Powered Devices
4.2. Force-to-Current Matrix Transformation
| Algorithm 1 Force-to-Current Transform | |||
| Input: Magnet’s X, Y, Z position, desired forces , , , and torques , . | |||
| Output: Vector I holds the coil currents required for stable levitation. | |||
| Procedure: | |||
| 1. | Determine the permanent magnet’s position. | ||
| 2. | Initialize values for the desired forces (, , ) and torques (, ). | ||
| 3. | for each coil do: | ||
| 1. Calculate radial distance and direction . | |||
| 2. Estimate the force and torque components at the point of interest based on the simulated lookup table using interpolation and extrapolation techniques. | |||
| 3. Construct matrix A from the rotation matrix and the estimated force and torque values. | |||
| 4. Compute , the pseudoinverse of matrix A. | |||
| 5. Calculate the required current vector by setting F to be the desired forces , , , , to achieve levitation. | |||
| end | |||
5. Results and Discussion
5.1. Integration Results
5.2. Performance Comparison with Related Work
5.3. Limitations and Potential Improvements
6. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
Abbreviations
| PID | Proportional–Integral–Derivative |
| Maglev | Magnetic levitation |
| NN | Neural Network |
| PWM | Pulse Width Modulation |
| MAE | Mean Absolute Error |
| RMSE | Root Mean Squared Error |
| MSE | Mean Squared Error |
| FPGA | Field Programmable Gate Array |
| PC | Personal Computer |
| EMPA | Electromagnetic Planar Array |
| TinyML | Tiny Machine Learning |
| TF | TensorFlow |
References
- Huang, X.; Kang, J.; Ding, H.; Xia, C.; Huang, D.; Wang, F. Adjacent Cross-Coupling Control for Magnetic Levitation System with Ultra-Local Sliding Mode Algorithm. IEEE Trans. Veh. Technol. 2025, 74, 2418–2428. [Google Scholar] [CrossRef]
- Khan, M.J.; Junaid, M.; Bilal, S.; Siddiqi, S.J.; Khan, H.A. Modelling, Simulation & Control of Non-Linear Magnetic Levitation System. In Proceedings of the 2018 IEEE 21st International Multi-Topic Conference (INMIC), Karachi, Pakistan, 1–2 November 2018. [Google Scholar]
- Qian, K.X.; Xu, H.X. Gyro-Effect and Earnshaw’s Theorem: Stable and Unstable Equilibrium for Rotary and Stationary Permanent Magnetic Levitators. In Proceedings of the 2008 2nd International Conference on Bioinformatics and Biomedical Engineering, Shanghai, China, 16–18 May 2008. [Google Scholar]
- Xu, Y.; Zhao, Z.; Yin, S.; Long, Z. Real-Time Performance Optimization of Electromagnetic Levitation Systems and the Experimental Validation. IEEE Trans. Ind. Electron. 2023, 70, 3035–3044. [Google Scholar] [CrossRef]
- Sun, Y.; Xu, J.; Chen, C.; Hu, W. Reinforcement Learning-Based Optimal Tracking Control for Levitation System of Maglev Vehicle with Input Time Delay. IEEE Trans. Instrum. Meas. 2022, 71, 7500813. [Google Scholar] [CrossRef]
- Frame, T.; Pechev, A.A. A Magnetically Levitated Precise Pointing Mechanism for Application to Optical Communication Terminals. Opt. Photonics J. 2012, 2, 85–97. [Google Scholar] [CrossRef]
- Salcudean, S.E.; Wong, N.M. Coarse-fine motion coordination and control of a teleoperation system with magnetically levitated master and wrist. In Experimental Robotics III; Springer: Berlin/Heidelberg, Germany, 1994; pp. 406–421. [Google Scholar]
- Yu, H.; Kim, W.j. A Compact Hall-Effect-Sensing 6-DOF Precision Positioner. IEEE/ASME Trans. Mechatron. 2010, 15, 982–985. [Google Scholar] [CrossRef]
- Britcher, C.P.; Cox, D.E.; Karlgaard, C.D.; Toniolo, M.; Dutta, S. Electromagnetic Modeling of Wind Tunnel Magnetic Suspension and Balance Systems. In Proceedings of the AIAA SCITECH 2023 Forum, National Harbor, MD, USA & Online, 23–27 January 2023; American Institute of Aeronautics and Astronautics: Reston, VA, USA, 2023. [Google Scholar]
- Koumboulis, F.N.; Skarpetis, M.G. Static controllers for magnetic suspension and balance systems. IEE Proc. Control Theory Appl. 1996, 143, 338–348. [Google Scholar] [CrossRef]
- Sawada, H.; Kunimasu, T. Development of a 60 cm Magnetic Suspension System. Jpn. Soc. Aeronaut. Space Sci. 2003, 50, 188–195. [Google Scholar] [CrossRef]
- Berkelman, P.; Dzadovsky, M. Extending the motion ranges of magnetic levitation for haptic interaction. In Proceedings of the World Haptics 2009—Third Joint EuroHaptics Conference and Symposium on Haptic Interfaces for Virtual Environment and Teleoperator Systems, Salt Lake City, UT, USA, 18–20 March 2009. [Google Scholar]
- Berkelman, P.; Dzadovsky, M. Single magnet levitation by repulsion using a planar coil array. In Proceedings of the 2008 IEEE International Conference on Control Applications, San Antonio, TX, USA, 3–5 September 2008. [Google Scholar]
- Qin, W.; Ma, Y.; Lv, G.; Wang, F.; Zhao, J. New Levitation Scheme with Traveling Magnetic Electromagnetic Halbach Array for EDS Maglev System. IEEE Trans. Magn. 2022, 58, 8300106. [Google Scholar] [CrossRef]
- Lai, Y.C.; Lee, Y.L.; Yen, J.Y. Design and Servo Control of a Single-Deck Planar Maglev Stage. IEEE Trans. Magn. 2007, 43, 2600–2602. [Google Scholar] [CrossRef]
- Berkelman, P.; Dzadovsky, M. Magnetic Levitation Over Large Translation and Rotation Ranges in All Directions. IEEE/ASME Trans. Mechatron. 2013, 18, 44–52. [Google Scholar] [CrossRef]
- Miyasaka, M.; Berkelman, P. Magnetic levitation with unlimited omnidirectional rotation range. Mechatronics 2014, 24, 252–264. [Google Scholar] [CrossRef]
- Lahdo, M.; Ströhla, T.; Kovalev, S. Design and Implementation of an New 6-DoF Magnetic Levitation Positioning System. IEEE Trans. Magn. 2019, 55, 8107407. [Google Scholar] [CrossRef]
- Berkelman, P.; Lu, Y.-S. Long Range Six Degree-of-Freedom Magnetic Levitation Using Low Cost Sensing and Control. J. Robot. Mechatron. 2020, 32, 683–691. [Google Scholar] [CrossRef]
- Jing, Y.; Wang, S.; Liu, Q.; Fu, K.; Yang, L.; Feng, W. Gap Self-Sensing Method for Maglev System Using Partial Electromagnet Coil. IEEE Trans. Ind. Electron. 2024, 71, 4273–4282. [Google Scholar] [CrossRef]
- Hussein, M.; Mohammed, Y.S.; Galal, A.I.; Abd-Elrahman, E.; Zorkany, M. Smart Cognitive IoT Devices Using Multi-Layer Perception Neural Network on Limited Microcontroller. Sensors 2022, 22, 5106. [Google Scholar] [CrossRef]
- Loukatos, D.; Lygkoura, K.-A.; Maraveas, C.; Arvanitis, K.G. Enriching IoT Modules with Edge AI Functionality to Detect Water Misuse Events in a Decentralized Manner. Sensors 2022, 22, 4874. [Google Scholar] [CrossRef] [PubMed]
- Han, H.; Siebert, J. TinyML: A Systematic Review and Synthesis of Existing Research. In Proceedings of the 2022 International Conference on Artificial Intelligence in Information and Communication (ICAIIC), Jeju Island, Republic of Korea, 21–24 February 2022. [Google Scholar]
- Jayalakshmi, T.; Santhakumaran, A. Statistical normalization and back propagation for classification. Int. J. Comput. Theory Eng. 2011, 3, 1793–8201. [Google Scholar]
- Giraud, F. Arduino Portenta H7 Carrier Shield, Florent Giraud. Available online: https://github.com/Rufus31415/arduino-pro-portenta-h7-carrier-board (accessed on 5 April 2021).
- Sabatini, A.M. Kalman-filter-based orientation determination using inertial/magnetic sensors: Observability analysis and performance evaluation. Sensors 2011, 11, 9182–9206. [Google Scholar] [CrossRef] [PubMed]
- Chaoraingern, J.; Numsomran, A. Embedded Sensor Data Fusion and TinyML for Real-Time Remaining Useful Life Estimation of UAV Li Polymer Batteries. Sensors 2025, 25, 3810. [Google Scholar] [CrossRef]
- Kalman, R.E. A new approach to linear filtering and prediction problems. J. Basic Eng. 1960, 82, 35–45. [Google Scholar] [CrossRef]
- Abadi, M.; Agarwal, A.; Barham, P.; Brevdo, E.; Chen, Z.; Citro, C.; Corrado, G.S.; Davis, A.; Dean, J.; Devin, M.; et al. Tensorflow: Large-Scale Machine Learning on Heterogeneous Systems, Software. Available online: www.tensorflow.org (accessed on 5 April 2021).
- Kluyver, T.; Ragan-Kelley, B.; Pérez, F.; Granger, B.; Bussonnier, M.; Frederic, J.; Kelley, K.; Hamrick, J.; Grout, J.; Corlay, S.; et al. Jupyter Notebooks-a publishing format for reproducible computational workflows. In Positioning and Power in Academic Publishing: Players, Agents and Agendas; IOS Press: Amsterdam, The Netherlands, 2016; Volume 2016. [Google Scholar]
- Picard, R.R.; Berk, K.N. Data splitting. Am. Stat. 1990, 44, 140–147. [Google Scholar] [CrossRef]
- Specht, D.F. A general regression neural network. IEEE Trans. Neural Netw. 1991, 2, 568–576. [Google Scholar] [CrossRef]
- Eckle, K.; Schmidt-Hieber, J. A comparison of deep networks with ReLU activation function and linear spline-type methods. Neural Netw. 2019, 110, 232–242. [Google Scholar] [CrossRef] [PubMed]
- Rasamoelina, A.D.; Adjailia, F.; Sinčák, P. A review of activation function for artificial neural network. In Proceedings of the 2020 IEEE 18th World Symposium on Applied Machine Intelligence and Informatics (SAMI), Herlany, Slovakia, 23–25 January 2020. [Google Scholar]
- Bosman, A.S.; Engelbrecht, A.; Helbig, M. Visualising basins of attraction for the cross-entropy and the squared error neural network loss functions. Neurocomputing 2020, 400, 113–136. [Google Scholar] [CrossRef]
- Sammut, C.; Webb, G.I. (Eds.) Mean Squared Error. In Encyclopedia of Machine Learning; Springer: Boston, MA, USA, 2010; p. 653. [Google Scholar]
- Dubey, S.R.; Singh, S.K.; Chaudhuri, B.B. Activation functions in deep learning: A comprehensive survey and benchmark. Neurocomputing 2022, 503, 92–108. [Google Scholar] [CrossRef]
- Xiong, Y.; Liu, X.; Lan, L.-C.; You, Y.; Si, S.; Hsieh, C.-J. How much progress have we made in neural network training? A New Evaluation Protocol for Benchmarking Optimizers. arXiv 2020, arXiv:2010.09889. [Google Scholar] [CrossRef]
- Kurbiel, T.; Khaleghian, S. Training of deep neural networks based on distance measures using RMSProp. arXiv 2017, arXiv:1708.01911. [Google Scholar] [CrossRef]
- Tan, J.; Zhang, T.; Coumans, E.; Iscen, A.; Bai, Y.; Hafner, D.; Bohez, S.; Vanhoucke, V. Sim-to-Real: Learning Agile Locomotion for Quadruped Robots. arXiv 2018, arXiv:1804.10332. [Google Scholar]








| Model | Architecture | Activation | Optimizer | MAE (mm) | MSE (mm2) | RMSE (mm) | Avg. Runtime (µs) |
|---|---|---|---|---|---|---|---|
| 1 | Type-1 | TanH | Adam | 0.0329 | 0.0105 | 0.1026 | 633.04 |
| 2 | Type-1 | TanH | Nadam | 0.0295 | 0.0188 | 0.1373 | 583.07 |
| 3 | Type-2 | TanH | Nadam | 0.0263 | 0.0384 | 0.1960 | 694.22 |
| 4 | Type-2 | TanH | Adamax | 0.0281 | 0.0354 | 0.1881 | 692.00 |
| 5 | Type-2 | Sigmoid | Nadam | 0.0308 | 0.0603 | 0.2456 | 626.27 |
| 6 | Type-2 | Swish | Nadam | 0.0442 | 0.0440 | 0.2098 | 678.17 |
| Model | MAE (mm) | Avg. Runtime (µs) |
|---|---|---|
| 1 | 0.0329 | 1034.21 |
| 2 | 0.0295 | 1017.21 |
| 3 | 0.0263 | 1169.71 |
| 4 | 0.0281 | 1043.19 |
| 5 | 0.0308 | 992.55 |
| 6 | 0.0442 | 1011.71 |
| Refs | Sensors | Hardware | Accuracy (mm) | Sampling Rate (Hz) | Cost |
|---|---|---|---|---|---|
| [15] | LED + Eddy Current | PC | - | 500 | High |
| [13] | Optical motion tracking | PC | 0.01 | 500 | High |
| [16] | Optical motion tracking | PC | 0.01 | 860 | High |
| [17] | Optical motion tracking | PC | 0.01 | 1000 | High |
| [19] | Optical motion tracking | PC | 0.01 | 1000 | High |
| [18] | Laser+ Eddy current | Sainsmart microcontroller | 0.008 | 1000 | Low |
| [4] | Eddy Air Gap | FPGA | 0.02 | 1000 | - |
| This work | Hall-effect | Portenta microcontroller | 0.026–0.040 | 855–1008 | Low |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Németh, Z.; See, C.H.; Goh, K.; Ghani, A.; Keates, S.; A. Abd-Alhameed, R. Machine Learning-Based Position Detection Using Hall-Effect Sensor Arrays on Resource-Constrained Microcontroller. Sensors 2025, 25, 6444. https://doi.org/10.3390/s25206444
Németh Z, See CH, Goh K, Ghani A, Keates S, A. Abd-Alhameed R. Machine Learning-Based Position Detection Using Hall-Effect Sensor Arrays on Resource-Constrained Microcontroller. Sensors. 2025; 25(20):6444. https://doi.org/10.3390/s25206444
Chicago/Turabian StyleNémeth, Zalán, Chan Hwang See, Keng Goh, Arfan Ghani, Simeon Keates, and Raed A. Abd-Alhameed. 2025. "Machine Learning-Based Position Detection Using Hall-Effect Sensor Arrays on Resource-Constrained Microcontroller" Sensors 25, no. 20: 6444. https://doi.org/10.3390/s25206444
APA StyleNémeth, Z., See, C. H., Goh, K., Ghani, A., Keates, S., & A. Abd-Alhameed, R. (2025). Machine Learning-Based Position Detection Using Hall-Effect Sensor Arrays on Resource-Constrained Microcontroller. Sensors, 25(20), 6444. https://doi.org/10.3390/s25206444

