Project tutorial

The Arduino101 way of Caregiving! © CC BY

Dealing with ill people or elderly at your home? No problem, here's the solution.

  • 671 views
  • 1 comment
  • 4 respects

Components and supplies

Ardgen 101
Arduino 101 & Genuino 101
×1
Seeed Grove Starter Kit for Arduino 101
×1
Servo (generic)
A servo
×1
SeeedStudio Grove - Button
×1
SeeedStudio Grove - Touch Sensor
×1
SeeedStudio Grove - Temperature Sensor
×1
SeeedStudio Grove - RGB LCD
×1
SeeedStudio Grove - Buzzer
×1
SeeedStudio Grove - Sound Sensor
×1
2821 01
Adafruit Feather HUZZAH with ESP8266 WiFi
Optional (for MQTT stuff)
×1
1434509556 android phone color
Android device
OPTIONAL - must choose one device
×1
Iphone hero
Apple iPhone
OPTIONAL - must choose one device
×1
Hero ipad family 2015 2x
Apple iPad
OPTIONAL - must choose one device
×1

Apps and online services

Blynk logo avatars
Blynk
NodeRED
Optional

About this project

Introduction

It's not always easy to take appropriate care of ill people or elderly living in our homes. In my case, I live with a person on an early stage of dementia. This means that some things that are not supposed to happen, happen. For example, this person cannot walk without wearing special shoes but sometimes forgets so, or maybe is not able to go to certain places and, without us noticing, there's no way to stop it. The worst case scenario (which has happened and that's mostly why I decided to create this) is when, at night, this person wakes up (without the special shoes) and falls down to the floor, making several injuries.

That said, here's the Arduino 101 way of caregiving! For the main unit, I'll be using the Arduino 101 connected to the app called Blynk over BLE. To do so, simply download blynk library at blynk.cc and the companion app for iOS or Android.

The components

This board has a Seedstudio Grove Base Shield on it, so it's easier to connect the components. Let's analyse them one by one:

  • Temperature Sensor -> It is quite important to know the temperature ins
  • ide the room this person will sleep, so here it is. It is connected to A3, and has no warnings programmed.
  • Sound Sensor -> For me this is the most important sensor. It is useful in almost any situation; if the person falls, screams, wakes up or any other thing, an alarm will be triggered (apart from the LCD turning red) so even if you are asleep a warning will wake you up. To disable the alarm simply touch the touch sensor or the button (whatever you decide to include)
  • Touch Sensor/Button -> It has two functionalities. First of all it tells you which temperature the room is using the LCD when pressed. Secondly, it stops the alarm when pressed.
  • RGB LCD -> This screen will provide general information about sensors, apart from a nice "everything is fine" message.
  • Servo -> In my case, we have automatic blinds triggered by a switch. In order for this to work the servo is normally at 90º position, and it turns to one side or the other in order to press the "up" switch or the "down" switch.
  • Buzzer -> This buzzer does an essential paper: warn you by sound.
  • WiFi device -> Even though Blynk app is awesome and it has many uses, you might want to extend the system. With the capabilities of MQTT protocol and a WiFi device (such as any ESP8266 board) you can send this data wherever you want like, for example, a Node-RED app, to trigger more alarms, a camera... Let me know what you create!

Blynk Widgets

The awesome Blynk app has some several widgets which interact with our boards and their sensors. Let's go, again, one by one:

  • Sound Graph -> Every 10 seconds, this bar-style graph updates, letting you motorize the sound history. The widget has some code linked to it, so when the Sound value exceeds 400 the alarm triggers.
  • Sound Labeled Value -> As the name says, this widget indicates the precise sound every 2 seconds. Like the first one, the alarm triggers when it exceeds 400.
  • Temperature Graph -> Taking values between 0 and 70 this line-style graph measures the temperature every 5 minutes. As it hasn't got any alarm connected to it, it's not necessary to check that often.
  • Temperature Labeled Value -> This widgets tells the exact value of the temperature, every 5 seconds.
  • Light Sensor -> It detects light levels and sens them to A0. It's matched with a piece of code that turns off LCD's backlight at night, for comfortable sleeping. However, it is not affected when alarm is triggered, then the screen will be as red as a screen can be.
  • The Blind Timer -> With a start hour of 22:00 and stop hour of 08:00, this timer is useful for the Blind's ups and downs. It works by sending 0 or 1 to virtual pin 1.
  • Last but not less important, the BLE connection widget -> It's essential if you want to communicate with the board.

Apart from these, there's enough room for some buttons and sliders, so be creative here! With MQTT, anything can be made.

Automatic Stuff

There are some automatic processes running on this system. The first one is the blind controller. Thanks to the Timer widget on Blynk we can set times for events to happen. For example, I've set that the Blinds go down at 22:00h and up at 08:00h. It is so cool.

Besides, when the light sensor detects no light, the RGB screen's light will disappear, making the room more confortable (the person I live with hates bright lights in the room while sleeping, like most of us I guess).

MQTT

For MQTT, we will use simple Serial Communication, wiring the Arduino's RX (D0) pin to WiFi device's TX, and WiFi device's RX to Arduino's TX (D1). The MQTT broker is completely up to the user, you can find some of them with a simple Google search. This is topic is large enough for a tutorial or a set of them, so I won't talk much about it. PubSubClient and this Adafruit tutorial look like a good starting point. Node-RED is also worth a view.

Conclusion

So, this is all guys! I hope you like the project as much as I do. Leave a comment with your opinion and share it over there! Any questions, of course, ask me right away.

Bye!

Code

Main codeArduino
Arduino 101 code for communication with the Blynk app.
//THINGS TO MODIFY FOR NORMAL USE


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Auth";
int SoundLimit = 400; //Set the limit of Sound to trigger the alarm

//NO MODIFICATION REQUEIRED FOR NORMAL USE

#include <Servo.h>
#include <rgb_lcd.h>
#include <Wire.h>
#include <math.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>

const int TouchPin = 4;     // Grove - Touch Sensor/Button connect to A3
const int pinAdc = A0;     // Grove - Sound Sensor connect to A3
const int pinTempSensor = A3;     // Grove - Temperature Sensor connect to A3
int buzzer = 6;     // Grove - Buzzer connect to 6

rgb_lcd lcd;  //Initialize Servo
Servo myservo; //Initialize Servo

int blind = 0; //Set blind variable

int clean = 0;

const int B = 4275;               // B value of the thermistor
const int R0 = 100000;            // R0 = 100k

BLEPeripheral  blePeripheral;

//Set colors for LCD
int colorR = 0;
int colorG = 255;
int colorB = 0;


void setup() {
  Serial.begin(9600);
  
  myservo.attach(3); //connect the Servo to pin 3

  blePeripheral.setLocalName("A101CG"); //Name your device!
  blePeripheral.setDeviceName("A101CG"); //Arduino 101 Care Giving
  blePeripheral.setAppearance(384);

  Blynk.begin(blePeripheral, auth);

  blePeripheral.begin();

  Serial.println("Waiting for connections...");

  lcd.begin(16, 2); //Start with a beautiful green color
  lcd.setRGB(colorR, colorG, colorB);
}


BLYNK_READ(V5) // Widget in the app READs Virtal Pin V5 with the certain frequency SOUND
{
  Blynk.virtualWrite(5, analogRead(pinAdc));
  if (analogRead(pinAdc) > SoundLimit) {
    alarm();
  }
}


BLYNK_READ(V2) // Widget in the app READs Virtal Pin V5 with the certain frequency SOUND
{
  Blynk.virtualWrite(2, analogRead(pinAdc));
  if (analogRead(pinAdc) > SoundLimit) {
    alarm();
  }
}


BLYNK_READ(V3) // Widget in the app READs Virtal Pin V5 with the certain frequency TEMPERATURE
{
  int a = analogRead(pinTempSensor );

  float R = 1023.0 / ((float)a) - 1.0;
  R = 100000.0 * R;

  float temperature = 1.0 / (log(R / 100000.0) / B + 1 / 298.15) - 273.15; //convert to temperature via datasheet ;
  Blynk.virtualWrite(3, temperature);
}


BLYNK_READ(V4) // Widget in the app READs Virtal Pin V4 with the certain frequency TEMPERATURE
{
  int a = analogRead(pinTempSensor );

  float R = 1023.0 / ((float)a) - 1.0;
  R = 100000.0 * R;

  float temperature = 1.0 / (log(R / 100000.0) / B + 1 / 298.15) - 273.15; //convert to temperature via datasheet ;
  Blynk.virtualWrite(4, temperature);
}


BLYNK_WRITE(V1) //Timer Widget is writing to pin V1  TIMER
{
  int pinData = param.asInt();
  if (pinData == 1 && blind == 1) {
    myservo.write(180);//Move servo to move blind down
    delay(15000);//Wait 15 secs until blind is down
    myservo.write(90);//Move servo to neutral position
    blind = 0;
    lcd.setRGB(0, 0, 0);
  }
  if (pinData == 0 && blind == 0) {
    myservo.write(0); //Move servo to move blind up
    delay(15000);//Wait 15 secs until blind is up
    myservo.write(90);//Move servo to neutral position
    blind = 1;
    lcd.setRGB(0, 255, 0);
  }
}


BLYNK_WRITE(V6) //Button Widget is writing to pin V6  LIGHT SENSOR
{
  int pinData = param.asInt();
  if (pinData < 100) { //If low light turn down
    colorR = 0;
    colorG = 0;
    colorB = 0;
  }
  else { //If normal light turn on green
    colorR = 0;
    colorG = 255;
    colorB = 0;
  }
}


void alarm() { //The Alarm
  while (true) {
    lcd.setRGB(255, 0, 0); //put the lcd in red
    delay(3000);
    lcd.clear();
    for (int i = 200; i < 1000; i++) {
      tone(buzzer, i); // Emit the noise
      delay(5);
    }
    delay(100); // A short break in between each whoop
    int sensorValue = digitalRead(TouchPin);
    if (sensorValue == 1) { //Stop alarm when touching
      break;
    }
  }
}


void loop() {

  Blynk.run();//run Main Blynk program
  blePeripheral.poll();


  int sensorValue = digitalRead(TouchPin); //When sensor touched, diplay temperature
  if (sensorValue == 1) {
    long sum = 0;
    if (clean == 0) {
      lcd.clear();
      clean = 1;
    }
    lcd.setCursor(0, 0);

    lcd.print("Temperature:");
    lcd.setCursor(0, 1);

    int a = analogRead(pinTempSensor );

    float R = 1023.0 / ((float)a) - 1.0;
    R = 100000.0 * R;

    float temperature = 1.0 / (log(R / 100000.0) / B + 1 / 298.15) - 273.15; //convert to temperature via datasheet ;
    lcd.print(temperature);
    delay(300);
  }

  else {
    lcd.setRGB(colorR, colorG, colorB);
    lcd.setCursor(0, 0);
    // Print a message to the LCD.
    lcd.print("All systems OK");
    lcd.setCursor(0, 1);
    lcd.print("Have a nice day");
    delay(20);
    clean = 0;
  }
}
MQTT CodeArduino
This code is based on an Adafruit Feather Huzzah ESP8266 board example, with a simple modification to publish over MQTT everything received with the Serial port.
// Based on code by Joël Gähwiler
// https://github.com/256dpi/arduino-mqtt


#include <ESP8266WiFi.h>
#include <MQTTClient.h>

const char *ssid = "ssid";
const char *pass = "pass";

WiFiClient net;
MQTTClient client;

unsigned long lastMillis = 0;

void connect(); // <- predefine connect() for setup()

void setup() {
  Serial.begin(9600);
  WiFi.begin(ssid, pass);
  client.begin("broker.shiftr.io", net);

  connect();
}

void connect() {
  Serial.print("checking wifi...");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }

  Serial.print("\nconnecting...");
  while (!client.connect("Arduino101CG", "try", "try")) {
    Serial.print(".");
    delay(1000);
  }

  Serial.println("\nconnected!");

  client.subscribe("/Arduino101CG");
  // client.unsubscribe("/Arduino101CG");
}

void loop() {
  client.loop();
  delay(10); // <- fixes some issues with WiFi stability

  if (!client.connected()) {
    connect();
  }






  

  if (Serial.available > 0) { //Publish on MQTT everything that comes through the Serial port
    client.publish("/Arduino101CG", Serial.read());
    delay(100);
  }
}






  

void messageReceived(String topic, String payload, char * bytes, unsigned int length) {
  Serial.print("incoming: ");
  Serial.print(topic);
  Serial.print(" - ");
  Serial.print(payload);
  Serial.println();
}

Schematics

Arduino 101 Way Of Caregiving
Grove system + WiFi Board
Arduino 101 cg bb azrubryqyj

Comments

Similar projects you might like

WIZnet S2E Deadbolts

Project tutorial by S2E Lock

  • 501 views
  • 2 comments
  • 4 respects

Super-Go: An Industrial IoT bot

Project tutorial by KS

  • 109 views
  • 2 comments
  • 0 respects

High Precision Scale with Arduino

Project showcase by mPelectronic

  • 551 views
  • 3 comments
  • 11 respects

GPS Tracking System for Vehicles

Project showcase by Sustainable Living Lab

  • 1,776 views
  • 0 comments
  • 7 respects

DIY Photogrammetry Turntable

Project showcase by alfiosky4

  • 3,381 views
  • 5 comments
  • 10 respects

Automatic Watering System

Project tutorial by Manson Hau

  • 5,004 views
  • 11 comments
  • 27 respects
Add projectSign up / Login