The Lock-In
My final contribution to "a Bigger Heart"
Real Time Sensor Monitoring with a Micro:bit and Flask
In this project, I continued building the real time sensor monitoring system Brendan and I started before using a BBC Micro:bit and a Python Flask server. The Micro:bit reads analog sensor values (e.g. heart rate), buffers them locally, and sends them in batches to the server over WiFi. The Flask server stores these values and sends the to Google sheets. The goal was to achieve a smooth, heartbeat-monitor-style display with minimal delay.
This 10 value buffer version worked best for responsiveness. It maintained a steady stream of readings, providing near real-time updates without overwhelming the Flask server or Google Sheets API.
I also created a second version that stores 100 values and sends them all at once. This version was designed to reduce the number of HTTP requests and better suit Google Sheets batch updates. However, it resulted in a slightly less smooth real-time experience.
Flask Server
The Flask server has multiple responsibilities:
Listen for incoming HTTP POST requests from the Micro:bit
Store incoming data in memory using a
dequehere I had it set to max 100 values so I could easily change how many values I want to send up to 100Upload data to a Google Sheet in the background
The /add_values_batch endpoint decodes the buffer, converts values to floats, timestamps them, and appends them to both the buffer and the Google Sheet.
Google Sheets Integration
I used the gspread library and an account with the Google Sheets API. Values are pushed in batches to try and avoid exceeding quota limits. Each reading is stored along with a timestamp.
Result
This setup lets me see near real time sensor data streamed and logged from a Micro:bit to Google Sheets via WiFi. It’s a lightweight system suitable for the IoT integration of our project.
Improvements
One of the main difficulties I faced was managing the speed of data being sent from the Micro:bit. When using the 10-value buffer approach, the Micro:bit would send requests so rapidly the Google Sheets API couldnt keep up as it has rate limits for how quickly you can send POST requests. If exceeded, the API would reject the updates, causing some data to be lost. To work around this, I experimented with buffering 100 values and sending them in a single batch, which helped reduce the frequency of requests but introduced latency. Finding the right balance between responsiveness and reliability was a key challenge in this project, but I did achieve what Brendan and I set out to do at the beginning of this project which was to send the values as fast as possible. So if continuing this project I would use something other than google sheets.
How this ties into the main project
This Micro:bit-Flask system was part of a larger two day group "Lock-In" project for our IoT Applications module. The overall goal was to build a heart monitoring system where heartbeat data from a sensor could be streamed and visualised in real time to a Unity or web interface. While other members of the team worked on frontend visualisation, RTC streaming, or Unity development, my focus was on setting up the hardware pipeline. I built the core system that read heartbeat data from the Micro:bit, buffered and sent the values over WiFi to a Flask server, and then stored them in Google Sheets for visualisation and analysis. This would in theory allow the frontend team to pull real sensor data and use it in their applications. I tried to coordinated closely to make sure the data pipeline was robust, fast, and easy to integrate, ensuring that everyone could build on top of a reliable data stream.
Discussion
Team Collaboration & Role
During the two-day sprint, our group divided into smaller units based on interest and technical strengths. While others focused on Unity integration, audio streaming, and signal servers, my responsibility was building the Micro:bit sensor pipeline. I worked independently to create a system that could collect analog sensor data (simulating heartbeat), buffer it on the Micro:bit, and stream it live to a Flask server via WiFi. This contribution acted as a crucial foundation that fed data into the wider system for real time visualization and audio conversion.
Although my work was mostly independant, it integrated tightly with the rest of the team’s cloud and frontend efforts. The Micro:bit script became the starting point for multiple architectural routes either pushing data to Google Sheets or feeding directly into WebRTC streams. I also kept the team updated on the buffer logic and request limits so that maybe other components could sync with the expected data flow rate.
Conclusion
Working on this Micro:bit and Flask pipeline gave me a hands on opportunity to build something essential to the wider project. It pushed me to think about data flow not just in terms of code, but in terms of speed, reliability, and integration with other systems like Google Sheets, React, and Unity. I learned how to buffer and batch data efficiently, how to deal with API limits in a real-world context, and how to structure a system that stays responsive under pressure.
Even though I was working mostly solo on my part, it never felt disconnected from the team. My work was an integral part of the whole system, feeding live sensor data that everyone else could build on. Seeing that data get visualized, turned into audio, and integrated into apps was a great reminder of how collaborative projects come together through each person’s individual contribution.
This was a simple setup on the surface a Micro:bit, a WiFi board, and a Python server but it became a powerful proof of concept for IoT streaming and teamwork. It’s something I could see being reused, expanded, or even turned into a full fledged product with just a bit more development. And for a two day sprint, that’s a pretty solid takeaway.
I just want to thank the amazing team I got to work with this semester it was truly something else. And I want to give an even bigger thank you to Jason Berry for not just being the best lecturer I've ever had but the best mentor as well.
Thank you to everyone and Happy Monday!
Comments
Post a Comment