Elderly Assistant - IDC2018IOT

by עוזל1 in Circuits > Wearables

635 Views, 1 Favorites, 0 Comments

Elderly Assistant - IDC2018IOT

HomeCareAssistanceTO_image_120215.jpg

The main purpose of the elderly assistant IOT project is to provide care and support to our older lovely ones through IOT technology which combines multiple sensors which interactively reacts and notifies both the elderly person caregiver and the family of the elderly person. In case of emergency the system will:

  • The system monitors the movement of the elderly person throughout his movement through the house and both navigates him and contains an online tracking system to let his family know of his or hers movements.
  • In case of an emergency, the elderly person will click the push button and the system would send notification to the caregivers phone to let him know of the emergency.
  • The system also monitors the time that it takes to the caregiver to supply help for the elderly person and also the times that elderly person fall or bump into objects so his family can monitor the caregiver.

The main challenge that we've faced during the development of the project was actually the power supply to the ultrasonic sensor. We've began conducting measurements using the 3.3V pin of our WeMos board and the distance that supersonic sensor measured was always 0. At that point we researched online to understand that the supersonic sensor required 5V power supply. Thus, we combined the 5V power supply of our Arduino Uno board. This solution allowed us to both enjoy the power supply of the Arduino Uno board and the WIFI capabilities of the WeMos board. If you have on your board 5V power supply and WiFi capabilities you can use only your board and wont need another board like we did.

As for the system's limitations we would like to point out that the user would be required to carry the Arduino Uno board along with him and therefore would recommend a lighter power supply (like battery). Furthermore, you will need WiFi access to upload the data to Adafruit.io servers.

Time schedule for future developments:

In 1 month: Provide statistics about the data that we sent to adafruit.io server such as: the times of the day that the caregiver should be more accessible to the elredrly one needs.

In half a year: Integrate an automated AI capabilities using deep-learning to map the floor entirely for the elderly person's (or even blind man) needs and help him navigate through the different rooms within the house.

The Required Components

NodeMCU.jpg
Arduino UNO.jpg
ultrasonic_sensor.jpg
button.jpg
breadboard.jpg
jumper_wire.jpg
piezo_buzzer.jpg

The required components for this project:

  • NodeMCU
  • Arduino UNO (or any other power source with 5V)
  • Ultrasonic sensor
  • PushButton
  • Breadboard
  • Jumper wires
  • Android phone
  • WiFi connection
  • Piezo buzzer

Let's get this party started!

Connecting the Ultrasonic Sensor

step2.jpeg
ultrasonic_sensor.jpg
step22.jpg

As the name indicates, ultrasonic sensors measure distance by using ultrasonic waves. The sensor head emits an ultrasonic wave and receives the wave reflected back from the target. Ultrasonic Sensors measure the distance to the target by measuring the time between the emission and reception.

As you see in the picture the Ultrasonic sensor has 4 pins. The VCC needs to be connected to a 5V power pin - in our WeMos board there is only 3.3v power pin so we used the 5V power pin from our Arduino Uno board. The GND to a Ground pin (or gnd as it appears on our board). The Trig (Trigger) and the Echo pins are connected to pins D2, D1 equivalently.

Connecting the Piezo Buzzer to the NodeMCU

piezo_buzzer.jpg
step3.jpeg
step33.jpg

A buzzer is an audio signalling device, which may be mechanical, electromechanical, or piezoelectric (piezo for short). Typical uses of buzzers and beepers include alarm devices, timers, and confirmation of user input such as a mouse click or keystroke.

To connect the piezo buzzer, do as follows: The white wire is connected to D4 pin of the NodeMCU and the black wire is connected to gnd pin.

Connecting the Push Button:

button.jpg
step4.jpeg
step44.jpg

The Push Button is a electronic component that connects two points in a circuit when you press it. We use these little buttons on everything!

When the push button is open (unpressed) there is no connection between the two legs of the push button, and we read a HIGH. When the push button is closed (pressed), there is a connection between its two legs, connecting the pin to ground, so that we read a LOW.

To connect the push button, connect one pin of the push button to pin D4 of the NodeMcu and another pin to gnd.

Stream, Log and Interact With Your Data Using Adafruit.io

adafruit1.jpg
adafruit2.jpg
adafruit3.jpg
adafruit4.jpg
adafruit5.jpg
adafruit6.jpg
adafruit7.jpg
adafruit8.jpg
adafruit9.jpg

Adafruit IO is a system that makes data useful. They focus on ease of use, and allowing simple data connections with little programming required.

To get started and stream your data using adafruit.io follow the next steps:

  1. Sign up to adafruit.io here.
  2. Click on the Feeds tab and create a new feed.
  3. Give the feed a name and a little description.
  4. Click on the Dashboards tab and create a new dashboard.
  5. Give the dashboard a name and a little description.
  6. Create a new block.
  7. Click on the block type that you want to add, for example Line Chart.
  8. Chose the feed (or feeds) that you want to connect with the dashboard.
  9. Edit block settings as you wish and then click on "Create block".
  10. Find your username to be used in the code. You can find your username by visiting https://accounts.adafruit.com/ and logging in. Your username is right there!
  11. Find your adafruit.io key to be used in the code. You can find your key by visiting https://io.adafruit.com and look in the top left. You will see a little navbar with a yellow key, click it to see your key. If you regenerate your key, your old key will no longer be valid and you'll need to update all your projects!

Using Blynk App:

blynk1.jpg
blynk2.jpg
blynk3.jpg
blynk4.jpg
blynk5.jpeg
blynk6.jpeg

Blynk app is an open source software which helps in monitoring the NodeMCU board. It is available in play store

To get started and control the NodeMCU follow these steps:

  • Create a New Project.
  • Give it a name
  • Select NodeMCU as HW Model
  • Copy the AUTH TOKEN to be used in the code
  • Add the Notification Widget from Widget Box.
  • Press Play

Boom!! the hardware interface is over now let's get into coding

The Code:

NodeMCU.jpg
// Libraries
#include <ESP8266WiFi.h> #include "Adafruit_MQTT.h" #include "Adafruit_MQTT_Client.h" #include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Your Token From Blynk App";
// Your WiFi credentials.
// Set password to "" for open networks.
#define WIFI_SSID "Your Wifi Service Set Identifier (SSID)"
#define WIFI_PASSPHRASE "Your Wifi Password"
// Adafruit IO
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "Your Adafruit Username"
#define AIO_KEY         "Your Adafruit Key"
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// Store the MQTT server, client ID, username, and password in flash memory.
const char MQTT_SERVER[] = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] = AIO_KEY __DATE__ __TIME__;
const char MQTT_USERNAME[] = AIO_USERNAME;
const char MQTT_PASSWORD[] = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);
// Setup feed for arrival time
const char ARRIVAL_TIME_FEED[] = AIO_USERNAME "/feeds/arrival-time";
Adafruit_MQTT_Publish arrival_time = Adafruit_MQTT_Publish(&mqtt, ARRIVAL_TIME_FEED);
// Setup feed for number of crashes
const char NUMBER_OF_CRASHES_FEED[] = AIO_USERNAME "/feeds/number-of-crashes";
Adafruit_MQTT_Publish number_of_crashes = Adafruit_MQTT_Publish(&mqtt, NUMBER_OF_CRASHES_FEED);
// Functions
void connect();
void notifyOnButtonPress();
// Pins configuration
const int speakerPin = D3;
const int trigPin = D2;
const int echoPin = D1;
const int buttonPin = D5;
// Global variables
long duration;
int distance;
int safetyDistance;
// Used to deliver data to the adafruit interface
bool emergency = false;
unsigned long currentTime = 0;
unsigned long elapsedTime = 0;
void setup() {
  Serial.begin(9600);
  delay(10);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASSPHRASE);
  
  // wait for WiFi connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    delay(10);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println();
  // connect to adafruit io
  connect();
  Blynk.begin(auth, WIFI_SSID, WIFI_PASSPHRASE);
  // Pins setup
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(speakerPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
  // Initialize the supersonic sensor.
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Supersonic sensor data
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;
  safetyDistance = distance;
  // if we are too close to hit the wall
  if (safetyDistance <= 20) {
    // make warning sound
    tone(speakerPin, 1000, 1000);
    
    // ping adafruit io a few times to make sure we remain connected
      if (! mqtt.ping(3)) {
        // reconnect to adafruit io
        if (! mqtt.connected())
          connect();
      }
        // Publish data
        if (! number_of_crashes.publish(1))
          Serial.println("Failed to publish number of crashes");
        else
          Serial.println("Number of crashes published!");
  }
  Blynk.run();
  notifyOnButtonPress();
  delay(500);
}
// Check if the emergency button is pressed and publish data to adafruit.io
void notifyOnButtonPress()
{
  // Invert state, since button is "Active LOW"
  int isButtonPressed = !digitalRead(D5);
  if (isButtonPressed) {
    if (emergency == false)
    {
      emergency = true;
      currentTime = millis();
      // Note:
      //   We allow 1 notification per 5 seconds for now.
      Blynk.notify("EMERGENCY - GRRANDPA JUST PUSH HELP BUTTON!!!");
    }
    else
    {
      elapsedTime = millis() - currentTime;
      //convert from milliseconds to seconds
      elapsedTime = elapsedTime / 1000;
      Serial.println(elapsedTime);
      // ping adafruit io a few times to make sure we remain connected
      if (! mqtt.ping(3)) {
        // reconnect to adafruit io
        if (! mqtt.connected())
          connect();
      }
        // Publish data
        if (! arrival_time.publish((int) elapsedTime))
          Serial.println("Failed to publish arrival time");
        else
          Serial.println("Arrival time published!");
        
        emergency = false;
      }
    }
  }
  // connect to adafruit.io via MQTT
  void connect() {
    Serial.print("Connecting to Adafruit IO... ");
    int8_t ret;
    while ((ret = mqtt.connect()) != 0) {
      switch (ret) {
        case 1: Serial.println("Wrong protocol"); break;
        case 2: Serial.println("ID rejected"); break;
        case 3: Serial.println("Server unavail"); break;
        case 4: Serial.println("Bad user/pass"); break;
        case 5: Serial.println("Not authed"); break;
        case 6: Serial.println("Failed to subscribe"); break;
        default: Serial.println("Connection failed"); break;
      }
      if (ret >= 0) {
        mqtt.disconnect();
      }
      Serial.println("Retrying connection...");
      delay(5000);
    }
    Serial.println("Adafruit IO Connected!");
  }

A Demonstration Video

Demonstration video