In this tutorial we will show you how you can build an epileptic seizure detecting bracelet.
IntroductionFor people who suffer from epileptic seizures, a quick response by medical services can often be of the utmost importance, as it can reduce the negative consequences (such as physical harm and brain damage). Wearing an epilepsy bracelet provides them with a means of quick detection and a call for help.
DescriptionThis project is comprised of an Arduino Nano board, which acts as our bracelet and an app, which runs on a mobile phone and acts as our means of notifying the appropriate people (for example a caretaker).
Information about the wearer's movements is sampled by accelerometers on the Arduino board. It then processes this information using machine learning algorithms to determine whether the wearer is experiencing a seizure or not.
When the Arduino detects movement resembling an epileptic seizure, it sends a signal to the connected mobile phone via Bluetooth Low Energy (BLE). Upon receiving this signal an alert starts within the app and a countdown timer is triggered. After 10 seconds, if the alert is not canceled, the app will send a text message and call the preset phone number.
The measured acceleration profile of a person experiencing a seizure is distinct. It is a series of rapid movements usually in more than one axis, the frequency of which varies through time. This is how it can be distinguished from everyday activities (as for example brushing your teeth or running) which are more consistent. As such given enough data we can build a predictive model.
- Edge Impulse
Edge Impulse is a free development platform for machine learning. We created an account using a shared email and created a new project. This is important as simply making your project public and sharing it with your peers will not enable them to make adjustments to the model or help you collect data.
- Data collection
We found the best way to collect data was using our phones (and not the Arduino board) as it was simpler to set up and enabled faster acquisition of the data. To connect your phone simply select "devices" from the menu on the left, then " + Connect device" and "Use your mobile phone". You will be presented with a QR code which you can then use to connect your phone.
This is where the arduous process of collecting data starts. We decided that each of us would contribute at least 10 minutes of data. Our sample duration is 10 seconds, which means we each contributed at least 30 samples of seizures (which we labeled 1) and 30 samples of everyday activities (which we labeled 0). Make sure to have the same amount of data for both groups, otherwise the final model could have problems with correctly predicting seizures.
As we did not have acces to patients suffering from epilepsy, we had to imitate seizures for the purpose of data collection. We achieved a similar movement by extending our arm and twitching randomly in differing directions and with differing intensity.
Having collected enough data we have to redeploy it into a training set, a validation set and a test set, usually in a ratio of 60%, 20%, 20% but we can use our own ratios by assigning samples to their respective sets.
- Creating an Impulse
Creating the ideal Impulse is more trial and error than an exact science. After selecting "Create impulse" we add a processing block and a learning block then save the impulse. Within impulse settings, we select how our data will be processed and used for predicting final results.
Check your parameters in "Spectral features" and save them. You can then generate features to see a representation of your data:
To train your model select "NN Classifier" and click "Start training". After some time you will be presented with data concerning the accuracy of your model.
Following this, test your model in the "Model testing" tab. Should you want to improve the accuracy of your model, you will likely have to play with the parameters within the "spectral features" tab, as well as Neural network settings and Neural network architecture within the "NN Classifier" tab. Remember that with higher accuracy comes greater complexity. Make sure your model isn't too complex or your Arduino Nano won't be able to run it.
DeploymentUnder the "Deployment" tab select "Arduino library". You will be presented with a zip library containing your model, which you can then compile onto your Arduino Nano. You can find our library on github in the attachments of this article.
We can now check if our model is working properly. Open your serial monitor then take your Arduino and shake it in a manner similar to when you were collecting data.
We have slightly modified the exported code from Edge Impulse so that the app connects to the Arduino via BLE without opening the serial monitor. It also automatically connects the bracelet with the app without having to select the proper device from a list of available bluetooth devices.
Furhtermore we have modified our code so the arduino always keeps sending either 0 or 1 via BLE to the Arduino (not just when the value changes), depending on whether the movement is classified as an epileptic seizure or not. This is so our application knows whether our Arduino is working properly or not. If for example the battery powering the bracelet failed, the app would not detect this and would display a normal state for our user, which is a serious issue.
As the arduino analyzes smaller segments (0.5 second) from the accelerometers we had to make further modifications. As such we built in an additional check. To trigger an alert on the app a seizure must be detected for at least 10 seconds (several segments, 20 in our case).
Mobile applicationThe mobile application was developed using Mit2app inventor for android devices. Developing an app in this enviroment is fast and simple, because of it's use of blocks as programming interface. One of the downsides however is a lack of scalability and limits in graphical user interface design.
Our application works as follows. First we need to input our caretakers phone number. Then the app starts scanning for devices and automatically connects to the Arduino bracelet. While it is connected, the app listens for seizure signals (in our case the number "1") coming from bracelet. When one is received, it starts a countdown timer lasting 10 seconds and if the timer is not canceled by the user, the app send a SMS and if selectd, also makes a call.
Many people can feel an attack coming. If a user starts to feel an upcoming seizure, he can click a big SOS button, which triggers both the SMS and the call function, regardless of the signals sent by the arduino.
ConclusionThis application enables you to autonomously contact your caretaker in case of a seizure. Both the call and SMS function are functioning as envisioned and we were able to satisfactorily achieve our goal despite our limited resources and short timeline. There are however some improvements to be made, which would significantly enhance the user experience and which should be considered before trying to put any such device on the market.
- Possible improvements
One of the limiting factors we had, is not having real acceleration sensor data for seizures (positive cases), which we had to simulate on our own. Given enough time and access to patients suffering from epilepsy would remedy this problem.
The app itself while functional, could be made to look more appealing to the masses. Before any introduction to the market is made a switch to native code should be considered as it enables much more flexibility in app design.
Wearability is another problem. For our proof of concept we simply strapped the Arduino Nano (which was connected to a power bank) to our wrists using a simple wristband. Improvements here would include a case for the Arduino, to make the board more robust in every day use and a proper wristband. Finding a small power source that could fit into the casing and provide a sufficient use duration would also be optimal.
Comments