Miles Nash
Published © CC BY-NC-SA

Electronic Lifeguard Arm Band

An actively sensing IOT arm band that will send an sms message for help if struggle is detected to prevent drowning.

IntermediateFull instructions provided1.5 hours1,497
Electronic Lifeguard Arm Band

Things used in this project

Hardware components

Adafruit Feather HUZZAH with ESP8266 WiFi
Adafruit Feather HUZZAH with ESP8266 WiFi
×1
SparkFun 9 Degrees of Freedom IMU Breakout - LSM9DS1
SparkFun 9 Degrees of Freedom IMU Breakout - LSM9DS1
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
usb battery
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1
velcro strap
×1

Software apps and online services

Maker service
IFTTT Maker service
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Diagram

Diagram of electronics wiring, the spark fun sensor is shown as the wrong sensor because no model of the real sensor existed

Code

Arduino Code

Arduino
Paste into the Arduino IDE, infill User Values, and upload to esp8266 HUZZAH
#include <Wire.h>
#include <SPI.h>
#include <SparkFunLSM9DS1.h>
#include <ESP8266WiFi.h>

LSM9DS1 imu; //creat instance of class

#define LSM9DS1_M  0x1E //I2C
#define LSM9DS1_AG  0x6B 

float g = 0; //total number of gsin acceleration over all axes
float g1,g2,g3,g4,g5,g6,g7,g8,g9,g10;
float lastTen = 0;
const char* host = "maker.ifttt.com";
int ledPin = 14;

///////////////////////////////////////////////////////////////////
//User Info
///////////////////////////////////////////////////////////////////
const char* ssid     = "----------";            //your SSID(name) of WIFI
const char* password = "----------";       // password of Wifi
const char* apiKey = "---------------------"; //copy the api key as described in the tutorial
const char* triggerName = "hazard_detected";  //trigger name you entered in ifttt setup

//ifttt allows only 100 texts per month, to limit use the following can be employed

bool conserveSms = true; //if true, only one text will be sent per incedent
int hazardDelay = 100; //time between texts sent in seconds, ignore if conserveSms is false

///////////////////////////////////////////////////////////////////
int lastHazard = -1000 * hazardDelay;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);
    imu.settings.device.commInterface = IMU_MODE_I2C;
  imu.settings.device.mAddress = LSM9DS1_M;
  imu.settings.device.agAddress = LSM9DS1_AG;
  // The above lines will only take effect AFTER calling
  // imu.begin(), which verifies communication with the IMU
  // and turns it on.
  if (!imu.begin())
  {
    Serial.println("Failed to communicate with LSM9DS1.");
    Serial.println("Double-check wiring.");
    Serial.println("Default settings in this sketch will " \
                  "work for an out of the box LSM9DS1 " \
                  "Breakout, but may need to be modified " \
                  "if the board jumpers are.");
    while (1)
      ;
  }

  //Wifi Setup
      WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}

void loop() {

  


    imu.readAccel();
    delay(500);
    g = abs(imu.calcAccel(imu.ax)) + abs(imu.calcAccel(imu.ay)) + abs(imu.calcAccel(imu.az)) - 1;
    Serial.println(g);
   Serial.println(lastTen);
    Serial.println();
 /* Serial.print(imu.calcAccel(imu.ax), 2);
  Serial.print(", ");
  Serial.print(imu.calcAccel(imu.ay), 2);
  Serial.print(", ");
  Serial.print(imu.calcAccel(imu.az), 2);
  Serial.println(" g");
    */
    g10 = g9;
    g9 = g8;
    g8 = g7;
    g7 = g6;
    g6 = g5;
    g5 = g4;
    g4 = g3;
    g3 = g2;
    g2 = g1;
    g1 = g;
    lastTen = g1 + g2 + g3 + g4 +g5 + g6 + g7 + g8 + g9 + g10;
  

  if (lastTen >= 10){
    if (conserveSms && ((millis() - lastHazard) >= (hazardDelay*1000))){
      sendForHelp();
      lastHazard = millis();
    }else if (conserveSms == false){
      sendForHelp();
    }
  }
}

void sendForHelp() {
  Serial.print("Connecting to ");
  Serial.println(host);

  WiFiClient client;
  const int httpPort = 80; ESP8266

  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  Serial.print("Sending for Help");
  client.print(String("POST ") + "/trigger/" + triggerName + "/with/key/" + apiKey + " HTTP/1.1\r\n" +
              "Host: " + host + "\r\n" +
              "Connection: close\r\n\r\n"); 
  digitalWrite(ledPin, HIGH);
}

Credits

Miles Nash

Miles Nash

7 projects • 28 followers
I'm a UC Berkeley EECS student with a passion for innovation and creating new things.

Comments