Blog #2 – Heart Rate Monitoring with Micro:bit

 Week 2 - IoT Analog Input 

Dean Sinnott, 20067691

Figure 1. MakeCode console 


For week 2, we were tasked with learning how to use a micro:bit and an analog input by working with a heart rate sensor. The goal was to read in data and begin to understand how to handle and visualize it in  a digital environment. This project helped build my confidence in using IoT technologies and creating MakeCode blocks. 


What was the plan ?

The objective was to simulate a simple ECG ( electrocardiogram) like signal and measure heart rate variability (HRV), the time difference between consecutive heartbeats. 

We used: 

  • 1 x micro:bit V2
  • 1 x pulse sensor 
Figure 2. micro:bit + pulse sensor setup


How the Pulse Sensor works 

The heart rate sensor uses light to detect blood flow. It works like:

A LED light shines into your skin => A photodetector measures how much light is reflected back 

As your heart beats, the volume of blood flowing through the near by blood vessels fluctuates, which affects how much light is returned. The sensor sends out this changing signal as an analog output, transformed to an electrical signal. 

The sensor is very sensitive to motion, so keeping my finger steady and applying even pressure was key to getting clean, readable data.


Code Breakdown

I used the Microsoft MakeCode editor to build the program. It was created using block-based logic and uploaded to the micro:bit via USB. 

The program was made up of five main parts: 

  • Startup Block: Displays a message ("Pulse ___") on the LED display when the micro:bit starts.
  • Loop 1 - Signal Reading: Continuously reads analog value from pin P2.
  • Loop 2 - Pulse Calculation: Using thresholds and time to identify a heartbeat (T2-T1). BPM is also being calculated. 
  • Loop 3 - Display :  Shows the BPM on the micro:bit display alongside a heart icon. 
  • Loop 4 - Serial Output: Sends the signal data to the MakeCode console using serial write value, allowing it to be visualized like an ECG signal. 

 A full breakdown and understanding can be found on,  https://medium.com/liki-blog/micro-bit-vital-signs-b76e495f6a59. 

Figure 3. Basic display code loops




Figure 4. Pulse calculation code block 


Making it easy to Troubleshoot

Using the MakeCode console was one of the most helpful parts of the project. The analog values from the heart rate sensor were graphed over time. This made it easier to: 
  • Spot heartbeat patterns 
  • See where motion interference occurred 
  • Identify good threshold values for the heartbeat detection. 
This visual feedback helped me tune the code and better understand how HRV data works. 

Figure 5. Vital signs


Final thoughts

This project was a great exercise in working with analog data, visualizing sensor input, and writing code to make sense of it. It was my first ever IoT mini project and it gave me major insight into the workflow, thinking pattern and problem solving I will need going forward in the module.

Figure 6. Notes




Comments

Popular posts from this blog

Blog 2 - HRV Demo

Week 1: HRV Review

Blog 5 - FFT & HRV