Blog 6 - Binbot - Igor Kapusniak

 

Blog 6 - Binbot

 

Introduction 

The BinBot is a smart recycling bin designed to encourage primary school students to sort their plastic bottles correctly through gamification. At its core, it is an interactive bin equipped with sensors and internet connectivity that allows classes to compete against each other. The bin measures how full it is using an ultrasonic sensor and tracks bottle returns through barcode scanning, awarding points to classes based on the value of recyclable bottles they deposit. This creates a fun, competitive environment where students can see their class's performance on a live leaderboard.

What makes the BinBot unique is how it brings various technologies together. Sensors on the bin send and receive data wirelessly through publishing and subscribing to  MQTT topics. Node-RED receives this data and processes it, verifies scanned barcodes against the return scheme API, and updates a dashboard with graphs and class rankings. This communication is encrypted using an XOR cipher to ensure that only authorised devices can read the transmitted data, protecting the integrity of the data.

The project promotes sustainable development and teaches kids the importance of recycling by making it rewarding. By combining hardware sensors, wireless communication, and cloud based processing, the BinBot turns waste management into an engaging classroom activity that aligns with UN Sustainable Development Goals around responsible consumption, climate action, and quality education.

 

Binbot System Diagram

The diagram shows how all the different parts of the BinBot system work together. On the left side is the actual bin itself, which has two microbits communicating with each other through encrypted radio signals. The slave microbit collects data from the ultrasonic sensor to measure how full the bin is and displays both the fullness percentage and class ranking on its screen, while the cloud board microbit handles all the communication with the MQTT Broker. Both microbits encrypt their messages before sending them so only they can understand what's being transmitted.

Once the data reaches the cloud board, it gets published to Node-RED which is the brain of the whole system. A barcode scanner on a phone sends bottle barcode scans through the IOT MQTT mobile app to Node-RED via MQTT, which checks if they are valid bottles using an API and then collects data about that bottle such as its capacity and type. The cloud board also subscribes to information from Node-RED about class rankings and sends that back to the Binbot to be displayed. When the bin gets too full and exceeds 90%, Node-RED sends an email notification and a message to Google Classroom to let the class know. All the barcode and fullness data gets recorded and feeds into a dashboard that displays live class rankings and statistics showing each class's progress and overall performance.

 


Team Design

The project was divided into five separate sections, with each team member working on their own component. This approach allowed the team to work in parallel and specialise in different areas of the system. The five sections were hardware and microbits, encryption and security, Google Classroom integration, data collection and visualisation, and barcode scanning. The last three sections all relied heavily on Node-RED to handle the data processing, making it a crucial part of tying everything together.
 
Tasks were divided among the 5 members as such:
 
Davin took on barcode scanning and API integration, developing the system to read bottle barcodes and verify them against the return scheme database to ensure only valid bottles were counted. 
 
George handled the Google Classroom integration and email service, setting up notifications to alert classes when their bin reached 90% fullness and managing the communication with the learning platform. 
 
John focused on encryption and security, implementing the XOR cipher that protected all radio communication between the microbits so only authorised devices could interact with each other.
 
Matteo worked on data collection and visualisation, building the dashboard that tracked class progress and displayed live statistics showing how each class was performing in the recycling competition

My Contribution 

My primary task for this project was to develop the code responsible for controlling the hardware. The microbits were split into two separate systems that needed to work together. The first was the slave microbit, which handled data collection from the ultrasonic sensor to measure bin fullness and displayed both the fullness percentage and class ranking on a screen. The second was the cloud board microbit, which acted as the master device and managed all communication between the bin and the internet. This involved receiving encrypted messages from the slave microbit, publishing that data to the MQTT broker, and subscribing to leaderboard information from Node-RED to send back down to the slave device for display.

Beyond the hardware, I also worked on the Node-RED side to act as a bridge between different parts of the system. I implemented the leaderboard array generation that created an array of classes based on their bottle total, and set up MQTT listeners that monitored for incoming barcode submissions from the bin. A key part of this work was formatting the barcode data in a way that Davin's API calls could use, and then taking the API responses and reformatting them so Matteo's data analytics and dashboard could process the information properly.

 

Development Overview

Cloud Board Microbit
The cloud board microbit acts as the master device and is responsible for all internet communication. It's divided into three main sections: 
 
On Start: This section initialises all the connections needed for the system to function. It sets up the WiFi connection using the credentials, connects to the MQTT broker with the authentication keys, and subscribes to the leaderboard topic so it can receive ranking data from Node-RED. The radio group is also configured and a confirmation LED is displayed to show successful setup.

 


On MQTT Received: When the leaderboard topic receives an update from Node-RED, this section gets triggered. It parses the incoming leaderboard data which comes as a comma separated list of classes, then iterates through to find where this class ranks. Once the rank is calculated, it gets encrypted using the XOR cipher and sent via radio to the slave microbit so it can be displayed.
 

 

On Radio Received: Every time the slave microbit sends data via radio, this section decrypts the message and splits it into a topic and value. The topic is constructed with the class ID and sent to MQTT along with the value, allowing the fullness data to be published to Node-RED for processing. A diamond shape flashes on the LED matrix to confirm successful reception. 

Slave Microbit
The slave microbit handles all sensor data collection and display. It consists of three main sections:

On Start: This initialises the encryption key, sets the radio group to match the cloud board, and sets up the HuskyLens display which shows both the fullness percentage and class ranking.

On Radio Received: When the encrypted ranking data arrives from the cloud board, this section decrypts it and stores it so it can be displayed on the HuskyLens screen.


Forever Loop: The ultrasonic sensor reads the distance to the bin's contents, which is then converted to a fullness percentage using the bin depth of 85cm. The percentage is encrypted and sent via radio to the cloud board. At the same time, the HuskyLens display is updated to show both the fullness percentage and the class ranking received from the cloud board, giving students feedback on their bin's status.

 

Node-RED 
 
Leaderboard Pipeline  

The leaderboard generation system takes all the bottle data collected and converts it into a ranked list of classes. This ranking is then published to MQTT so the microbits can display it on the bin's display in real-time.

Get Leaderboards Array: This function retrieves all the accumulated data about each class's bottle deposits from Node-RED's internal storage. It takes the stored school information and converts it into an array, then sorts the classes by their total deposit value in descending order so the highest scoring class appears first. The function then extracts just the class names and formats them as a comma-separated string, making it easy to pass along to the next step.

MQTT Publisher: Once the leaderboard array is generated, this node publishes the sorted class names to the binbot/leadboard topic on the MQTT broker. The cloud board microbit is subscribed to this topic and receives the updated rankings and sends it to the slave microbit for display. This creates a leaderboard that updates whenever a new bottle is scanned and processed.

 


 
Barcode Pipeline
The barcode processing pipeline in Node-RED handles incoming bottle scans from each class and prepares them for validation. It starts with four separate MQTT listeners one for each class that subscribe to their respective barcode topics. Initially, I tried to get dynamic topic subscriptions working so we wouldn't need four separate listeners, but that approach didn't work, so we went with individual listeners for each class.

Only Classes: This function filters the incoming messages to ensure they're actual barcode data coming from the correct topics. It uses a regex pattern to check that the message is coming from a valid binbot/classX/barcode topic, then extracts the class ID from the topic so we know which class submitted the barcode.

Class Data: Once we've confirmed it's a valid barcode message, this function structures the data into a format that can be used by the rest of the system. It takes the barcode number and wraps it up with information about which class it came from, creating a JSON object. This format makes it easy for the next step to process.
 
API Calls: After the data is formatted, it gets sent through three different APIs to validate and capture more data about the bottle. First, it checks against the return scheme API which simply returns true or false to tell us if the bottle is a part of the bottle return scheme. If it's not valid, the process stops there and the barcode is rejected. If it passes validation, the further data about the bottle gets collected with product information from the Open Food Facts API to capture details like the product name and container type.

 

 

Teamwork Reflection

Working on the BinBot project as a team was a nice change of pace compared all the other modules from this semester. Being able to split the work meant we could each focus specific areas, whether that was hardware, security, or data processing. What really stood out was how well everyone communicated throughout the project we used Slack to share updates, had regular check-ins to see where everyone was at, and weren't afraid to ask for help when we got stuck. The whole process felt much more collaborative than I expected.
 
An area that I think could have been improved was initial planning and documentation. There were moments where different parts of the system didn't connect as smoothly as they should have. Sometimes the data format coming from one section didn't match what the next section was expecting, or there was confusion about how certain parts of Node-RED were supposed to work together. I think what would have helped was setting up clearer documentation earlier on about what each section was outputting and how it should be formatted. That way, when we came to integrate everything at the end, it would have been a lot quicker.

 

Conclusion

The BinBot project was a really enjoyable experience to work on. We managed to overcome obstacles with the hardware setup, successfully implemented encrypted communication between devices, and built a complete Node-RED backend that validates bottles and updates rankings.

Once everything was connected, the data was sent from the bin sensors and IOT App through to the dashboard making it easy for classes to track their progress and see live leaderboard updates. The whole system came together to create something that's both functional and useful for teaching kids about recycling.


Project Demo

The final project working can be seen in the videos below: 

Individual Part

 

 

 





 

Comments

Popular posts from this blog

Blog 1 - Igor Kapusniak

Blog 5 - Bin Bot Project - Davin Barron