DIY epilepsy seizure detector

    My friend has some strange health problems. Doctors say this is "cryptogenic epilepsy." The bottom line is that sometimes in his sleep at night he begins to have an “shake” attack. In the end, I was asked to make a device that should be worn on the arm and squeaky nasty if you shake it for ten seconds to notify loved ones and help in a timely manner.

    The most obvious solution is to use an accelerometer. I bought one of the first ones I got - the BMA150 from Bosch.


    Small, infection, only 3x3mm, but we didn’t solder it.

    I must say right away that I am doing this exclusively at the amateur level, so do not criticize much.

    After reading the datasheet, it turned out that it is possible to communicate with the accelerometer via I²C or SPI, but also has a special output for external interrupt. Those. You can configure it once so that under certain conditions it outputs a logical unit there. In our case, this is ideal - you do not need to constantly interrogate the sensor, it will itself wake the microcontroller from sleep mode if there is a certain amount of shaking. This is very important, given that you need to make the device as economical as possible in terms of power.

    Accelerometer Setup

    For experiments and tuning, I etched the board so that I could easily solder:

    For some reason, the I²C accelerometer did not want to work. It’s possible that I was mistaken somewhere. But on SPI everything worked without problems. The sensor is available as an array of memory, which is divided into two parts:

    • EEPROM with default settings, i.e. which are used at the time of inclusion
    • Operation registers with current settings and sensor readings

    My joy knew no bounds when I finally received the data: The

    accelerometer can automatically generate an external interrupt in a variety of cases. We need the simplest event - any sufficiently strong movement. The sensor does this if the following condition is true on any axis:

    |acc(t0)-acc(t0+3/(2*bandwidth))| >= any_motion_thres

    any_motion_thres is set in a special register. Empirically, I found out that with a refresh rate of 25Hz, the optimal value is 20h. In this situation, the interrupt flag is set if it is easy to shake the sensor. The flag is removed automatically if the condition ceases to be fulfilled for some time.

    Having made sure that all parameters are set optimally, I saved these settings already in EEPROM. Thus, the accelerometer immediately after switching on will output a logical unit to INT if there is movement, and SPI is no longer needed.

    Board Development

    I chose the ATMEGA8A microcontroller. It has two external interrupts (I decided to use one of them for the button, and the other for the accelerometer itself), works in the voltage range 2.7-5.5V, and in the deepest sleep mode, “power down” consumes only 0.5uA. It is assumed that the microcontroller will sleep almost all the time, because energy conservation is very important. However, to wake up from such a sleep mode, it is necessary to close the INT0 / INT1 foot to the ground, and the accelerometer, if there is movement, on the contrary gives a high level, so for inversion you need to put a transistor. I decided to power the sensor directly from the feet of the microcontroller itself, so that it could be turned on and off without unnecessary losses. The speaker also connected directly. For debugging, it was decided to put another LED. I did not draw a diagram, and the board as a result looked like this:

    Ready board: Alas, I only had a tweeter, which turned out to be larger than the board itself:


    Everything is quite simple here. The device has two operating modes:

    • Off. In this state, we do not supply power to the accelerometer and wake up only at the touch of a button. In this form, the microcontroller can work for at least a year (verified), the battery discharge is close to self-discharge.
    • Included. When the device is turned on, we power up the accelerometer and wake up both from the press of a button and from the signal from the sensor. If the button lasts one and a half seconds, the device goes back to the off state. If the interrupt generated a signal from the sensor, and it repeats for 10 seconds at least once in two seconds, then we will sound the alarm until the button is pressed.

    The accelerometer, by the way, also has a sleep mode, from which it can wake up at predetermined time intervals, but I decided not to use it, so as not to affect the accuracy and reliability. According to the documentation, this sensor consumes 200 μA, this should be enough for many nights.

    Body building

    The case was decided to print on a 3D printer.

    In the end, everything looked like this: Alas, in the end the device turned out to be very bulky and collective farm: But this is still the first experimental model. I think that later the size and appearance can be greatly optimized. Well, do not forget that even in this form it can save a person’s life. Video device in operation:

    Sorry for the dirty fingers, they are still in plastic and ferric chloride.

    I foresee certain questions, I will answer them immediately:

    • Yes, seizures in this person only in a dream
    • Yes, all bouts are accompanied by shaking
    • The button is recessed, so it’s difficult to accidentally turn off the device

    Update as of July 6, 2014

    As I promised, I could not stop on the first version, all the more as a result I was asked to reduce the response time and increase the sensitivity.

    Alas, the BMA150 accelerometers were no longer available in the store, but there was a BMA250. A quick glance at the datasheet showed that it was even much cooler. True, even less:

    Two by two millimeters, with 12 contacts. However, this time there were no problems with sizes. It is rather even a plus.

    This model has a number of very nice settings. And the polarity of the interrupt can be indicated (goodbye, an additional transistor), and their duration, and much more. Yes, it's just great! I was already very happy when I selected the optimal parameters for all the registers, but all the joy came to naught when I realized that the BMA250 does not have the ability to save these settings in EEPROM. This is such a fly in the ointment that I could not believe it for a long time.

    I had to separate on the board and SPI to the accelerometer, so that every time I turn it on I would configure it again.

    But if you have to change any of the settings, it will not need to be evaporated. And yes, I listened to the advice in the comments and used a small piezo buzzer, the battery is placed under the board, as a result, the device has greatly decreased in size. Even when turned on, the voltage on the battery is now measured, and if it is lower than 2.8V, an additional signal is emitted. For this, an ADC with an internal 2.56V stabilizer and a voltage divider is used to fit into this range.

    In the case:

    And when closed:

    Also popular now: