Healthcare Category

Tutorial: Real-time iOS Heart Rate Monitor and Dashboard

2 min read Michael Carroll on Sep 30, 2015
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

How to build an iOS heart rate monitor that streams heart rate data in real time to a real-time dashboard from the iOS smartphone app.

In Part One of our blog series, we built an Android heart rate monitor application and real-time dashboard. To build on that, in this part, we’ll show you how to build the same application for iOS devices.

How the iOS App Works

The iOS application will collect the heart rate readings and stream the data to a real-time dashboard. The iOS phone’s camera will be used to capture the heart rate. When the app user presses a finger against the camera, an image processing algorithm detects the red component on the finger image to sense the blood flow and then calculates a reading.

The reading is averaged at the time span of one minute, and the heart rate is determined. Once we have the heart rate reading, the app streams the data in real time to a monitoring dashboard.

Project Resources

Our final application will look and function like this:

iOS Heart Rate Monitor

PubNub Initialization

AppDelegate.m is the main application entry point for this app.  It also defines the function PublishOnPubNub( ), which handles the publishing of heart rate readings to the doctor’s portal.

Registering with the Doctor’s Id

Users register with the doctor’s id for sending their heart rate reading. The ViewController class defines a function called SaveDoctId_btn( ) for capturing the doctor’s id keyed in by the users. This is then used to form the PubNub channel name in the same way as done for the Android App in Part One.

Capturing the Heart Rate

The iOS app captures finger images from the camera frame to detect the heart beats and derives the heart rate from them. The ViewController class is responsible for controlling and capturing the camera frames.

Further, the captureOutput( ) function captures and converts RGB to HSV and saves the valid frames to be used by the PulseDetector class for pulse rate sensing.

The PulseDetector class defines the functions addNewValue( ) and getAverage( ) which are used to get the pulse rate from valid frames out of 10 frames per second and derive the average reading for a one minute interval.

Finally, when the derived reading is taken, the app sends it to the real-time dashboard via the PublishOnPubNub( ) function defined in the AppDelegate class. And that’s it!

Wrapping Up

This is just one example of how real-time technology is changing how we’re building healthcare applications. A massive growing and evolving market, by 2020, it’s estimated that IoT healthcare will hit $117 billion dollars. And real-time technology will continue to integrate itself into a wide variety of healthcare applications, for patients, doctors, and organizations alike.

More from PubNub

NPP and HIPAA: Notice of Privacy Practices Definition
Healthcare CategoryJan 6, 20235 min read

NPP and HIPAA: Notice of Privacy Practices Definition

A Notice of Privacy Practices (NPP) is one of the requirements of HIPAA and helps patients understand their personal data rights.

Michael Carroll

Michael Carroll

HIPAA Violation Examples
Healthcare CategoryJan 5, 20236 min read

HIPAA Violation Examples

HIPAA violations can be financially expensive and devastating to a brand. Examine some examples of HIPAA violations, and learn...

Michael Carroll

Michael Carroll

How to Add a Notification Badge to Icons in React Native
Real-time Chat BlogDec 19, 20226 min read

How to Add a Notification Badge to Icons in React Native

Display real-time notification badges with PubNub and React Native to display important information and bring users back to your...

Michael Carroll

Michael Carroll