What I intend to do is come up with a system that will detect and alert the uncommon movements in sleep, since seizures will not be tested I will focus on the most common data from visual muscle twitches and jerks, adding on possible add-ons in the future would be fun to play around building a more diverse system.   Since there is so much we can do its best we just try to focus on a working under the bed mattress detection system that will relay irregular patterns to a remote device. - Wesley Gardner

 

Well lets start off by going with this.....

I now know if I had more time I certainly would have been able to do more but with the time I had I felt like I accomplished what I set out to do.  In some way that is.  When I first started I decided to freshen up on the ST Software and constantly the BLE module was looking at me while I was doing so. This caused me more time invested in learning about the module then what I intended on doing.

oOoOoOo Shiny!

Sometimes we get distracted and that happens, so lets just pretend the BLE module doesn't even exist in this design challenge going forward here.

 

Lets just say time was not on my side as it seems to be as of late so I had to get going.  I was having issues right off the bat of course you can't use the ST Software on Linux and you can't even install the STM32 boards on the Raspberry Pi in the Arduino IDE.  And of course I always like to use a Raspberry Pi in a project whenever I can so this was no different and was very glad I did as it made things more interesting and not so straight forward in my books.  Well since I would have to make it so that both would communicate well together I opted for using the Arduino IDE on a windows PC to program the Nucleo board.  This would allow me to once put onto the Raspberry Pi be able to read the serial outputs on the board making it so that I would be able to set the Raspberry Pi as my Host unit.

 

The first thing I had to do was update the board to handle the STM32 boards.

For doing this all I did was  I went to -->File--->Preferences-->Select Additional Board manager

Then entered the following into the Additional Boards Manager URLs:

https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json

Click OK and then go to Tools--->Board--->Board Manager

Search for STM32 Cores and install

Then you should be able to select your board I am using a NUCLEO-H743ZI2 So I selected NUCLEO-144 AND then my board Part number: NUCLEO H743ZI2

 

When it came to the wiring of the unit I just soldered it  onto a male header pin and put it into a breadboard so that I could just run my wires where I needed them to go without any issues just in case I wanted to move or adjust anything going forward.

 

Pin 1 connect to 5v

Pin 2 Connect to A0

Pin 3 connect to Ground

 

KEMET SENSOR

PIN 1 = VIN  = Power input        = Red

Pin 2 = Vout = Sensor Output   = White

Pin 3 = GND  = Ground             = Black

 

The Arduino Code I decided I would try converting it to a voltage to allow for a possible more stable flow once it was active. I did try baldengineer example which worked and I played around with his code for a bit but ended up wanting a lower value.

 

The Code: Also found in the bottom of this document as a download for easy access.

//KEMET SENSOR
//PIN 1 = VIN  = Power input
//Pin 2 = Vout = Sensor Output
//Pin 3 = GND  = Ground

//I am using the Nucleo 144 on PC to upload my data to the unit.
//Currently not able to upload via Raspberry Pi.  
//Will certainly check out options later.
//Open-->File--->Preferences-->Select Additional Board manager 
//Enter: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json 
//Click OK and then go to Tools--->Board--->Board Manager
//Search for STM32 Cores and install
//Then you should be able to select your board
//I am using a NUCLEO-H743ZI2 So I selected NUCLEO-144 AND then my board 
//Part number: NUCLEO H743ZI2


const int Kemet = A0; 

void setup() 
{
  Serial.begin(57600);
  delay(2500);
  while(!Serial);  
  Serial.println("STM32 Analog Read Test on Raspberry Pi");  
}

void loop() 
{
  int kemetADC = analogRead(Kemet);
  float kemetV = kemetADC / 1023.0 * 5.0;
  Serial.println(kemetV); 
  delay(100);
}

 

So now that I had it all working it was time to head over to the Raspberry Pi, to use another program I have not used for many things but thought I would give it a shot again due to the flexibility I would have in the long run and being able to share what I have done and so that others could use either other vibration sensors and even use a Arduino UNO and create their own unit at a fraction of the cost of using the ST board and Kemet sensor.

 

We are going to be using Node-Red which you can get from https://nodered.org/  I think its a pretty sweet setup and have come to really enjoy the program.   On the Raspberry Pi make sure to check your version I think I actually had to upgrade mine as the version in the raspberry pi repo was out of date.

 

On the Raspberry Pi we needed to set a few things the timestamp was set to .20 Seconds   the Nucleo on the serial node was set to the settings we put in our arduino code which then we could output the data to a gauge, chart, or text reading perfect!

Output of the sensor when no vibration is detected....it may have been picking up noise from the multiple raspberry pi's I had on my desk at the time as well.  But this allowed us to keep track of the unit and find out a good base line roughly where the normal values would be.

 

As you can see here when the sensor is knocked or shaken it outputs a higher reading and even a lower....we want to try to use both of those upper and lower readings as triggers

Now I am not so good at this but I just wanted to list the abnormal reading and set the alarm for it and test if it would work and yes it seems to be working posting a 4.88 reading which is above the abnormal reading.  Now I was having a issue as I set the reading for normal reading to be between the two reading so 3.6 to 4.1 and I was getting a constant output which then was putting too much data out into the part that I wanted to concentrate on and that was using Twilio as my method of notification.  You can sign up for a free account and get some credits which makes it nice and easy to get your projects going.  But when I did I had a mass amount of text messages coming in as I was sending all values to the output which, like I said I am not the greatest when it comes to any of this and have tons to learn.  After using node red on this project I certainly will be playing with it a lot more as I have found just how versatile and helpful it can be in quickly prototyping a device.  And your able to host your own dashboard which then in turn you can self host all your projects and still be able to access it anywhere.

 

If you would like to try Twilio out you can check it out here and its a referral link so you would be helping me get some extra credits as well.  www.twilio.com/referral/lYh8Bd

 

you can import the following into node red to get a more hands on view of everything (Twilio info was removed from code you will have to setup your own)

[

    {

        "id": "85973545.a09aa8",

        "type": "tab",

        "label": "Flow 1",

        "disabled": false,

        "info": ""

    },

    {

        "id": "fdcbf895.d9cc98",

        "type": "serial request",

        "z": "85973545.a09aa8",

        "name": "nucleo",

        "serial": "cadc46e0.46f658",

        "x": 410,

        "y": 320,

        "wires": [

            [

                "ebff47d1.1af248",

                "777dd95b.afe868",

                "d1244039.a4d71",

                "9f4b9de.d70406",

                "2f5f4fea.f0b49"

            ]

        ]

    },

    {

        "id": "d1244039.a4d71",

        "type": "ui_text",

        "z": "85973545.a09aa8",

        "group": "209b6d13.846b12",

        "order": 0,

        "width": 0,

        "height": 0,

        "name": "",

        "label": "vibration Kemet Sensor Reading",

        "format": "{{msg.payload}}",

        "layout": "row-spread",

        "x": 730,

        "y": 200,

        "wires": []

    },

    {

        "id": "d45ac32c.c4f03",

        "type": "debug",

        "z": "85973545.a09aa8",

        "name": "",

        "active": true,

        "tosidebar": true,

        "console": false,

        "tostatus": false,

        "complete": "payload",

        "targetType": "msg",

        "statusVal": "",

        "statusType": "auto",

        "x": 790,

        "y": 420,

        "wires": []

    },

    {

        "id": "17089e69.8c0b72",

        "type": "inject",

        "z": "85973545.a09aa8",

        "name": "",

        "props": [

            {

                "p": "payload"

            },

            {

                "p": "topic",

                "vt": "str"

            }

        ],

        "repeat": ".2",

        "crontab": "",

        "once": false,

        "onceDelay": 0.1,

        "topic": "",

        "payload": "",

        "payloadType": "date",

        "x": 240,

        "y": 320,

        "wires": [

            [

                "fdcbf895.d9cc98"

            ]

        ]

    },

    {

        "id": "777dd95b.afe868",

        "type": "ui_chart",

        "z": "85973545.a09aa8",

        "name": "",

        "group": "209b6d13.846b12",

        "order": 1,

        "width": 0,

        "height": 0,

        "label": "chart",

        "chartType": "line",

        "legend": "true",

        "xformat": "HH:mm:ss",

        "interpolate": "bezier",

        "nodata": "",

        "dot": false,

        "ymin": "",

        "ymax": "",

        "removeOlder": "30",

        "removeOlderPoints": "",

        "removeOlderUnit": "1",

        "cutout": 0,

        "useOneColor": false,

        "useUTC": false,

        "colors": [

            "#1f77b4",

            "#aec7e8",

            "#ff7f0e",

            "#2ca02c",

            "#98df8a",

            "#d62728",

            "#ff9896",

            "#9467bd",

            "#c5b0d5"

        ],

        "outputs": 1,

        "x": 650,

        "y": 140,

        "wires": [

            []

        ]

    },

    {

        "id": "ebff47d1.1af248",

        "type": "ui_gauge",

        "z": "85973545.a09aa8",

        "name": "",

        "group": "209b6d13.846b12",

        "order": 0,

        "width": "3",

        "height": "3",

        "gtype": "gage",

        "title": "gauge",

        "label": "units",

        "format": "{{value}}",

        "min": 0,

        "max": "5",

        "colors": [

            "#00b500",

            "#e6e600",

            "#ca3838"

        ],

        "seg1": "3",

        "seg2": "4",

        "x": 650,

        "y": 80,

        "wires": []

    },

    {

        "id": "46cb34b6.99722c",

        "type": "twilio out",

        "z": "85973545.a09aa8",

        "twilio": "",

        "twilioType": "sms",

        "url": "",

        "number": "",

        "name": "ESMS-W",

        "x": 840,

        "y": 520,

        "wires": []

    },

    {

        "id": "2f5f4fea.f0b49",

        "type": "function",

        "z": "85973545.a09aa8",

        "name": "Vibration",

        "func": "var payload=msg.payload;\nvar alarm_flag=context.get(\"alarm_flag\");\nif(typeof alarm_flag==\"undefined\")\nalarm_flag=false;\n\nif (payload>4.2 && !alarm_flag)\n{\n        alarm_flag=true;\n        msg.alarm=1;\n        context.set(\"alarm_flag\",alarm_flag);\n        msg.topic = \"Subject: Vibration Abnormal\"\n        return msg;\n}\n\nif (payload<3.5 && !alarm_flag)\n{\n        alarm_flag=true;\n        msg.alarm=1;\n        context.set(\"alarm_flag\",alarm_flag);\n        msg.topic = \"Subject: Vibration Abnormal\"\n        return msg;\n}\n",

        "outputs": 1,

        "noerr": 0,

        "initialize": "",

        "finalize": "",

        "x": 580,

        "y": 420,

        "wires": [

            [

                "d45ac32c.c4f03",

                "46cb34b6.99722c"

            ]

        ]

    },

    {

        "id": "9f4b9de.d70406",

        "type": "debug",

        "z": "85973545.a09aa8",

        "name": "",

        "active": false,

        "tosidebar": true,

        "console": false,

        "tostatus": false,

        "complete": "false",

        "statusVal": "",

        "statusType": "auto",

        "x": 830,

        "y": 320,

        "wires": []

    },

    {

        "id": "cadc46e0.46f658",

        "type": "serial-port",

        "serialport": "/dev/ttyACM0",

        "serialbaud": "57600",

        "databits": "8",

        "parity": "none",

        "stopbits": "1",

        "waitfor": "",

        "dtr": "none",

        "rts": "none",

        "cts": "none",

        "dsr": "none",

        "newline": "\\n",

        "bin": "false",

        "out": "char",

        "addchar": "",

        "responsetimeout": "200"

    },

    {

        "id": "209b6d13.846b12",

        "type": "ui_group",

        "name": "Vibration",

        "tab": "d5323251.7cc73",

        "order": 2,

        "disp": true,

        "width": "14",

        "collapse": false

    },

    {

        "id": "3397fae1.7472d6",

        "type": "twilio-api",

        "name": "ESMS",

        "sid": "",

        "from": ""

    },

    {

        "id": "d5323251.7cc73",

        "type": "ui_tab",

        "name": "Home",

        "icon": "dashboard",

        "disabled": false,

        "hidden": false

    }

]

So when it comes down to it we need to finally see if it works well lets have a look at my phone capture and see what actually appeared.

 

I had to remove a few of the messages from before when there was a mass text to my phone from it but as you can see the 4.88 warning of vibration this is a quite aggressive measurement in my books which would be consistent with a convulsive seizure.  Now there is way more that I can do and will be playing around with as I am quite enjoying Node-Red.  I still need to have it take multiple high readings and make that the trigger and then a duration trigger as anything over 4 minutes one would probably want to have EMS on scene in my research that is which we can send another notification stating the duration time of each seizure.

 

I also decide I would make a case which I could then attach some more wires to as a quick back yard approach at making my own sensor pad which would work on a recliner chair and on a hospital bed mattress.

 

Nobody said it had to be pretty.

 

So originally it was suppose to have a top case as well but found the brackets where enough to hold it in.

 

But I couldn't find thin enough wire and a chunk of foam that I was wanting to use as the base and thread it through multiple times.  This would just have to do which in the end it worked and I was happy with the result I was able to put it under a mattress and cause it to react and send a message.  Now depending on the mattress it might have to be placed on top on a chair it would be fun to make a thin cushion to house the unit.

 

I have most defiantly learned a lot from this design challenge and it has opened my eyes to a whole bunch of new projects and things I would love to spend more time learning about I would have loved to have had a unit that I could have given to someone to use and setup and be able to test for me.

 

With twilio the free account it has a limit to one phone number you can send a text message to the reason I thought twilio would be a great fit as if it was a working solution one would be able to use a paid account and be able to use multiple phone numbers to be able to receive the messages since at 3am and the support worker is down stairs playing video games or having a nap it is crucial they be notified right away as well as anyone else that wants to be notified.  Having duration notifications would be great as well which you could set to send to certain numbers which would help collect data on the person having seizures as well.

 

All my files are in the zip file below feel free to check it out it includes Arduino files, Sketchup and STL files, Node-Red JSON and code to import either works.