Introduction: Elderly Assistant - IDC2018IOT

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 servers.

Time schedule for future developments:

In 1 month: Provide statistics about the data that we sent to 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.

Step 1: The Required Components

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!

Step 2: Connecting the Ultrasonic Sensor

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.

Step 3: Connecting the Piezo Buzzer to the NodeMCU

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.

Step 4: Connecting the Push Button:

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.

Step 5: Stream, Log and Interact With Your Data Using

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 follow the next steps:

  1. Sign up to 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 and logging in. Your username is right there!
  11. Find your key to be used in the code. You can find your key by visiting 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!

Step 6: Using Blynk App:

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

Step 7: The Code:

// 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      ""
#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_PASSWORD[] = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
// 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.print("Connecting to ");
  // wait for WiFi connection
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  // connect to adafruit io
  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);
  digitalWrite(trigPin, HIGH);
  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 (! {
        // reconnect to adafruit io
        if (! mqtt.connected())
        // Publish data
        if (! number_of_crashes.publish(1))
          Serial.println("Failed to publish number of crashes");
          Serial.println("Number of crashes published!");
// Check if the emergency button is pressed and publish data to
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.
      elapsedTime = millis() - currentTime;
      //convert from milliseconds to seconds
      elapsedTime = elapsedTime / 1000;
      // ping adafruit io a few times to make sure we remain connected
      if (! {
        // reconnect to adafruit io
        if (! mqtt.connected())
        // Publish data
        if (! arrival_time.publish((int) elapsedTime))
          Serial.println("Failed to publish arrival time");
          Serial.println("Arrival time published!");
        emergency = false;
  // connect to 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) {
      Serial.println("Retrying connection...");
    Serial.println("Adafruit IO Connected!");

Step 8: A Demonstration Video