Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
DIY Projects Lab
Published © CC BY-NC-SA

Women Safety Device with GPS Tracking

Here we will build a band that can be worn by women, using which they can inform police or anyone, using SOS emergency SMS along with the cu

IntermediateFull instructions provided3 hours19,419
Women Safety Device with GPS Tracking

Things used in this project

Story

Read more

Schematics

Schematics

Code

Code

Arduino
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
static const int RXPin = 2, TXPin = 3;
static const uint32_t GPSBaud = 9600;
int  m = 9740;
int y = 71;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin); 
SoftwareSerial SIM900(7, 8);
int Buzzer = 4; 
String textForSMS;
int Switch = 5; 

String datareal;
String dataimaginary;
String combined;
int raw = 1000000;

String datareal2;
String dataimaginary2;
String combined2;

double longitude;
double latitude;

void setup()
{
  SIM900.begin(19200);
  Serial.begin(9600);
  ss.begin(GPSBaud);
  delay(10000); 
  Serial.println(" logging time completed!");
  randomSeed(analogRead(0));
  pinMode(Switch, INPUT);
  digitalWrite(Switch, HIGH);
  pinMode(Buzzer, OUTPUT);
  digitalWrite(Buzzer, LOW);

  Serial.println(F("DeviceExample.ino"));
  Serial.print(F("Testing TinyGPS++ library v. "));
  Serial.println(TinyGPSPlus::libraryVersion());

  Serial.println();
}



void sendSMS(String message)
{
  SIM900.print("AT+CMGF=1\r");                     
  delay(100);
  SIM900.println("AT + CMGS = \"+918830584864\"");  
  delay(100);
  SIM900.println(message);                         
  delay(100);
  SIM900.println((char)26);                        
  delay(100);
  SIM900.println();
  delay(5000);                                     

}

void loop()
{
  int reading;
  
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while (true);
  }
  
  if (digitalRead(Switch) == LOW)
  {
    displayInfo();
    latitude = gps.location.lat(), 6 ;
    longitude = gps.location.lng(), 6 ;
    long datareal = int(latitude);
    int fahad = ( latitude - datareal) * 100000;
    long datareal2 = int(longitude);
    int fahad2 = (longitude - datareal2 ) * 100000;
    textForSMS.concat(fahad);
    //textForSMS = "Longitude:  ";
    textForSMS.concat(datareal2);
    textForSMS = textForSMS + ".";
    textForSMS.concat(fahad2);
    //textForSMS = textForSMS + " Latitude: ";
    textForSMS.concat(datareal);
    textForSMS = textForSMS + ".";
    sendSMS(textForSMS);
    Serial.println(textForSMS);
    Serial.println("message sent.");
    delay(5000);
  }
  else
    digitalWrite(Switch, HIGH);
  digitalWrite(Buzzer, LOW);
}


void displayInfo()
{
  Serial.print(F("Location: "));
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
    Serial.print(" ");
    Serial.print(F("Speed:"));
    Serial.print(gps.speed.kmph());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.println();
}

Credits

DIY Projects Lab

DIY Projects Lab

41 projects • 157 followers
I am a DIY hobbyist by passion and an Electronics Engineer by profession. Sponsor (PCB Manufacturer) - www.nextpcb.com

Comments