Project in progress
Alexa Skill for Seizure-Risk Users (Requires Wristband)

Alexa Skill for Seizure-Risk Users (Requires Wristband) © GPL3+

A wristband that works in conjunction with alexa to detect if the user is having a seizure, The wristband monitors pulse and gyroscope data.

  • 2,422 views
  • 0 comments
  • 6 respects

Components and supplies

About this project

Welcome To The Alexa Wristband Project

Hi my name is Kris, i've always been a strange but interesting individual. Hacking away in my in-home lab with the tools the internet has provided, expanding my knowledge by application and approach rather then studying and testing. I'd like to explain what it is im doing here quickly and straight to the point. So we can use our resources to benefit our outcome here on earth.

-Kris

What Is It

A wristband that detects seizures, comes equipped with a pulse, gyro sensor and connects to wifi to report events. What Is The Device Used For

  • Fall Risk
  • Seizure Detection
  • Irregular Arrhythmia Events
  • Autonomic Events Reporting

What It Can DoWhen the device detects a seizure,heart event,fall. Alexa will ask the user to respond. If there is no response the device will seek Medical help We have a layout and a test system in the works, the wristband sketch is in the development folder - Listed on GITWhere We've Come So FarCoding The Real - Time Notification PlatformThe Alexa / ECHO API, If used for what we are developing. The Alexa API will need to develop a NEW function for notifications to pass through without using context like "Im Reminding You" or require the user to ask what the notification is. so if there is a function integrated that can take text to speech and send it to alexa/ECHO without needing to be called on by a function - intent.We Need More Options ! More info about the problem found here...

https://community.smartthings.com/t/play-a-message-remotely-on-sensor-trigger-through-alexa-voice/56946

and here

https://stackoverflow.com/questions/33409530/amazon-echo-push-a-message-to-the-device

The Code

There is nothing special here just a API that makes a call to a home server to send the request to Alexa, store's the user's data... Requirements - Library'sIPArduino .INO File Property

http://www.instructables.com/id/Wearable-heart-beat-sensor-ESP8266Pulse-sensor/

ARDUINO

  • GYRO - mpu6050
  • WIFI - esp

Direct Links

EDA - https://easyeda.com/kris193/Bionic_Controller-fa710b2fb0de45e5890d60f8d222c095

Drive - http://docs.google.com/document/d/1Pn-qL3KPpfgW_2eByCOJL4VaNJWr2PjLrmeETrg6gzk/edit?usp=sharing

GIT- https://github.com/givemesite/ALEXA-APP

The PHP & Arduino CODE

PHP

<?PHP
//////////////////////
//    ALEXA //
// This is used to import all the lib's
// V0.0.2
//     GMS INC 2018
////////////////////// 
include ("./ALEXA.php");
//Fall Risk 
//Seizure Detection
//Irregular Arrhythmia Events   
//Autonomic Events Reporting
//////
?>

ARDUINO

//////////////////////
// This is used to import all the lib's
// V0.0.2
//     GMS INC 2018
//////////////////////
/////////////////////////////
/////////
///////// Setup Loop
//
//
//The Includes Files 
//#include <ESP8266WiFi.h> 
//#include <Ticker.h> 
/////////////////////////////
/////////
///////// Setup wifi 
//
//
#include <ESP8266WiFi.h>
#include <Ticker.h>
//The Includes Files 
//#include <ESP8266WiFi.h> 
//#include <Ticker.h> 
/////////////////////////////
/////////
///////// Setup Pin Trigers and Types
//
///*
   MPU6050 Triple Axis Gyroscope & Accelerometer. Motion detection.
   Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
   GIT: https://github.com/jarzebski/Arduino-MPU6050
   Web: http://www.jarzebski.pl
   (c) 2014 by Korneliusz Jarzebski
*/
#include <Wire.h>
#include <MPU6050.h>
//The Includes Files 
//#include <ESP8266WiFi.h> 
//#include <Ticker.h> 
/////////////////////////////
/////////////////////////////
//Fall Risk 
//Seizure Detection
//Irregular Arrhythmia Events   
//Autonomic Events Reporting
//#include <ESP8266WiFi.h> 
//#include <Ticker.h> 
void setup() { 
MPU6050 mpu;
Ticker flipper; 
const int httpPort = 80; 
Ticker sender; 
const int maxAvgSample = 20; 
volatile int rate[maxAvgSample];                    
// used to hold last ten IBI values 
boolean sendok = false; 
volatile unsigned long sampleCounter = 0;          
// used to determine pulse timing 
volatile unsigned long lastBeatTime = 0;          
// used to find the inter beat interval 
volatile int P =512;                      
// used to find peak in pulse wave 
volatile int T = 512;                     
// used to find trough in pulse wave 
volatile int thresh = 512;                
// used to find instant moment of heart beat 
volatile int amp = 100;                   
// used to hold amplitude of pulse waveform 
volatile boolean firstBeat = true;        
// used to seed rate array so we startup with reasonable BPM 
volatile boolean secondBeat = true;       
// used to seed rate array so we startup with reasonable BPM 
volatile int BPM;                   
// used to hold the pulse rate 
volatile int Signal;                
// holds the incoming raw data 
volatile int IBI = 600;             
// holds the time between beats, the Inter-Beat Interval 
volatile boolean Pulse = false;     
// true when pulse wave is high, false when it's low 
volatile boolean QS = false;   
const char* ssid = "ssid"; 
const char* password = "password"; 
WiFiClient client; 
const char* host = "192.168.1.80";//you pc IP 
//MPU 6050 
Serial.begin(115200);
 Serial.println("Initialize MPU6050");
 while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G))
 {
   Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
   delay(500);
 }
 mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS);
 mpu.setIntFreeFallEnabled(false);  
 mpu.setIntZeroMotionEnabled(false);
 mpu.setIntMotionEnabled(false);
 mpu.setDHPFMode(MPU6050_DHPF_5HZ);
 mpu.setMotionDetectionThreshold(2);
 mpu.setMotionDetectionDuration(5);
 mpu.setZeroMotionDetectionThreshold(4);
 mpu.setZeroMotionDetectionDuration(2);  
 checkSettings();
 pinMode(4, OUTPUT);
 digitalWrite(4, LOW);
 pinMode(7, OUTPUT);
 digitalWrite(7, LOW);  
 // End MPU 6050
 // Start Wifi 
Serial.begin(115200); 
delay(10); 
Serial.print("Connecting to "); 
Serial.println(ssid); 
WiFi.begin(ssid, password);  
while (WiFi.status() != WL_CONNECTED) { 
  delay(500); 
  Serial.print("."); 
} 
Serial.println(""); 
Serial.println("WiFi connected");   
Serial.println("IP address: "); 
Serial.println(WiFi.localIP()); 
Serial.print("connecting to "); 
Serial.println(host); 
if (!client.connect(host, httpPort)) { 
  Serial.println("connection failed"); 
  return; 
} 
//client.print("255"); 
delay(10); 
Serial.println(); 
Serial.println("end Setup"); 
flipper.attach_ms(2, Test); 
sender.attach(2, senderfunc); 
} 
void senderfunc() 
{ 
sendok=true; 
} 
/////////////////////////////
/////////
///////// MAIN Loop
//
//
//
//
/////////////////////////////
void loop() {   
// Start Sending BPM 
   if(sendok) 
   { 
      delay(100); 
          WiFiClient client; 
            const int httpPort = 80;
// to port to send the data 
            if (!client.connect("YOURPCIP", httpPort)) { 
              Serial.println("connection failed"); 
              return; 
            } 
            //Serial.print("Requesting URL: "); 
            // This will send the request to the server 
            client.print(BPM); 
            Serial.println(BPM); 
            delay(10); 
            sendok =false; 
            flipper.attach_ms(2, Test); 
   } 
} 
void sendtcp() 
{ 
} 
int count = 0; 
void Test() 
{ 
count++; 
if(count ==1000) 
{ 
  flipper.detach(); 
  count =0; 
  //sendtcp(); 
  sendok=true; 
} 
    Signal = analogRead(A0);              
// read the Pulse Sensor  
      sampleCounter += 2;                         
// keep track of the time in mS with this variable 
  int N = sampleCounter - lastBeatTime;       
// monitor the time since the last beat to avoid noise 
    if(Signal < thresh && N > (IBI/5)*3){       
// avoid dichrotic noise by waiting 3/5 of last IBI 
      if (Signal < T){                        
// T is the trough 
          T = Signal;                         
// keep track of lowest point in pulse wave  
       } 
     } 
  if(Signal > thresh && Signal > P){          
// thresh condition helps avoid noise 
      P = Signal;                             
// P is the peak 
     }                                        
// keep track of highest point in pulse wave 
//  NOW IT'S TIME TO LOOK FOR THE HEART BEAT 
// signal surges up in value every time there is a pulse 
if (N > 250){                                   
// avoid high frequency noise 
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) ){         
  Pulse = true;                               
// set the Pulse flag when we think there is a pulse 
  //digitalWrite(blinkPin,HIGH);                
// turn on pin 13 LED 
  IBI = sampleCounter - lastBeatTime;         
// measure time between beats in mS 
  lastBeatTime = sampleCounter;               
// keep track of time for next pulse 
       if(firstBeat){                         
// if it's the first time we found a beat, if firstBeat == TRUE 
           firstBeat = false;                 
// clear firstBeat flag 
           return;                            
// IBI value is unreliable so discard it 
          }    
       if(secondBeat){                        
// if this is the second beat, if secondBeat == TRUE 
          secondBeat = false;                 
// clear secondBeat flag 
             for(int i=0; i<=maxAvgSample-1; i++){         
// seed the running total to get a realisitic BPM at startup 
                  rate[i] = IBI;                       
                  } 
          } 
  // keep a running total of the last 10 IBI values 
  word runningTotal = 0;                  
// clear the runningTotal variable     
  for(int i=0; i<=(maxAvgSample-2); i++){               
// shift data in the rate array 
        rate[i] = rate[i+1];             
// and drop the oldest IBI value  
        runningTotal += rate[i];          
// add up the 9 oldest IBI values 
      } 
  rate[maxAvgSample-1] = IBI;                         
// add the latest IBI to the rate array 
  runningTotal += rate[maxAvgSample-1];               
// add the latest IBI to runningTotal 
  runningTotal /= maxAvgSample;                    
// average the last 10 IBI values  
  BPM = 60000/runningTotal;              
// how many beats can fit into a minute? that's BPM! 
  QS = true;                             
// set Quantified Self flag  
  // QS FLAG IS NOT CLEARED INSIDE THIS ISR 
  }                        
} 
if (Signal < thresh && Pulse == true){     
// when the values are going down, the beat is over 
    //digitalWrite(blinkPin,LOW);            
// turn off pin 13 LED 
    Pulse = false;                         
// reset the Pulse flag so we can do it again 
    amp = P - T;                           
// get amplitude of the pulse wave 
    thresh = amp/2 + T;                    
// set thresh at 50% of the amplitude 
    P = thresh;                            
// reset these for next time 
    T = thresh; 
   } 
if (N > 2500){                             
// if 2.5 seconds go by without a beat 
    thresh = 512;                         
// set thresh default 
    P = 512;                             
 // set P default 
    T = 512;                               
// set T default 
    lastBeatTime = sampleCounter;        
 // bring the lastBeatTime up to date         
    firstBeat = true;                     
// set these to avoid noise 
    secondBeat = true;                   
 // when we get the heartbeat back 
   } 
//sei();                                    
// enable interrupts when youre done! 

Code

Custom parts and enclosures

EDA
This the eda files https://easyeda.com/kris193/Bionic_Controller-fa710b2fb0de45e5890d60f8d222c095

Schematics

The EDA Files
EDA https://github.com/givemesite/ALEXA-APP

Comments

Similar projects you might like

Alexa Skill for Seizure-Risk Users (Requires Wristband)

Project in progress by GMS Bionics

  • 1,687 views
  • 0 comments
  • 6 respects

Wise Shower Driven by Alexa Skill

Project in progress by Virgilio Enrique Aray Arteaga

  • 2,853 views
  • 1 comment
  • 4 respects

Voice Activated Media Appliances Using Arduino and Alexa

Project tutorial by Patel Darshil

  • 5,413 views
  • 2 comments
  • 21 respects

DIY Air Humidifier with Backlight Controlled by Alexa

Project tutorial by Andrii Romanenko

  • 2,048 views
  • 0 comments
  • 8 respects

IoT arduino ESP Garage Door opener (UD)

Project in progress by David Smerkous

  • 13,324 views
  • 6 comments
  • 20 respects
Add projectSign up / Login