stevenAkhil Veeraghanta
Published © GPL3+

Black Bokz: Senior tracker

Provides real time information and gives the caretaker the ability to keep a better eye on their patient.

IntermediateShowcase (no instructions)244
Black Bokz: Senior tracker

Things used in this project

Hardware components

GPS receiver (generic)
×1
gsm antenna
×1
Jumper wires (generic)
Jumper wires (generic)
×5
enclosure
×1
heart rate monitor
×1

Hand tools and fabrication machines

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

Story

Read more

Code

BlackBoks: LinkitOne Code

Arduino
The code that allows the BlackBoks to be capable of performing its useful functions.
//tx - rx on lcd driver board
//rx - tx on lcd driver board
//digital pin to Leap Cruiser board
//digital pin to HeartRate sensor
//these are the only connections required

#include <LDateTime.h>
#include <LGSM.h>
#include <LGPS.h>
//creating all the required variables
String longitude;
datetimeInfo t;
unsigned int rtc;
String latitude;
String signalstrength;
String initlong;
String initlat;
String checker;
String googmap;
boolean set = true;
boolean firstbeat = false;
boolean secondbeat = false;
boolean thirdbeat = false;
int time1;
int time2;
int time3;
String phonenumber = "6044466280";
String allowedradius;
boolean leftallowedradius = true;
boolean alreadyinformed = false;
String heartrate = "";
gpsSentenceInfoStruct info;
char str[32];
void setup() {
  //Begining serial communication between computer and the arduino
  Serial.begin(115200);
  Serial1.begin(9600);
  Serial.println("attempting to connect sim card");
  while (!LSMS.ready())
  {
    delay(1000);
  }
  Serial.println("Sim initialized");
  LGPS.powerOn();
  Serial.println("LGPS Power on");
  //get the inital
  delay(3000);
  pinMode(2, OUTPUT);
  LSMS.beginSMS("6044466280");
  LSMS.print("BlackBoks established");
  LSMS.println("Waiting for allowed radius, please input a distance in meters");
  Serial.println("sending");
  Serial.println(LSMS.endSMS());
  while (LSMS.available() == false) {
    delay(100);
  }
  String rec = "";
  int k = 0;
  Serial.println("in setup");
  Serial.println("recieved distance text message");
  k = LSMS.read();
  while (k > 0) {
    rec += String((char)k);
    delay(10);
    k = LSMS.read();
  }
  allowedradius = rec;
  delay(1000);
  LSMS.flush();
  delay(1000);
  Serial.println("Distance recieved");
  LSMS.beginSMS("6044466280");
  LSMS.print("Distance of " + allowedradius + " has been allowed as a HomeZone radius by the BlackBoks");
  LSMS.println();
  LSMS.println("OPTIONS");
  LSMS.println("1. Text Location to recieve the location of the BlackBoks");
  LSMS.println("2. Text Viatls to get important information like heart rate");
  LSMS.println("3. Text Reminder to send a custom message to the LCD display");
  LSMS.println("4. Text Stop to stop the wheelchair");
  LSMS.println("5. Text Release to allow user to regain control");
 
  Serial.println("sending");
  Serial.println(LSMS.endSMS());
  pinMode(3, OUTPUT);
}

//converts DMS latitude into decimal for google maps input
void getLatitudeLongitudeforGOOGLEMAPS() {
  LGPS.getData(&info);
  char* information = (char*) info.GPGGA;
  char *tokens;
  Serial.println(information);
  tokens = strtok(information, ",");
  tokens = strtok(NULL, ",");
  tokens = strtok(NULL, ",");
  latitude = tokens;
  tokens = strtok(NULL, ",");
  checker = tokens;
  if (checker.equals("W") || checker.equals("S")) {
    latitude = "-" + latitude;
  }
  if (checker.equals("N") || checker.equals("E")) {
    latitude = "+" + latitude;
  }
  tokens = strtok(NULL, ",");
  longitude = tokens;
  tokens = strtok(NULL, ",");
  checker = tokens;
  if (checker.equals("W") || checker.equals("S")) {
    longitude = "-" + longitude;
  }
  if (checker.equals("N") || checker.equals("E")) {
    longitude = "+" + longitude;
  }
  Serial.println("------------");
  Serial.println(longitude);
  Serial.println(latitude);
  Serial.println("------------");
  
  //doing the calculation after recieving the necessary bits from the strtok method.
  String lon = longitude.substring(0, 1) + String((double(longitude.substring(1, 4).toFloat()) + (longitude.substring(4, 6).toFloat() / 60) + (longitude.substring(7, 9).toFloat() / 3600) + (longitude.substring(9).toFloat() / 216000)), 6);
  Serial.println(lon);
  String lat = latitude.substring(0, 1) + String((double(latitude.substring(1, 3).toFloat()) + (latitude.substring(3, 5).toFloat() / 60) + (latitude.substring(6, 8).toFloat() / 3600) + (latitude.substring(8).toFloat() / 216000)), 6);
  Serial.println(lat);
  googmap = lat + "," + lon;
  Serial.println(googmap);
}

String processtextmessage() {
  String rec = "";
  int k = 0;
  if (LSMS.available()) {
    Serial.println("in main loop");
    Serial.println("recieved text message");
    k = LSMS.read();
    while (k > 0) {
      rec += String((char)k);
      delay(10);
      k = LSMS.read();
    }
    return (rec);
  }
}
//sends text message to the previously set phone number
void sendtextmessage(String msg) {
  LSMS.beginSMS(phonenumber);
  LSMS.print(msg);
  Serial.println("Sending text (1 if succeded 0 if failedded)");
  Serial.println(LSMS.endSMS());
}

//gets the intial location of the BlackBoks

void setinitallocation(){
getLatitudeLongitudeforGOOGLEMAPS();
initlat = latitude;
initlong = longitude;
set = true;
}

//using the haversine formula to calculate distance from longitude to latitude
float calcdistance(String latitude, String longitude, String initlat, String initlong){
double dlon = (double)longitude.toFloat() - (double)initlong.toFloat();
double dlat = (double)latitude.toFloat() - (double)initlat.toFloat(); 
double lat1 = (double)initlat.toFloat();
double lat2 = (double)latitude.toFloat();
double va;
va = (pow((sin(dlat/2)),2.0) + cos(lat1) *cos(lat2) * pow((sin(dlon/2)),2.0)) ;
double vc = 2 * atan2( sqrt(va), sqrt(1-va) ) ;
float distance = 6371 * vc;
return(distance); //gives the distance between the latitude and longitude points
}

void loop() {
  if (set = false){
  setinitallocation();
  }
  

  //the heart rate calculation
  if (digitalRead(3) == 1)
  {
    LDateTime.getTime(&t);
    time1 = t.sec;
    Serial.println("Time 1    " + String(time1));
  }
  while (digitalRead(3) == 1) {
    delay(10);
  }

if (digitalRead(3) == 1) {
  LDateTime.getTime(&t);
  time3 = t.sec;
  Serial.println("Time 3    " + String(time3));
}    

int timeinterval1 = time3 - time1;
String heartrate = String(60 / timeinterval1);
getLatitudeLongitudeforGOOGLEMAPS();

if (calcdistance(latitude,longitude,initlat,initlong) > allowedradius.toFloat()){
 sendtextmessage("The BlackBokz has left the safezone");
}
if (LSMS.available()) {
  //if a text message has been recieved, then process it into a string
  String rec =  processtextmessage();
  if (rec.equals("Location")) {
    Serial.println("Entering Location");
    getLatitudeLongitudeforGOOGLEMAPS();
    
    //this link allows the caretaker to see exact location on google maps
    sendtextmessage("Request for LeapCruiser Location: https://www.google.ca/maps/place/" + googmap + "//@" + googmap + ",17z");
  }
  if (rec.equals("Vitals")) {
    sendtextmessage("Heart rate");
  }
  if (rec.equals("check")) {
    sendtextmessage("Heart rate");
  }


  if (rec.equals("Stop")) {
    digitalWrite(2, HIGH);
  }
  if (rec.equals("Release")) {
    digitalWrite(2, LOW);
  }
  if (rec.equals("Reminder")) {
    sendtextmessage("Please input the 16 character message to be displayed");
    LSMS.flush();
    while ( LSMS.available() == false) {
      delay(100);
    }
    
    //update lcd screen with message sent by caretaker
    processtextmessage().toCharArray(str, 17);
    Serial1.write(str);
  }
}
LSMS.flush();
}

Arduino Driver Code

Arduino
It is loaded onto the Arduino that will be controlling the LCD.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27  
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
int input = 1;
char str[32];
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
String j = "BlackBokz Beta0.1";
void setup(){
  Serial.begin(9600);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);lcd.begin (16,2);
  lcd.setCursor(0,0) ;
  lcd.println(j);
  }
  void loop(){
    int i=0;

  if (Serial.available()) {
    delay(100); //allows all serial sent to be received together
    while(Serial.available()) {
      j = Serial.readString();
      //reads the string recieved and then puts it into the lcd
    }
      //if the leap cruiser isnt plugged in you can run this code with the time you want to display the message 
      //delay(10000);
    lcd.clear();
    lcd.println(j);
  }
  
  //the message will not change unless the Leap Cruiser wheelchair is also plugged in which allows for an overide clearing the lcd. 
  


  }
      

Credits

steven

steven

3 projects • 8 followers
Akhil Veeraghanta

Akhil Veeraghanta

2 projects • 15 followers
Your average hackster

Comments