Combating Aflatoxin Poisoning Using Smart IoT and Predictive Analytics for Sustainable Food Systems
By Emmanuel Mbije, Josiah Justinian, Jackline justus
INTRODUCTION
Aflatoxins are highly toxic secondary metabolites produced by certain strains of Aspergillus flavus and Aspergillus parasiticus fungi. These toxins contaminate crops like maize, groundnuts, and other cereals, leading to severe health effects and economic losses.
Aflatoxin contamination continues to threaten food safety, public health, and market competitiveness in Kenya, particularly affecting rural maize farmers and low-income consumers. As temperatures rise and storage infrastructure remains weak, the spread of mold and aflatoxins in post-harvest crops becomes increasingly dangerous.

Where Does Contamination Happen Most?
1. Storage: High humidity, poor ventilation, and stacking of sacks in small spaces create perfect conditions for fungal growth.
2. Harvesting: Delay in harvesting and doing so during wet seasons traps moisture in crops.
3. Transport: Prolonged delays (e.g. border delays) under poor conditions increase risk.
4. Drying: Insufficient drying leads to moisture levels >14% — a key trigger for aflatoxin.
Key Enablers of Contamination
- High humidity (95%)
- Warm temperature (>28°C)
- High crop moisture
- Poor storage practices and low farmer awareness

BACKGROUND TO THE PROBLEM
Existing systems for detecting aflatoxins rely on laboratory testing, which is expensive, centralized, and slow. Farmers must wait days or weeks to receive results often too late to salvage contaminated crops.
Through our engagement with a university-based IoT lab, we learned about ongoing research using LoRa-enabled sensors to monitor humidity in silos. However, these systems were largely experimental and uncoordinated, with no centralized way to collect and act on the data.
Additionally, interviews with local extension officers revealed that
- Most rural managers do not have thermometers or hygrometers.
- Decisions about drying and ventilation are made by intuition, not data.
- There is no channel for reporting or mapping mold outbreaks.
OUTLINING THE CHALLENGE
Develop a data collection and analysis tool to enable stakeholders to prevent and combat aflatoxin poisoning.
We refined this challenge into five core tasks:
- Collect reliable environmental data
- Analyze and process it automatically
- Deliver real-time alerts to field managers
- Visualize risks for decision-makers
- Predict future threats using machine learning
THE PREDICAMENT: Key Technical Challenges We Address
Challenge | Our Approach |
---|---|
Low infrastructure areas | GSM/LoRa communication + solar-powered sensors |
Lack of digital training | Simple SMS/USSD interfaces for silo managers |
Fragmented data | Centralized, encrypted cloud database + local caching |
Manual data interpretation | AI/ML models detect risk trends and generate insights |
Inaccessible lab testing | Preventive alerts replace delayed detection |
Poor visibility for stakeholders | Web-based dashboards with maps, graphs, and reports |
OUR VALUE PROPOSITION: AflaSense

This solution addresses a widespread and growing challenge using accessible, low-cost technology informed by principles of sustainable development and data-driven policy action.
Through expert consultations, field assessments, and sensor prototyping, our team developed AflaSense a smart IoT-based system that helps prevent contamination at the storage level by providing real-time environmental monitoring, alerts, and predictive analytics.
This solution addresses a widespread and growing challenge using accessible, low-cost technology informed by principles of sustainable development and data-driven policy action
TECHNICAL IMPLEMENTATION
1. Data Collection
We proposed a designed and tested a prototype sensor system built on open-source hardware and off-the-shelf components. The system will include:
- DHT22 sensor for temperature and humidity
- Capacitive moisture sensor to detect sack dampness
- ESP32 microcontroller for edge processing and wireless transmission
- Arduino IDE for firmware development
- MicroPython for early data logging tests
- Data is sampled every 15 minutes and locally cached
- Threshold values (e.g., >88% RH) are based on FAO aflatoxin prevention guidelines
- Environmental data is encoded as JSON and tagged with silo ID, timestamp, and GPS coordinate
2. Data Processing & Storage
- Encrypted JSON packets sent to cloud via MQTT
- Local SD backup ensures no loss during outages
- Data organized by:
- Device ID
- GPS-tagged silo
- Timestamp
- Threshold events (e.g., >88% RH)
There are a lot of ways to do this but with the research we have done it seems that using NLPs is the best way to go. We opted to use ChatGPT as our NLP since ChatGPT has a feature to create your own custom GPT to analyze the reports from our database and give us insights on the contents, so whatever we need be it trends on material (important) sustainability challenges and so on we just have to ask it.

https://www.youtube.com/embed/pLyH7389uDM?feature=oembedHow to build a custom GPT

3. Analysis & AI Integration
- Time-series models (ARIMA, LSTM) for predicting future risks
- Decision trees classify silos by low/medium/high risk
- Trend graphs detect mold incubation patterns

4. Data Visualization
- Custom dashboards for each stakeholder group:
- Farmers: SMS alerts only
- Extension officers: Silo status and local maps
- Ministry officials: County-wide risk heatmaps and intervention reports
- Formats: Live dashboard, downloadable .PDF, .CSV, .XLSX reports

5. Automation & Alerts
- If thresholds are exceeded:
- Alert generated in system
- SMS sent to silo manager
- Flag added to dashboard
- Scheduled weekly digest emailed to stakeholders

In theory, we’ve already built and tested our model, and we’re satisfied with how it performs in both field simulations and feedback from potential users. Now, the focus is on automating the entire pipeline from data collection and analysis to stakeholder dashboards — and deploying it in the cloud for scalability and sustainability.
Here’s how we plan to achieve that:
1. Cloud Infrastructure Setup
We will use a cloud platform like Google Cloud Platform (GCP) or AWS to host the full architecture of our solution. For scalability and cost-efficiency, we’ll provision serverless compute options (e.g., AWS Lambda, Cloud Functions) or virtual instances (like EC2 or GCP Compute Engine) to handle processing tasks like sensor data ingestion and alert generation.
2. Automated Data Collection and Storage
Our sensors will send data periodically via GSM or LoRa. These data streams will hit API endpoints hosted in the cloud, and raw data will be stored securely in cloud storage (AWS S3 or GCP Buckets).
We’ll also use managed databases like MongoDB Atlas or Cloud Firestore to store time-series sensor readings, thresholds, and alert histories. Triggers (e.g., from Firebase Functions or AWS Lambda) will automatically push new data into the analysis pipeline.
3. Automated Analysis (Including GPT/ML Integration)
For the intelligence layer:
- Our real-time sensor readings will be automatically parsed and assessed using threshold-based logic and ML models for predictive risk scoring (e.g., aflatoxin incubation modeling).
- As the system grows, we plan to train custom GPT-based models to analyze sensor patterns, silo performance, and regional trends. These will be hosted in managed services like AWS SageMaker or Vertex AI.
The entire analysis process — from data ingestion to prediction — will be handled by orchestrated workflows (e.g., AWS Step Functions, GCP Cloud Composer).
4. Visualization & Front-End Hosting
We will build our dashboard using React or Vue, hosted via platforms like Firebase Hosting, Netlify, or AWS Amplify.
The dashboard will fetch live data via a secure API, giving users access to:
- Real-time risk levels
- Historical trends
- Downloadable reports (PDF, CSV)
- Predictive maps showing likely aflatoxin hotspots
Frontend updates will be automated using CI/CD pipelines (e.g., GitHub Actions, Cloud Build), so any change in code pushes live seamlessly.
5. Security and Access Management
Security is a core part of our cloud design:
- We’ll use Firebase Authentication or AWS Cognito to manage user access (farmers, government, NGOs).
- IAM roles and policies will restrict database/API access to only authorized accounts.
- Data will be encrypted both in transit and at rest using built-in cloud encryption.
6. Monitoring and Scaling
We’ll enable real-time performance monitoring with tools like GCP Stackdriver or AWS CloudWatch, allowing us to catch outages or errors quickly.
We will also set up auto-scaling rules to handle high-load periods, such as during harvest seasons or regional contamination spikes.
7. Continuous Updates and Maintenance
- We’ll automate database backups, and use managed database tools for high availability and disaster recovery.
- Our ML/GPT models will be retrained as needed using data pipelines (e.g., SageMaker Pipelines, Vertex AI Pipelines).
- Stakeholders will receive monthly model reports, showing accuracy metrics and what changes were made.



SDG ALIGNMENT

THE TEAM

BSc Computer engineering
and Information Technology

BSc Agriculture and natural
resources economics and
business

BSc in computer science