Inspiration

Water quality monitoring systems commonly depend on fixed threshold values and continuous processing. This can make it difficult to identify unusual combinations of water-quality parameters or gradual changes that do not immediately cross a predefined threshold.

We wanted to build a system that could detect abnormal water conditions locally while also making intelligent use of the limited computing resources available on an embedded device.

This led us to develop EdgeAI WaterGuard, an RTOS-based Edge AI system for water-quality anomaly detection on an ARM Cortex-M33 microcontroller.

What We Built

EdgeAI WaterGuard monitors three important water-quality parameters:

  • pH
  • TDS
  • Turbidity

The system uses an autoencoder neural network trained offline using water-quality data. Instead of deploying the complete TensorFlow framework to the microcontroller, we export the trained neural-network weights, normalization parameters, and anomaly threshold and implement the inference operations in embedded C.

The trained model is designed to learn the characteristics of normal water. When new sensor data is provided, the autoencoder reconstructs the input. A large difference between the original input and reconstructed output indicates that the input does not match the learned normal pattern.

The reconstruction error is calculated using: MSE = \frac{1}{3}\sum_{i=1}^{3}(x_i-\hat{x}_i)^2 where (x_i) represents the normalized sensor input and (\hat{x}_i) represents the reconstructed value.

What it does

EdgeAI WaterGuard is an RTOS-based Edge AI water-quality monitoring system designed to detect abnormal water conditions using pH, TDS, and turbidity measurements.

The system acquires sensor readings through the STM32H533RE, preprocesses the measurements, and passes them to a compact autoencoder running locally on the ARM Cortex-M33. The autoencoder learns the characteristics of normal water-quality patterns and detects deviations using reconstruction error.

The model follows a compact:

3 → 8 → 4 → 2 → 4 → 8 → 3 architecture.

The reconstruction error is calculated as: MSE = \frac{1}{3}\sum_{i=1}^{3}(x_i-\hat{x}_i)^2

A confidence mechanism prevents a single noisy measurement from immediately triggering an anomaly response. When an abnormal condition is confirmed, the RTOS can dynamically prioritize critical processing tasks.

How we built it

he system combines embedded sensing, Edge AI, and RTOS-based scheduling.

Water-quality measurements from the pH, TDS, and turbidity sensors are acquired by the STM32H533RE. The readings are normalized using the same parameters used during model training.

The autoencoder was trained offline using Python and TensorFlow. The training pipeline consists of:

Water-quality dataset ↓ Data cleaning ↓ Feature selection ↓ Normalization ↓ Autoencoder training ↓ Reconstruction-error analysis ↓ Anomaly threshold

The trained model parameters are then converted into embedded C-compatible data and deployed on the STM32 rather than running the complete TensorFlow framework on the microcontroller.

The embedded inference pipeline is:

Sensors ↓ STM32H533RE ↓ Normalization ↓ Encoder ↓ Latent representation ↓ Decoder ↓ Reconstructed values ↓ Reconstruction error ↓ Anomaly confirmation ↓ RTOS task-priority response

The application is organized using μT-Kernel 3.0, allowing sensing, AI processing, and system response to operate as separate RTOS tasks.

Challenges we ran into

One of our biggest challenges was moving from a Python-based machine-learning environment to a resource-constrained embedded platform. We had to understand how an autoencoder actually works rather than treating it as a black box. This included understanding neural-network weights, matrix multiplication, activation functions, normalization, latent representations, reconstruction, and reconstruction error. Another challenge was ensuring that preprocessing on the STM32 matches the preprocessing used during model training. Even a trained model can produce incorrect results if real sensor values are normalized differently from the training data. We also had to consider embedded constraints such as memory usage, execution time, and RTOS scheduling.

Accomplishments that we're proud of

Developed an Edge AI water-quality anomaly detection architecture for an ARM Cortex-M33 platform. Built and trained an autoencoder using TensorFlow. Used pH, TDS, and turbidity as the primary water-quality features. Implemented dataset preprocessing and feature normalization. Generated the trained neural-network weights required for embedded inference. Converted the model concept into a lightweight embedded C inference implementation. Integrated the AI processing architecture with STM32H533RE. Designed the system around μT-Kernel 3.0 RTOS. Implemented a compact neural-network architecture suitable for embedded deployment. Incorporated reconstruction-error-based anomaly detection instead of depending exclusively on individual fixed thresholds. Designed confidence-based anomaly confirmation to reduce false positives caused by transient sensor noise. Designed dynamic RTOS priority management so that critical processing can receive increased CPU attention when abnormal conditions are detected. Kept the AI inference local to the embedded device, reducing dependence on cloud processing.

What we learned

Through this project, we learned how to take a machine-learning model from a dataset to an embedded deployment.

We worked with:

Python and TensorFlow Dataset preprocessing Autoencoder neural networks Model training and evaluation Neural-network inference Embedded C STM32H533RE ARM Cortex-M33 μT-Kernel 3.0 RTOS task management Edge AI deployment Memory and computational constraints

The project helped us understand that deploying AI on an embedded system is not simply about training a model. The real challenge is making the trained model operate reliably within the computational and memory limitations of the target hardware.

What's next for EdgeAI WaterGuard

The next stage is focused on hardware validation and optimization.

We plan to further validate the system with different real-world water conditions and characterize:

Sensor accuracy and calibration. AI inference latency. RAM and Flash usage. RTOS scheduling overhead. Dynamic-priority response time. False-positive and false-negative behavior. Long-duration system stability.

We also plan to optimize the neural-network implementation further for the ARM Cortex-M33, including reducing unnecessary memory usage and computational overhead.

Ultimately, EdgeAI WaterGuard aims to provide a self-contained real-time water-quality monitoring system where sensing, AI inference, anomaly detection, and scheduling decisions happen directly on the embedded ARM platform.

Built With

  • ai
  • anomaly
  • arm
  • artificial
  • autoencoder
  • c
  • cortex-m33edge
  • deep
  • detection
  • embedded
  • intelligence
  • iot
  • learning
  • machine
  • monitoring
  • networks
  • neural
  • python
  • quality
  • rtos
  • stm32
  • stm32h533re
  • systems
  • tensorflow
  • water
Share this project:

Updates

Submission history