Aman Kumarneeladri biswas (TheBlank)
Published © MIT

HealthEcos

HealthEcos - An ecosystem for realtime monitoring of health data and detection of the symptoms related to COVID-19 and medication management

AdvancedFull instructions provided20 hours967
HealthEcos

Things used in this project

Story

Read more

Schematics

Schematics - dispenser

HealthEcos Architecture

Basic architecture layout for the ecosystem

Schematics - Band

Code

Pill dispenser code

Arduino
The code for automatic programmable pill dispenser
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

Servo servo;

char auth[] = "***************";

char ssid[] = "yolo***";
char pass[] = "*********";
int a = 0;
int b = 0;
int c = 10;
int d = 0;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
servo.attach(2); //D4
servo.write(0);
delay(1500);
}

BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
a = pinValue;
}

BLYNK_WRITE(V2)
{
int pinValue = param.asInt();
b = pinValue;
}

BLYNK_WRITE(V3)
{
int pinValue = param.asInt();
c = pinValue;
}

BLYNK_WRITE(V4)
{
int pinValue = param.asInt();
d = pinValue;
}


void loop()
{
Blynk.run();
Serial.println(d);
if(d==1)
  {
    servo.write(90);
    Serial.println(a);
    Serial.println(b); 
    Serial.println(c);

    delay(c*1000);

    if(a>0 && b>0)
      {
        Serial.println("im in A loop");
        servo.write(90);
        delay(1000);
        servo.write(165);
        delay(1000);
        a=a-1;

        Serial.println("im in B loop");
        servo.write(90);
        delay(1000);
        servo.write(15);
        delay(1000);
        b=b-1;
      }

    else if(a>0 && b==0)
      {
        Serial.println("im in A loop");
        servo.write(90);
        delay(1000);
        servo.write(165);
        delay(1000);
        a=a-1;
    
        Serial.println("Refill Pill B");
        Blynk.notify("Refill Pill B");
      }

     else if(a==0 && b>0)
      {
        Serial.println("Refill Pill A");
        Blynk.notify("Refill Pill A");
        
        Serial.println("im in B loop");
        servo.write(90);
        delay(1000);
        servo.write(15);
        delay(1000);
        b=b-1;
      }
     else 
      {
        Blynk.notify("Refill Pill A & B");
        Serial.println("Refill Pill  A & B");
      }
   }
}

Alexa skill code (JSON)

JSON
{
"interactionModel": {
"languageModel": {
"invocationName": "pill dispenser",
"modelConfiguration": {
"fallbackIntentSensitivity": {
"level": "LOW"
}
},
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",

"samples": []
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
},
{
"name": "OnOffIntent",
"slots": [
{
"name": "OnOff",
"type": "OnOffValue",
"samples": [
"no",
"yes"
]
}
],
"samples": [
"switch {OnOff} pill dispenser",
"switch {OnOff} the pill dispenser",
"turn {OnOff} pill dispenser ",
"turn {OnOff} the pill dispenser"
]
}
],
"types": [
{
"name": "OnOffValue",
"values": [

{
"name": {
"value": "Off"
}
},
{
"name": {
"value": "On"
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "OnOffIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "OnOff",
"type": "OnOffValue",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.1491531299731.496876215167"
}
}

]
}
],
"delegationStrategy": "SKILL_RESPONSE"
},
"prompts": [
{
"id": "Elicit.Slot.1491531299731.496876215167",
"variations": [
{
"type": "PlainText",
"value": "Do you want to turn the pill dispenser on or off?"
}
]
}
]
}
}

Intent for switching on/off: -

JavaScript
Node js - 10
const http = require('http');
exports.handler = async (event, context, callback) => {
console.log(event.request.intent)
if (event.request.intent.slots.OnOff.value == "on") {
var responseJson = {
version: "1.0",
response: {
outputSpeech:
{
type: "PlainText",
text: "Okay, Switching On now",
},
shouldEndSession: true
},
sessionAttributes: {}
};
console.log("starting request...")
return new Promise((resolve, reject) => {
const options = {
host: 'blynk-cloud.com',
path: '/v3izbbVLp7NwS05NaSYIWq_NPIT-qnFk/update/V4?value=1',
port: 80,
method: 'GET'
};
const req = http.request(options, (res) => {
resolve('Success');
callback(null,responseJson);
});
req.on('error', (e) => {
reject(e.message);
var responseJson = {
version: "1.0",
response: {
outputSpeech:
{

type: "PlainText",
text: "I got an error from Blink",
},
shouldEndSession: true
},
sessionAttributes: {}
};
callback(null,responseJson);
});
// send the request
req.write('');
req.end();
});
} else {
return new Promise((resolve, reject) => {
var responseJson = {
version: "1.0",
response: {
outputSpeech:
{
type: "PlainText",
text: "Okay, Switching off now",
},
shouldEndSession: true
},
sessionAttributes: {}
};
const options = {
host: 'blynk-cloud.com',

path: '/v3izbbVLp7NwS05NaSYIWq_NPIT-qnFk/update/V4?value=0',
port: 80,
method: 'GET'
};
const req = http.request(options, (res) => {
resolve('Success');
callback(null,responseJson);
});
req.on('error', (e) => {
reject(e.message);
var responseJson = {
version: "1.0",
response: {
outputSpeech:
{
type: "PlainText",
text: "I got an error from Blink",
},
shouldEndSession: true
},
sessionAttributes: {}
};
callback(null,responseJson);
});
// send the request
req.write('');
req.end();
});
}
};

Smart Band code

Arduino
This contains the code for band used for real-time health monitoring of the person and data transmission to blynk app
#include <Dps310.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "********************"; // you need to create your own blynk id

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pi";
char pass[] = "********";

// Dps310 Opject
Dps310 Dps310PressureSensor = Dps310();
float a = 0;
float b = 0;
float p_prev;
float p_new;
float diff;
float height;

int Signal;
int s;
int PulseSensor= A0;

#define vTEMPERATURE_PIN V1
#define vPRESSURE_PIN V2
#define vPULSE_PIN V3
#define vALT_PIN V4


float Altitude()
{
  
  float altitude;
  float alt_pressure = b; // in Si units for Pascal
  // alt_pressure = alt_pressure/100;
  altitude = 44330 * (1.0 - pow((alt_pressure/1013.25), 0.1903));
  //altitude = altitude/1000;
  return altitude;
  
}


void setup()
{
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);
  while (!Serial);


  //Call begin to initialize Dps310PressureSensor
  //The parameter 0x76 is the bus address. The default address is 0x77 and does not need to be given.
  //Dps310PressureSensor.begin(Wire, 0x76);
  //Use the commented line below instead of the one above to use the default I2C address.
  //if you are using the Pressure 3 click Board, you need 0x76
  Dps310PressureSensor.begin(Wire);

  Serial.println("Init complete!");
}
BLYNK_WRITE(V1)
{
  float pinValue = param.asFloat();
  a = pinValue;
  
 }



void loop()
{
  Blynk.run();
  float temperature;
  float pressure;
  uint8_t oversampling = 7;
  int16_t ret;
  Serial.println();
  //Serial.print("Hello");

  //lets the Dps310 perform a Single temperature measurement with the last (or standard) configuration
  //The result will be written to the paramerter temperature
  //ret = Dps310PressureSensor.measureTempOnce(temperature);
  //the commented line below does exactly the same as the one above, but you can also config the precision
  //oversampling can be a value from 0 to 7
  //the Dps 310 will perform 2^oversampling internal temperature measurements and combine them to one result with higher precision
  //measurements with higher precision take more time, consult datasheet for more information
  ret = Dps310PressureSensor.measureTempOnce(temperature, oversampling);

  if (ret != 0)
  {
    //Something went wrong.
    //Look at the library code for more information about return codes
    Serial.print("FAIL! ret = ");
    Serial.println(ret);
  }
  else
  {
    Serial.print(" Temperature: ");
    a = temperature;
    Serial.print(temperature);
    Serial.println(" degrees of Celsius");
    //Serial.println(a);
    Blynk.virtualWrite(vTEMPERATURE_PIN, a);
  }

  //Pressure measurement behaves like temperature measurement
  //ret = Dps310PressureSensor.measurePressureOnce(pressure);
  ret = Dps310PressureSensor.measurePressureOnce(pressure, oversampling);
  if (ret != 0)
  {
    //Something went wrong.
    //Look at the library code for more information about return codes
    Serial.print("FAIL! ret = ");
    Serial.println(ret);
  }
  else
  {
    Serial.print(" Pressure: ");
    Serial.print(pressure);
    Serial.println(" Pascal");
    b = pressure/100;
    Blynk.virtualWrite(vPRESSURE_PIN, b);
    
  }

  p_new = pressure;
  diff = p_new - p_prev;
  p_prev = p_new;
  Serial.print(" Pressure Difference: ");
  Serial.println(diff);
  if(diff > 2.0)
  {
    Serial.println(" Person might had a fall");
    //Blynk.notify(" Person might had a fall, Waiting for 3 secs.... to detect if the fall truly happened ");
    Serial.println(" Waiting for 3 secs.... to detect if the fall truly happened ");
    delay(3000);
    float fall_pressure;
    ret = Dps310PressureSensor.measurePressureOnce(fall_pressure, oversampling);
    if (ret != 0)
  {
    //Something went wrong.
    //Look at the library code for more information about return codes
    Serial.print("FAIL! ret = ");
    Serial.println(ret);
  }
  else
  {
    Serial.print(" Fall Pressure: ");
    Serial.print(fall_pressure);
    Serial.println(" Pascal");
  }
//    float fall_pressure = f_pressure;
//    Serial.println(f_pressure);
//    Serial.print(" Fall pressure: ");
//    Serial.println(fall_pressure);
    if(abs(p_prev - fall_pressure) < 1.0)
    {
      Serial.println(" Help needed for the person. ");
      Blynk.notify(" Person had a fall, needs help!! ");
    }
  }
// pulse sensor code
  Signal = analogRead(PulseSensor);
  s = Signal/8;
  Serial.print(" BPM: ");
  Serial.println(s);
  Blynk.virtualWrite(vPULSE_PIN,s);
  //Wait some time
  delay(500);

  
  height = Altitude();
  Blynk.virtualWrite(vALT_PIN,height);
}

Credits

Aman Kumar

Aman Kumar

1 project • 3 followers
neeladri biswas (TheBlank)

neeladri biswas (TheBlank)

0 projects • 0 followers

Comments