Healthcare Category

Tutorial: Real-time iOS Heart Rate Monitor and Dashboard

2 min readPubNub Staff 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

Can Empathy Exist in the Metaverse
News May 16, 20221 min read

Can Empathy Exist in the Metaverse

A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.

PubNub Staff

PubNub Staff

How to Advance Telehealth and Virtual Care Technologies
News May 2, 20221 min read

How to Advance Telehealth and Virtual Care Technologies

Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...

PubNub Staff

PubNub Staff

Another Step Towards Data Security: ISO-27001 Implementation
BuildMay 2, 20221 min read

Another Step Towards Data Security: ISO-27001 Implementation

Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.

PubNub Staff

PubNub Staff