← All projects

IoT Algal Bloom Detection System

A low-cost, field-deployable water monitoring station that samples lake water, measures it with inexpensive sensors, and uses machine learning to predict harmful algal bloom risk.

Overview

In recent years, in British Columbia, harmful algal blooms have increasingly threatened local aquatic life, and have made lakes and rivers unsafe for recreation. The root problem, is that monitoring and detecting these algal blooms is both complex and labour-intensive. Lab testing for chlorophyll-a, the standard indicator, is slow and expensive, and there's very little local water-quality data for most bodies of fresh water in BC. The most common method of detection is via satelite imaging, which can only report blooms after they happen. This system estimates bloom risk, and provides fast bloom detection via cheap physical sensors, instead of the complex or delayed analysis of alternatives.

An Arduino MKR WiFi 1010 pumps lake water into a separate testing reservoir, keeping the electronics away from the water's surface. There it measures pH, temperature and turbidity, and estimates phosphorus by reading the colour change of a reagent with an RGB sensor, before a solenoid valve drains the reservoir for the next sample. Machine learning models then rate each sample as algae absent, algae may be present, or algae present.

System diagram of the algal bloom monitoring station
Algal bloom monitoring system output

Prototype and cloud dashboard

Each reading is sent over MQTT to a ThingsBoard server running in Docker. The custom dashboard shows live sensor data and controls the device remotely through RPC calls, and high-risk readings trigger an automatic email alert. MQTT was chosen over a REST API for its low latency, and it let the device send and receive updates almost instantly.

The sensor station from the front
The sensor station in operation

Machine learning

The biggest challenge was the data. The available water-quality dataset had no labels marking which samples were blooms, so several approaches were tried. K-means clustering produced clusters that looked plausible but put every test sample into a single cluster, and semi-supervised pseudo-labelling performed just as poorly.

Supervised learning with surrogate targets worked best. Thresholds on total nitrogen and conductivity left no samples in the middle "may be present" class, so the final models were trained against chlorophyll-a instead, using Health Canada's 33 µg/L guideline for primary-contact water. Because chlorophyll-a is only the training target and not an input, the deployed device never needs an expensive chlorophyll sensor.

Trained this way, random forest reached 78% accuracy with a macro F1-score of 0.68, and gradient boosting reached 74%. Both predicted all three risk levels and agreed with each other on 84.74% of test samples. Both models were also run on data collected by the device itself, demonstrating the full pipeline from sensor to cloud to risk rating.

Lessons and next steps

The reservoir is larger than field use needs, which wastes time, power and reagent on every sample, and boosting 3.3 V up to 12 V for the solenoid drains a Li-ion battery within days, so a smaller reservoir and a native 3.3 V valve are the main planned changes. The low-cost pH probe also needs frequent recalibration.

A blue dye stood in for the Molybdenum Blue phosphorus reagent to validate the colour-sensing pipeline, and no lab chlorophyll-a measurements were available for the device's own samples. Real reagents, a labelled dataset and field samples taken during bloom season would be the next step toward verifying the models in the field.

Skills and technologies

IoT Arduino MQTT ThingsBoard Docker Sensor Integration Machine Learning Python Random Forest Gradient Boosting Fusion 360 Technical Writing

Source code, wiring diagrams, 3D models and full documentation are in the GitHub repository.