Shahariar
Published © CC BY-SA

Swim'Safe: An Underwater Drown Detection Beacon

A wearable solution to detect if a disabled person got drowned and try to draw the attention of Lifeguards for help !!

BeginnerFull instructions provided4 hours436

Things used in this project

Hardware components

Beetle - The Smallest Arduino
DFRobot Beetle - The Smallest Arduino
×1
Grove - OLED Display 1.12'' V2
Seeed Studio Grove - OLED Display 1.12'' V2
×1
Infineon DSP368 Pressure Sensor
×1
Battery, 3.7 V
Battery, 3.7 V
×1
Dot Laser Diode
×8
Dead Smart Watch or 3D Printed Enclosure
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Schematic Drown Detector Prototype

Code

Drown Detector

C/C++
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <Dps3xx.h>

#define USER_BUTTON A0

// Dps3xx Object
Dps3xx Dps3xxPressureSensor = Dps3xx();
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17);   // ESP32 Thing, HW I2C with pin remapping

uint8_t button_state = 0;
uint8_t exit_timer = 0;
float drown_depth = 0.0;

void setup()
{
  Wire.begin();
  u8g2.begin();
  Dps3xxPressureSensor.begin(Wire);

  pinMode (A2, OUTPUT);
  digitalWrite(A2, LOW);
  pinMode (USER_BUTTON, INPUT_PULLUP);


  // blinky check for device functionality

  for (int i = 0; i < 4; i++)
  {
    digitalWrite(A2, HIGH);
    delay(200);
    digitalWrite(A2, LOW);
    delay(200);
  }


}

void loop()
{
  float temperature;
  float air_pressure;
  float underwater_pressure;
  uint8_t oversampling = 7;
  int16_t ret;

  ret = Dps3xxPressureSensor.measurePressureOnce(air_pressure, oversampling);
  ret = Dps3xxPressureSensor.measurePressureOnce(air_pressure, oversampling);

  // Scroll through setup menu

  while (button_state == 0)
  {
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB10_tr);
    u8g2.setCursor(25, 15);
    u8g2.print("Press Button");
    u8g2.setCursor(25, 30);
    u8g2.print("To Calibrate");
    u8g2.setCursor(30, 55);
    u8g2.print(air_pressure);
    u8g2.sendBuffer();
    read_button();
    delay(100);

  }

  while (button_state >= 1 && exit_timer < 50)
  {
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB10_tr);
    u8g2.setCursor(25, 15);
    u8g2.print("Set Depth of");
    u8g2.setCursor(25, 30);
    u8g2.print("Drown Detect");
    u8g2.setCursor(25, 55);
    drown_depth = 0.1 * button_state;
    u8g2.print(drown_depth);
    u8g2.setCursor(55, 55);
    u8g2.print("at meters");
    u8g2.sendBuffer();
    read_button();
    exit_timer++;
    delay(100);

  }

  while (digitalRead(USER_BUTTON))
  {
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB10_tr);
    u8g2.setCursor(25, 15);
    u8g2.print("Drown Detect");
    u8g2.setCursor(25, 30);
    u8g2.print("  is Active !!!");
    u8g2.setCursor(25, 55);
    u8g2.print(" Swim Safely ");
    u8g2.sendBuffer();
    ret = Dps3xxPressureSensor.measurePressureOnce(underwater_pressure, oversampling);
    digitalWrite(A2, LOW);


    // if water presure increase from drowning
    // 1m water column pressure = 10000 Pa
    while (underwater_pressure > (air_pressure + drown_depth * 10000))
    {
      u8g2.clearBuffer();
      u8g2.setFont(u8g2_font_ncenB10_tr);
      u8g2.setCursor(25, 15);
      u8g2.print(" Drowning  !!");
      u8g2.setCursor(25, 30);
      u8g2.print("Please Help !");
      u8g2.setCursor(25, 55);
      u8g2.print("Beacon Active");
      u8g2.sendBuffer();
      ret = Dps3xxPressureSensor.measurePressureOnce(underwater_pressure, oversampling);
      digitalWrite(A2, HIGH);
      delay(100);
    }
  }
  button_state = 0;
}



void read_button (void)
{
  if (!digitalRead(USER_BUTTON))
  {
    button_state ++;
  }

}

Credits

Shahariar

Shahariar

74 projects β€’ 265 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments