Aitor Gamarra
Published © CC BY

The Arduino101 way of Caregiving!

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

IntermediateFull instructions provided3 hours3,793
The Arduino101 way of Caregiving!

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
Seeed Studio Grove Starter Kit for Arduino 101
×1
Servos (Tower Pro MG996R)
A servo
×1
Seeed Studio SeeedStudio Grove - Button
×1
Seeed Studio SeeedStudio Grove - Touch Sensor
×1
Seeed Studio SeeedStudio Grove - Temperature Sensor
×1
Seeed Studio SeeedStudio Grove - RGB LCD
×1
Seeed Studio SeeedStudio Grove - Buzzer
×1
Seeed Studio SeeedStudio Grove - Sound Sensor
×1
Adafruit Feather HUZZAH with ESP8266 WiFi
Adafruit Feather HUZZAH with ESP8266 WiFi
Optional (for MQTT stuff)
×1
Android device
Android device
OPTIONAL - must choose one device
×1
iPhone
Apple iPhone
OPTIONAL - must choose one device
×1
iPad
Apple iPad
OPTIONAL - must choose one device
×1

Software apps and online services

Blynk
Blynk
Node-RED
Node-RED
Optional

Story

Read more

Schematics

Arduino 101 Way Of Caregiving

Grove system + WiFi Board

Code

Main code

Arduino
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 Code

Arduino
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();
}

Credits

Aitor Gamarra

Aitor Gamarra

2 projects • 3 followers

Comments