Introduction: ZazHRM - a Bluetooth Heart Rate Monitoring System for Sleep Time
ZazHRM is being developed to try to perform heart rate monitoring (HRM) during sleep time. This prototype broadcasts via Bluetooth (BT), in near real-time, a measure of the heart rate (HR) or the pulse signal to an Android phone in a 10 meter radius. An App running on the Android phone enables the graphic visualization of either the HR or the pulse. When the HR falls below or rises above predefined thresholds, the App can also trigger an alarm for the caregiver.
The prototype comprises an Android App developed with AppInventor, a PulseSensor to measure the heart pulse signal, a HC-05 BT module to perform the BT communication, and an Arduino Uno board where a C program orchestrates the different parts. In addition, a Python script also shows how to perform basic offline processing of the data accumulated during monitoring. Code and relevant files are stored on GitHub.
Please, read also the warnings at the end of this presentation.
Thank you in advance for your feedback.
Step 1: Material Preparation
1) Arduino Uno Board; if you are new to the world of Arduino, you may like to buy a kit and enjoy learning from the tutorial projects.
2) Plug-and-play heart-rate sensor for Arduino; on the same site, you may want to familiarize yourself with the examples provided by the creators of the PulseSensor.
3) DSD TECH HC-05 Bluetooth Module
4) Android phone; it doesn't need to be a recent phone.
5) Breadboard holder to organize the pieces together.
6) An ordinary Tupperware (W = 15 cm, L = 25 cm, H = 4 cm) to host everything and protect the circuit. You will need some tool to drill clean openings in the Tupperware.
7) LEDs (1 red, 1 yellow and 1 green); the red indicates that HR measurements are either above the upper threshold or below the lower threshold; the yellow indicates that the pulse is being observed; the green indicates that the HR measurements are in the expected range.
8) Resistors (1 x 1k, 1 x 2k, 3 x 220)
9) Jumper wires
10) 5 meter cable, to allow the wearer to move more freely in the bed and to increase the communication range.
11) One on/off push button with cable.
12) Two rechargeable 9 volt batteries and a two 9V battery cables; as indicated in the circuit diagram later, the two batteries need to be wired in parallel.
13) Velcro, to non-permanently stick one or two 9 volt rechargeable batteries to the breadboard holder.
14) A connector kit and a crimping tool, to build connectors for the 5 meter cable, add pins to the 9V battery cables and add pins to the on/off push button cable. If you are not familiar with crimping, allow yourself to damage a few dozen connectors before getting it right ;)
15) Optional: a finger brace stabilizer or its equivalent for the toes, depending on where it feels the most comfortable, but HR from toe may be harder to get than from finger. You can also minimize the motion of the wire connecting the PulseSensor by simply letting it run under your wristwatch.
16) A basic voltmeter, to test the voltage divider in front of the BT module, the quality of your crimping or the parallel connection of the batteries.
Step 2: Circuit Diagram
1) The 3 wires running from the PulseSensor to the Arduino board are 5 meter long. You will need to crimp these 3 wires on both sides: female on the PulseSensor side and male on the Arduino side.
2) The voltage divider in front the RX connector of the HC-05 comes directly from the DSD Tech documentation.
Step 3: Suggested Use
- The person being monitored is in one bedroom
- PulseSensor straps around one finger or one toe; more likely to work with a finger than a toe.
- Breadboard is installed at a 2.5 meter distance away from the bed, giving the wearer 2.5 meters of leeway.
- The phone should remain connected to its charger throughout the night.
- The screen needs to be locked in the vertical position.
- The screen saver timer needs to be set to a value superior to one minute.
- The distance between the phone and the breadboard should be inferior to 10 meters; the maximum distance may vary as a function of the building materials separating the circuit from the phone.
A few words about the caregiver, me, and the person receiving care, Zaz (no affiliation with the singer). Zaz is the nickname of a family member and I am an average tech guy; Zaz is a cheerful, courageous and compassionate person who has epilepsy. Without entering into details, there is a link between epileptic seizures and HR. ZazHRM may however also be helpful in the more general context of conditions where bradycardia and tachycardia are nocturnal symptoms. Please, do not hesitate to take initiative to modify this prototype to best meet your needs, or your curiosity.
The picture above was created with Floorplanner and Gimp.
Step 4: Demo Video
- 0-49 s --> loading the App from AppInventor
Remark: if it is the first time loading the App, you will need to connect your Android phone to the HC-05. Press the "Connect BT" button, then select the HC-05; the address of the BT module will be remembered the next time you load the App, as will other settings.
- 49-1:15 s --> overview of the hardware setup
Remark: before powering on the circuit and strapping the PulseSensor to your finger, the compiled C code needs to be uploaded from a laptop to the arduino board via the usb port.
- 1:15-1:30 s --> strapping the PulseSensor
- 1:30-1:35 s --> starting to monitor
Remark: when the "Start HRM" button is pressed, the heart rate (HR) is automatically recorded on the phone, until the "Stop HRM" is pressed. The HR log will be saved locally on the phone in the format "bmpLog_MM-dd-yyyy hh:mm:ss a.txt".
- 1:40-1:50 s --> changing the scale of the display
- 1:55-2:05 s --> changing display to night mode
- 2:05-2:30 --> displaying the pulse signal
Remark: when displaying the pulse by pressing the "Pulse" button, the recording of the HR is temporarily stopped until you press the "BPM" button again.
- 2:30-3:10 --> adjusting upper or lower HR threshold
Remark: after changing the numerical value of the upper or the lower HRM threshold, you need to press the "Set" button
- 3:10-3:20 --> setting alarm in sound mode
- 3:20-3:50--> testing the alarm in sound mode
- 3:55-4:05 --> setting alarm in vibrate mode
- 4:05-4:30 --> testing the alarm in vibrate mode
- 4:30-4:40 --> setting the alarm in blink mode
- 4:40-5:10 --> testing the alarm in blink mode
- 5:15-5:20 --> setting alarm in vibrate mode
- 5:20-6:00 --> testing the alarm when circuit goes down
Remark: an alarm may also be triggered if the batteries' charge is too low, the HC-05 fails or the phone is located too far for the BT.
- 6:10-end --> showing where the HR logs are stored
Step 5: Offline Visualization and Interpretation of Logged Data
On GitHub, file “bpmLog_01-04-2021 015922 AM.txt”, you can see an example of my logged HR data for one night. The file “hrAnalysis.html” shows in details how this data is processed and visualized. To modify the code, you need to open the Jupyter Notebook file, “hrAnalysis.ipynb”, in Jupyter.
In this example, HR was logged during 6 hours and 27 minutes of sleep.
- The first figure shows the HR logs and the downtimes; it is down 1.7% of the time and the number of downtime instances is 115.
- The second figure shows the histogram of the HR logs; the small bump at 5 are the downtime events.
- The third figure shows the HR logs without the downtime instances.
- The fourth figure shows the histogram of the downtime events.
- The shortest downtime event was less than a second and the longest was 18 seconds long.
- The alert delay, "Alert D", was set to 5 s on the App. By setting "Alert D" to 20 s, only one downtime event would have triggered a false positive alarm (5 s + 18 s > 20 s).
"AlertD" applies a delay only to downtime events. If the HR value falls below the lower threshold, but is not associated with a downtime event, the alert will be triggered without delay; same thing when HR goes above the upper threshold, there is no delay. This can of course be changed in the code.
Here, the HR range was set to [30, 100]. During the night, a few seconds were spent below the lower threshold, and the upper threshold was crossed 6 times, each time for a few seconds (2s, 3s, 5s, 3s, 4s and 5s). Note that I am not known to have any heart related issues or conditions that may affect its rhythm.
Phone's battery charge: before = 100 %, after = 87 %; with the phone remaining connected to its charger throughout the recording. This means that the App consumes the phone battery quicker than the phone can recharge it.
Circuit's battery charges: before = (8.27 V, 8.32V) , after = (7.4 V, 7,54 V). Arduino needs a voltage source between 7 and 12 Volts; below 7 volts, the circuit will become unstable. Assuming a linear model for the consumption of the charges, the batteries could have powered the circuit for an additional 2 hours.
Step 6: To Do
Possibility to email automatically the HR logs when the "Stop" button is pressed.
Pulse reading is sensitive to body motions. An orthopedic stabilizer helps, but it would be nice to have a gyro chip inserted in the stabilizer to better handle and understand the motion artifacts; see image above.
The graphic visualization of the pulse occasionally has some scaling issues. As part of the AppInventor library, it would be useful to develop a robust component to display real-time 1D signals. Not only it could facilitate the visualization of the pulse or the HR, but also the visualization of EEG channel output , galvanic skin response, motion, temperature, pressure, ...
Possibility to log on the phone the raw pulse data for latter analysis; it would require a modest amount of changes to the App's code and, in comparison to logging HR data, about 10 to 20 times the amount of storage on your phone. Watching and storing the pulse for a few minutes would probably not impact the circuit's batteries significantly; for a whole night however, it would likely be a different story.
Evaluate the power consumption of the circuit under different circumstances.
Step 7: Source Code and Comments
Arduino, AppInventor and Python source code can be found on GitHub.
To modify and run the arduino code, in addition to have an arduino board, you need to install on your PC the Arduino IDE. You will also need to have some basic knowledge of the C programming language; you can find a lot of online tutorials.
You can directly install the App on your Android phone by downloading to your phone the "ZazHRM.apk" file found on GitHub. Another way is to load on your PC the source code in the AppInventor environment: go to the App page, click “Load App into MIT App Inventor” and, as shown at the beginning of the demo video, load the App to your phone via a QR code. In order to scan the QR code, you also need to install from Google Play Store the MIT AI2 Companion App on your Android phone. To see the comments in the AppInventor code, you need to press on the question mark located at upper left corner of some blocks. If you find it intimidating to directly modify the App, maybe you can first enjoy doing a few tutorials.
For the Python code, you can have a look at the html file, hrAnalysis.html. To modify the code you need to install Python and Jupyter, or an Anaconda release. Python is easier to learn than C, and you can also find a lot of online tutorials.
Step 8: Warnings
ZazHRM is not a medical device nor is it intended for medical diagnosis and is provided to you "as is," and no express or implied warranties are made whatsoever with respect to its functionality, operability, or use, including, without limitation, any implied warranties, fitness for a particular purpose, or infringement.
ZazHRM is designed to take power from a low-voltage DC source, i.e. 9 volt batteries. The Arduino Uno board needs to be connected to a laptop while uploading the code from the laptop to the Arduino Uno board, or when experimenting (for example) to compare the quality of the signal between the App and the Arduino environment. NEVER connect the PulseSensor to your body while the laptop is plugged to the wall outlet.
ZazHRM is not intended to be complete in terms of required design, marketing, and/or manufacturing related protective considerations, including product safety and environmental measures typically found in end products that incorporate semiconductor components or circuit boards.