|
Azure Sphere Development Kit |
x 1 | |
|
MikroE Heart Click 4 |
x 1 | |
|
RGB LED |
x 1 | |
|
Button |
x 1 |
|
Visual StudioMicrosoft
|
|
|
Microsoft Azure |
|
|
3D Printer (generic) |
|
|
Microsoft Power Bi |
MyPulse (Heart Rate and SpO2 Sensor)
Abstract
Now-a-days so many of us wear an array of sensors on our wrist all the time, keeping track of various vitals such as heart rate and stress levels.
Although the heart rate depends heavily on the individual’s age, generally, a resting heart rate of 60bpm – 100bpm is normal. Anything below or above this indicates signs of a possible disease like diabetes or atrial fibrillation.
Blood oxygen levels do not vary with age and a healthy person would have a saturation of over 95%. Anything below can indicate that there is not enough oxygen pumped around the body meaning that there may be a problem with anything from the lungs to the production of red blood cells in the individual. Diseases include emphysema, bronchitis and pneumonia.
Wouldn’t it be interesting to build your own device that precisely tracks your heart rate and blood oxygen (SpO2) levels with the press of a button?
MyPulse is an IoT application that allows the user to measure their heart rate and SpO2 levels by pressing a button and softly putting their finger on the device for 30 seconds. MyPulse is directly integrated with Microsoft Azure IoT allowing the collected data to be securely streamed to the platform from where it is beautifully illustrated on a dashboard.
Project Overview
The application can be split into the frontend and the backend. The frontend of the application refers to the actual device that collects the heart rate and blood oxygen values from the user while the backend refers to the data storage and dashboard.
I chose to make use of the Microsoft Azure Sphere development kit to power the project. The Azure Sphere supports Mikro Bus interfaces. These allow for the connection of MikroElektronika extension boards. MikroE has hundreds of extension boards offering a wide variety of functionality. Each board is essentially a module that snaps on the device in a Mikro Bus. These boards make prototyping and developing an application very simple and fast making them a great choice for our application.
We make use of the MikroE Heart Click 4. This is a heart rate and blood oxygen module that can easily be plugged into a Mikro Bus. It is also officially supported by the Azure Sphere community.
Some quick facts: studies correlate temperature and barometric pressure with the chance of stroke. A study by NCBI states that the chances of acute stroke increase by 2.4% per a 1°C change in temperature. Another study by NCBI relates that the majority of people rushed to the doctor with a stroke have been exposed to fluctuations in barometric pressure.
In light of this, I decided to also collect the barometric pressure and temperature data. These data are collected by onboard sensors meaning that we don’t have to connect any external components to get this functionality.
The Azure Sphere also has support for typical components. I connected a buzzer and RGB LED to the device to provide user feedback.
Microsoft Azure is directly integrated with the Azure Sphere device. Azure IoT Hub is used in the backend. Azure IoT Hub provides us with an endpoint to send the data from the Azure Sphere. The data is collected in the IoT Hub. The hub allows for thousands of devices to stream data.
A stream analytics job is used to periodically check for new data in the IoT Hub. When new data is detected, the job will push this data into a Power Bi dataset. Finally, Microsoft Power Bi is used to visualise the data. Power Bi allows us to create a beautiful dashboard by dragging and dropping elements on a canvas.
Figure 1: MyPulse Mobile Dashboard
Figure 1 and figure 2 illustrate the dashboard. Through the use of Microsoft Power Bi, the data collected from the device is illustrated online and accessible from any device, anywhere. The dashboard shows the most recent heart rate and blood oxygen level alongside graphs that show these values over time. The dashboard is easily sharable with anyone allowing your doctor to have direct access to the data collected in seconds.
Figure 2: MyPulse Web Dashboard
Project Architecture
Figure 3: Project Architecture Diagram
Figure 3 illustrates the project architecture in the frontend and the backend. The Azure Sphere is put into sleep mode and is woken up by the press of the button on the device. The button being pressed, signals that the user wishes to take a sample.
The device will turn the MikroE heart rate sensor on and start sampling it. The device will attempt to detect a pulse for a couple of seconds. If a pulse is detected, it will measure it together with the blood oxygen levels, otherwise the device will send an error and prompt the user to try again.
If the data is collected successfully. The device will sample the room temperature and barometric pressure and then compile the data and send it over an internet connection to IoT Hub.
The data will arrive in IoT Hub in seconds. In another few seconds, the stream analytics job set up will identify the presence of new data in IoT Hub and extract it. The job will then inject the data into a Power Bi report. When the user opens the Power Bi report, the dashboard will showcase the data.
The user can take as many samples as wished a day using the device. All the data collected is reflected live in the online dashboard.
Frontend
This section will cover the frontend of the application in detail.
Azure Sphere Development Board
Figure 4: Azure Sphere Development Kit
I chose to make use of the Microsoft Azure Sphere development kit (figure 4) to power the project. I made this decision because the Azure Sphere is an industry-grade development board that is really easy to work with. It offers plug and play capabilities that allow for rapid development of applications. The device is also vertically integrated with Microsoft Azure IoT offering easy and secure access to an industry leading IoT provider.
I believe that security is very important to ensure that the application is running smoothly and undisturbed by outside sources. The Azure Sphere device is as secure as it gets when it comes to IoT. From the Pluton chip ensuring that the device’s code can only be modified by users with access to the specificity needed in the app manifest, this device will ensure that the application is running smoothly and securely.
The Azure Sphere supports Mikro Bus interfaces. These allow for the connection of MikroElektronika extension boards. These boards make development easier and faster. The Azure Sphere also has integrated WiFi support making it very easy to connect to the internet. Microsoft Azure is directly integrated with the Azure Sphere device making connecting to the backend secure and seamless.
Sensors and Modules
The application makes use of three separate sensors to collect data. All the sensors used by the application are listed and explained in table 1.
Table 1: Sensors
Collecting Data
Data is collected by the device from various sensors after the user presses the button. To save resources, the temperature and atmospheric pressure are only collected if a successful heart rate and SpO2 are taken. Table 2 shows all the data fields collected by the application.
Table 2: Data Collected
User Feedback
I decided to also incorporate a buzzer and an RGB LED into the project to provide the user with feedback. The buzzer will buzz whenever the user should place their finger on the heart rate sensor and when the sensor completes its measurement to notify them that they can lift their finger.
Table 3 describes what the different colours of the LED signify for the user.
Table 3: LED Colour Significance
Sending Data to the Backend
The application will report all the data collected to the backend if the device successfully collected a heart rate sample. All the sensor data is collated and sent in an encrypted package to IoT Hub over an internet connection.
Device Enclosure
Figure 5: Render of the enclosure
Figure 5 shows a render of the device’s enclosure. I personally made it out of acrylic and glued it together but I have the STL files in the GitHub repo if you wish to 3D print the enclosure together with drawings with dimensions.
The enclosure consists of a box shape with three holes at the top; one for the RGB LED, one for the button and the other for the heart rate module. Make sure the material used is as thin as possible so that the user’s finger will be able to touch the sensor through the hole. 3mm to 5mm is fine.
Backend
Figure 6: Backend Architecture overview
Figure 6 illustrates an overview of the backend architecture. Each part of the backend is described in more detail below:
Azure IoT Hub
All the data that is sent to the backend is received by the Azure IoT Hub. This acts as a gateway for sending data from an IoT device to Azure Cloud. The service allows devices to be authenticated and then saves the data streamed temporarily. Figure 7 illustrates the connected device in the IoT Hub.
Figure 7: IoT Hub Devices
Stream Analytics Job
This is a glue service provided by Azure. It is separate from the IoT Hub. This service runs all the time and periodically checks to see if there is new data present in the IoT Hub. Whenever the device sends data to the hub, it takes a couple of seconds for the job to detect the new data. When this happens, the job will extract the data from the IoT Hub and inject it into a Power Bi Dataset.
Power Bi
This is the last stop for the data. Power Bi allows us to create a dashboard which can be populated with the data injected by the job into the dataset. Whenever a user opens the dashboard on any device, it will refresh the data and display the newest data from the dataset. On average it takes about 30 seconds to a minute for the data to get from the device to the dashboard. The dashboard (figure 8) illustrates all the data collected by the device.
Figure 8: Web MyPulse Dashboard
Going Further
As I was creating the project, I came across a lot of ideas that I did not get a chance to implement. The list below goes through them in case you want to add them in.
- The frontend device can be equipped with an OLED display that will inform the user about their heart rate and SpO2 levels as well as the temperature and barometric pressure when the sample is successful.
- The device could have a background function that reads the temperature and barometric pressure while the device is in stand-by and prints them on the OLED display.
- The data could be streamed into Cosmos DB for safekeeping.
Constructing the Project
This section will walk through the construction of the project.
Step 1: Required Materials
The BOM for the project can be seen above.
Figure 9: Required Materials
Step 2: Prerequisites
Before we start building the project. You will need to ensure that you have access to a Windows 10 PC with Visual Studio 2017 or 2019 installed. You will also require the Azure Sphere SDK installed on your PC.
Note that I am working on version 19 and not the most recent version. Although there should be no problem loading project files using the new SDK, some bugs can occur.
You will then need to follow this well laid out guide provided by Microsoft to get started with your development board and set it up. When your device is in debug mode and connected to Wi-Fi, you can continue with the guide.
Step 3: Connecting the Circuit
The next thing to do is wire the circuit. I used a breadboard for prototyping, but the final device should be soldered together. Please reference figure 10 for the schematics. Ensure to connect the MikroE heart click to MikroE socket 1.
Figure 10: Circuit Schematics
Step 4: Acknowledging the Code
The project's code is composed of 4 main sections:
- Get Button
- Get Heart Rate
- Analyse Data
- Send Data to Azure
Please download the code from the GitHub repository if you would like to follow along with the section explanations.
Get Button
This function samples the button and checks if it is pressed.
Get Heart Rate
This is the heart of the code; the device will wait until the button is pressed and then take a 30 second sample of the heart rate and SpO2 levels. The device will then compile the values and check if they are valid moving on to the next function.
Analyse Data
This function analyses the vitals to see if the values are OK or out of health limits. The device will then alert the user respectively.
Send Data to Azure
Finally, this function will append all the data collected together in a buffer and send it to Azure IoT.
Step 5: Setting Up Azure IoT
This guide will walk you through setting up the Azure side of the application. Make sure you have a Microsoft Azure account before proceeding with this section.
- Sign into the Azure Portal.
- Select the Create a Resource button from the home screen.
- Search for IoT Hub and select the option.
- Click on the create button to create a new IoT Hub.
- From the options on the next page, select your subscription and create a new resource group for the project. Make sure to select your region accordingly. Finally, give your IoT Hub a name.
- Click on the Size and Scale tab. You can create a free IoT hub in Azure. Do this by selecting the F1 tier. S3 tier is perfect for adding multiple devices.
- Click on Create and wait for the resource to deploy.
- Select the resource (you can find it in the all resources tab from the menu on the left of the screen.
- Scroll on the menu (starting with the settings heading) on the left of the screen until you see IoT devices under the Explorers heading. Select the option.
- On the next window, press the new button in the top left of the screen to create a new device.
- Give your device a name and ensure that symmetric key is selected from the authentication type. Tick the auto-generate keys option and click on save.
That’s it! IoT Hub is set up!
Step 6: Changing Variables
It is very important to add your IoT hub connection to the application to allow the device to communicate with the backend. The steps below illustrate this process.
- Get the code from the GitHub repo if you have not done so already and open the solution in Visual Studio.
- From the solution explorer on the screen, right click the references option and select Add Connected Service from the dropdown.
- On the new window, select Device Connectivity with Azure IoT.
- You will be prompted to sign into your Microsoft account. Do so and then select the subscription you used, set the connection type to IoT Hub Connection String, select the IoT Hub and then the device.
- Now navigate over to the app_manifest.json file in the solution and check that the AllowedConnections and CmdArgs are populated (if not, go through step 4 again).
- Copy the value of the CmdArgs field from the manifest.
- Locate the connection_strings.h file in the solution and paste the copied value as the value for MY_CONNECTION_STRING.
That’s it!
Step 6: Setting up the Streaming Job
The next step is to set up the streaming job that extracts the data from the IoT Hub and inputs it into the Power Bi dataset.
- Navigate back to the home page in Azure.
- Create a new Stream Analytics Job resource.
- Give the job a name and select the same subscription, group and location as the IoT Hub. Set the streaming units to 1.
- Click create to deploy the resource and wait for it to deploy.
- After the deployment completed, click back into the analytics job.
- Scroll down to Inputs under Job topology in the menu on the left of the screen and select the option.
- Click on Add Stream Input from the window and select IoT Hub.
- Name it InputFromAzureIoT and select the IoT Hub. Set the endpoint to Messaging and ensure the access policy is iothubowner.
- Click on save to save the input, Azure will test your input automatically, wait for this to succeed.
- After the input testing succeeded, click on Outputs from the same menu and click on the add button.
- Select Power Bi from the options. When you do this, you will be asked to authorise. Click the authorise button and sign into Power Bi.
- After you signed in, fill in the next fields as shown in figure 11 and wait for the output to be tested.
Figure 11: Stream Analytics Output
- Finally, click on Query from the menu on the left and paste the code below in the query. If you named your inputs and outputs accordingly, you should get no errors.
SELECT
Oxygen as oxygen,
HeartRate as heartrate,
Temperature as temperature,
Pressure as pressure,
System.timestamp as timestamp
INTO
[OutputToPowerBi]
FROM
[InputFromAzureIoT]
- Now click on Save Query from the menu on the top of the page.
- Click on Overview on the menu on the left and select start from the top of the page to start your job.
That’s it, your job is running! The job will automatically create a Power Bi dataset if one does not exist and then append data to it.
Step 8: Flashing the Code
We now have to flash the application to the device to send some data to the backend. For this test, the user will need to take a couple of samples using the device with the debug monitor on and see if the device is successfully sending data to the cloud and the data is found in the stream analytics job.
Plug the device into your computer and run the solution on the device.
Step 9: Setting Up Power Bi
The final thing that we have to do is set up Power Bi. The steps below will guide you through this. If all the previous steps went well, a dataset called MyPulse should be in the datasets section of Power Bi.
- The first thing to do is open powerbi.com and sign in.
- You will be directed to your dashboard, from here select your workspace from the menu on the left of the page and expand it.
- Check to see if MyPulse is under the Datasets section.
- We will be using the Power Bi desktop application to develop this dashboard. Install the app if you have not already and then sign in and open it.
- When you create a new app, you will be prompted to select a data source, select Power Bi datasets from the options or if you do not get a prompt, navigate to Home and then Get Data and select Power Bi datasets.
- Select the dataset MyPulse from the list, after a small bit, the menu on the right of the screen should populate with the data.
- Now that all the data is there, it’s up to you to create visuals for the data, you can experiment with different graphs and text boxes through the Visualizations menu and if you need any help PowerBi has a great getting started guide. My dashboard ended up looking like figure 12.
Figure 12: My Dashboard in Power Bi
Step 10: Constructing the Enclosure
The last thing to do is build the enclosure for the project. The schematics are all in the GitHub repo. You can 3D print the parts and then glue them together. There is enough space for the device and a breadboard to fit in together with all the sensors. Ensure that the LED, button and heart rate sensors are poking out of the three holes on the top of the enclosure.
Conclusion
MyPulse is an IoT application which leverages Microsoft Azure Sphere and Power Bi to display data about your heart rate and SpO2 levels on a clean, minimal dashboard. With the press of a button and thirty seconds of your time you get an insight into valuable information about your vitals.
I was inspired to create this project when I found out about the various health defects that can occur as a result of low blood oxygen levels. I became curious as to what my blood oxygen levels were and decided to create this device. I hope that individuals use this project to inspect their own vitals and maintain a healthy lifestyle.
MyPulse (Heart Rate and SpO2 Sensor)
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
- Comments(0)
- Likes(0)
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Andrei Florian
- PhoneLocator AbstractFigure 1: PhoneLocator’s instant responseHave you ever forgotten your phone in your friend's...
- SmartWristband Abstract Figure 1: The SmartWristband device being worn Monitor patients sent to self-isolate with t...
- Senso (Identification of Ilegal Logging) AbstractFigure 1: The Senso device attached to a treePeople are always told to recycle and turn off ...
- SmartWay (Geolocation Monitoring) AbstractFigure 1: The SmartWay device attached to the child's bag is glowing orange (meaning they ha...
- FlowerPot Monitor Abstract Growing and maintaining a flower or plant can be difficult. It takes time, dedication and c...
- Monitemp (Monitor Temperature And Humidity) AbstractFigure 1: A Monitemp device Not everyone has a thermostat in their home, and even if they do...
- SmartPostBox AbstractFigure 1: Post box powered by SmartPostBox Figure 1: Post box powered by SmartPostBox SmartP...
- MyPulse (Heart Rate and SpO2 Sensor) Abstract Now-a-days so many of us wear an array of sensors on our wrist all the time, keeping track ...
- CityGuide (Digital Tour Guide) AbstractCityGuide is a digital tour guide application which allows people to sightsee throughout a c...
- IntlAir (Air Quality Monitoring and Automatic Purification) Project Overview People spend most of their day at home, they wake up, go to work, then come back an...
- UnifiedWater AbstractFigure 1: UnifiedWater device being held above canal Yearly, over 8 billion tonnes of plasti...
-
-
-
kmMiniSchield MIDI I/O - IN/OUT/THROUGH MIDI extension for kmMidiMini
113 0 0 -
DIY Laser Power Meter with Arduino
163 0 2 -
-
-
Box & Bolt, 3D Printed Cardboard Crafting Tools
156 0 2 -
-
A DIY Soldering Station Perfect for Learning (Floppy Soldering Station 3.0)
564 0 3