DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question

26 Jan 2017, 13:12

Healthcare Tracking System for Dementia Patients and Elderly (Part 1) - Hexiwear Test Drive


Technology is integrating more and more into our lives day by day. One of the areas, it has revolutionised is medicine. Over the past few years, the innovation around health and fitness gadgets has rocketed. Health/fitness trackers, air pollution monitors, sleep trackers, glucose monitors, electrocardiogram (ECG) reading on the go, electroencephalography (EEG) data readers, and etc. In the past, these devices were only available in the hospitals but now you can build one for yourself and attach to your body. Yes you can do it, and today we are going to build a healthcare tracking system. I have been selected for the Hexiwear (923-6084) Test Drive by DesignSpark, my project is to build a healthcare tracking system with Hexiwear.

Why do we need a healthcare tracking system?

There are many uses of the healthcare tracking systems but I will mention just a few of them. Let's say you have a machine which records the heart beats of a person. This data can give enormously important information about person's heart and possible illnesses can be diagnosed before it occurs. Another example, think about dementia patients or elderly people. It is essential someone should be around them, on their own they could become lost, or even need urgent treatment in the event of an accident or reoccurring illnesses, with no one to help the result can be catastrophic. However, if they have a tracking system which can detect when they faint and inform the emergency service, they can be treated on time.

What is Hexiwear?

Hexiwear, developed by MikroElektronika, is an open-source wearable development kit which was successfully funded on KickStarter. It combines many sensors like 3D accelerometer, 3-axis digital gyroscope, pressure sensor, heart rate sensor and more. It has ARM powered Kinetis K64x MCU by NXP. It can connect to other devices by Bluetooth Low Energy and inform the user via 1.1" full-colour OLED display. It is a great tool for creating prototypes in a short time. You can check the Hexiwear's website for more information.

Hexiwear Block DiagramHardware architecture of the Hexiwear - Source: Hexiwear - MikroElektronika


How Does the System work?

The tracking system is going to inform the emergency service with the location information when the patient faints. First, we need to detect the faint. According to MedicineNet, heart rhythm changes are the most common cause of the faint (syncope), either increase or decrease[1]. Hexiwear has an optical heart rate sensor for measuring the heart rate. However, it is a demonstrative purpose and works on the fingertips. It requires more complex algorithms to measure heart rate on the wrist[2]. This makes it unfeasible to detect the faint using heart rate with Hexiwear so I created a simple algorithm using motion. The Hexiwear will measure the users movement via the accelerometer and gyroscope. If a sudden change occurs and is followed by a motionless state, it shows the user has fainted. Hexiwear also needs to inform emergency service. It has Bluetooth Low Energy connectivity which enables it to connect most smartphones. A simple android program gets the signal from the Hexiwear and sends the GPS location to the emergency service or responsible people. The program can be improved by adding medicine reminder, emergency button, enable/disable option, and whatever else you can imagine.

Let's Start Building Step by Step :)

Hexiwear is compatible with the mbed platform and I chose this platform. I prefer mbed because it is easy to write a program. It is cloud base so you don't need to download the development environment. There are some programs on the mbed Hexiwear Code Repository. I downloaded the serial port program and modified it. As a habit, I implement serial port for debugging purpose. You can remove it when the system is working properly. 

Main Function of serial.c Program

The main function includes printf commands to send data over the serial port and changing the state of the RGB LED using threads. You can find the whole program and other sources on my GitHub page and this program is saved as serial.c. The result of this code is as shown below.



















Hexiwear while blinking LED and sending data through the serial port.

Now, we can move on the next stage, detecting the faint. Since, it is not precise to measure heart rate, we can use the gyroscope and accelerometer. I need to confess that it is harder than I thought to detect the falling. I think I focused on benefits of the health tracking system more than the implementation of it. Preliminary results show that it requires a comprehensive research and testing so I will build a primitive fall detecting system. If you are interested in the topic, you can check research papers [3-5]. First of all, we need to fix the Hexiwear to make calculations easier and increase the accuracy. The algorithm will measure the accelerometer and gyroscope data and calculate the RMS values. If it exceeds the threshold values, the device will consider it a fall. Then after a few seconds, the Hexiwear will check for motion again. If it gives the constant results, it will assume the situation as a faint.

I planned to connect Hexiwear to the wrist but it makes calculation much harder so we need to fix the Hexiwear to make calculations easier and increase the accuracy. 

Let's move on to how we can do this with the code. At the beginning, we need to add the library files FXOS8700.h and FXAS21002.h for the accelerometer and gyroscope, respectively. Then, we need to create a thread which will measure the gyroscope and accelerometer data. RMS value can be easily calculated by the square root of the arithmetic mean of the squares of the gathered data. The tricky part is what is the threshold values for the faint. In order to calculate it, I took some measurements while walking and sitting with the Hexiwear fixed to my belt. I also collected data when the Hexiwear was stable on the table and when it was falling from the 50-60 cm above the ground.

Gyroscope and accelerometer data are taken from Hexiwear when it was fixed on a belt during different actions.

Gyroscope and accelerometer data are taken from Hexiwear when it fell from 50-60 cm above the ground.

The figures above depict that acceleration does not exceed 0.75 m/s2 while the gyroscope data stays around 30 °/s during the normal conditions. On the other hand, acceleration can reach up to 1.32 and the gyroscope gives results with three digits. I decided to choose the accelerometer limit to 1 and the gyroscope limit to 100. They are both far from normal conditions, so can be detected easily as a faint condition. When the measured data becomes greater than the threshold, the program waits five seconds and checks for a motionless state. If motion is detected, it is a false alarm. If not, it means that user has fainted.

Main part of the faintDetection.c program

You can find this program(faintDetection.c) on this link. I also added the raw data I have collected on my GitHub. This is the first part of the health tracking project for DesignSpark Test Drive. Next part(s), I will add Bluetooth connectivity and run OLED display to add some other functionalities.


1 - Fainting (Syncope)

2 - Heart Rate Inaccuracy

3 - Detecting Human Falls with a 3-Axis Digital Accelerometer

4 - On Developing a Real-Time Fall Detecting and Protecting System Using Mobile Device

5 - Detecting Falls with Wearable Sensors Using Machine Learning Techniques


Mehmet is an Embedded Systems Engineer and he loves to play with new boards(toys). He is looking for PhD opportunities. Lately, he has created a website where he shares his knowledge and postgraduate experience.

26 Jan 2017, 13:12