Things used in this project

Hardware components:
Ardgen mega
Arduino Mega 2560 & Genuino Mega 2560
×1
NEO 6 GPS
×1
Adafruit SD Card Shield
×1
Adafruit SD Card Shield
×1
Seeedstudio gprs shield V2.0
×1
SeeedStudio GPRS Shield V2.0
×1
11026 02
Jumper wires (generic)
×1
Tens70
9V battery (generic)
×1
Box
×1
Box
×1

Schematics

Basic connection circuit
Sch
Electronic schematic
Sch

Code

CodeArduino
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include "call.h"

#include <TinyGPS++.h>

//To change pins for Software/Hardware Serial, use 27, 28 lines in GSM.cpp.
//To use Arduino Mega please define MEGA in line 5 in GSM.h.

#include <SPI.h>
#include <SD.h>

//Mega CS pin
const int chipSelect = 53;


//We have to create the classes for SMSs and calls.
CallGSM call;
SMSGSM sms;

char number[20];
byte stat = 0;
int value = 0;

char value_str[5];

//GPS Variable

// The TinyGPS++ object
TinyGPSPlus gps;

const char *googlePrefix = "http://maps.google.com/maps?q=";


double Lat;
double Long;
int day, month, year;
int hour, minute, second;

int num_sat;

boolean one_point_true = false;



void setup()
{

  //Serial connection.
  Serial.begin(9600); 
  
  //GPRS connection
  Serial.print(F("Starting GSM..."));
  //Start configuration of shield with baudrate.
  if (gsm.begin(9600))
    Serial.println(F("READY"));
  else Serial.println(F("IDLE"));

  //GPS connection 
  Serial.println(F("Starting GPS"));
  //GPS com port
  Serial2.begin(9600);

  //SD Card start
  Serial.print(F("Initializing SD card..."));
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(53, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println(F("Card failed, or not present"));
    // don't do anything more:
    return;
  }
  Serial.println(F("card initialized."));

}


//******************************************************************************
//Main loop
void loop()
{

  Get_GPS(); // Get the position

  Check_call(); //See if anyone is calling


};

////////////////////////////////////////////////////////////////////////////////


//******************************************************************************
// Get the position from the GPS
void Get_GPS()
{

  while (Serial2.available() > 0)
    if (gps.encode(Serial2.read()))

      num_sat = gps.satellites.value();
  //Serial.println(num_sat);

  if (gps.location.isValid() == 1) {

    Lat = gps.location.lat();
    Long = gps.location.lng();

    if (Lat != 0 && Long != 0) one_point_true = true;

  }




  if (gps.date.isValid())
  {
    day = gps.date.day();
    month = gps.date.month();
    year = gps.date.year();
  }

  if (gps.time.isValid())
  {

    hour = gps.time.hour();
    minute = gps.time.minute();
    second = gps.time.second();
  }

  smartDelay(500);


  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while (true);
  }


}


//******************************************************************************
// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (Serial2.available())
      gps.encode(Serial2.read());
  }
  while (millis() - start < ms);
}
//////////////////////////////////////////////////////////////////////////////// 

//******************************************************************************
// Check to see if anyone is calling
void Check_call()
{
  //Checks status of call
  stat = call.CallStatusWithAuth(number, 0, 0);

  //If the any incoming call
  if (stat == CALL_INCOM_VOICE_AUTH) {
    delay(100);
    //Hang up the call.
    call.HangUp(); //Reject the call

    Send_SMS();

  }
}
////////////////////////////////////////////////////////////////////////////////


//******************************************************************************
// Send an SMS with the current position or the last known position
void Send_SMS()
{


  int error;

  char Date[13];
  sprintf(Date, "%02d/%02d/%04d ", day, month, year);

  char time1[10];
  sprintf(time1, "%02d:%02d:%02d ", hour, minute, second);

  //Serial print GPS data
  /*
   Serial.print(Date);
  Serial.print("  ");
  Serial.print(time1);
  Serial.print("  ");
  Serial.print("Lat: ");
  Serial.print(Lat, 6);
  Serial.print("  ");
  Serial.print("Long: ");
  Serial.println(Long, 6);
  */

  delay(100);

  char lat_print[10];
  dtostrf(Lat, 5, 6, lat_print);

  char Long_print[10];
  dtostrf(Long, 5, 6, Long_print);


  if (num_sat >= 3 && one_point_true == true)
  {
    char sms_OK[160];
    sprintf(sms_OK, "Hugo location is now: Lat: %s, Log: %s. %s%s,+%s\n", lat_print, Long_print, googlePrefix, lat_print, Long_print);
    Serial.println(sms_OK);

    error = sms.SendSMS(number, sms_OK);
    delay(500);
    if (error == 0) //Check status
    {
      Serial.println(F("SMS ERROR"));
    }
    else
    {
      Serial.println(F("SMS OK"));
    }

  }

  else if (num_sat < 3 && one_point_true == true)
  {

    char sms_NOK[150];
    sprintf(sms_NOK, "I can not seen to find Hugo. Last time that i've saw him, was in: Lat: %s, Log: %s. %s%s,+%s\n", lat_print, Long_print, googlePrefix, lat_print, Long_print);
    Serial.println(sms_NOK);

    int error = sms.SendSMS(number, sms_NOK);
    if (error == 0) //Check status
    {
      Serial.println(F("SMS ERROR"));
    }
    else
    {
      Serial.println(F("SMS OK"));
    }

  }

  else if (one_point_true == false)
  {
    Serial.println(F("No valid GPS point"));

  }

//Save everything in the SD Card
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {


    dataFile.print(Date);
    dataFile.print(" ");
    dataFile.print(time1);
    dataFile.print(" ");
    dataFile.print(number);
    dataFile.print(" ");
    dataFile.print(lat_print);
    dataFile.print(", ");
    dataFile.print(Long_print);
    dataFile.print(" ");
    dataFile.print(error);
    dataFile.println();

    dataFile.close();

  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println(F("error opening datalog.txt"));
  }

}
////////////////////////////////////////////////////////////////////////////////

Credits

Me
Hugo Gomes

http://www.hugogome.net

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Arduino Like Function on Kinetis K82 Freedom Stupid Board
Intermediate
  • 76
  • 4

Protip

1000 of K82 Freedom Boards are collecting dust because of the hobbyist unfriendly IDE, pump up the duds with easy Arduino-like functions.

Reducing Arduino Power Consumption
Intermediate
  • 162
  • 5

Full instructions

One the most important feature of portable electronics should be long battery life. We can reduce the current drawn by several ways.

DIY Patient Thermometer for Healthcare Training
Intermediate
  • 66
  • 2

Work in progress

DIY thermometer, IR remote controlled. 9 different temperatures. For use in healthcare simulation training. Cost-effective solution.

Arduinomated Car Parking with Voice Assistance in Smartphone
Intermediate
  • 593
  • 11

Full instructions

Make an assistant which tells you about how much to drive backwards without any collision through your smartphone by Arduino and 1Sheeld.

Raspberry Pi Motion Tracking Gun Turret
Intermediate
  • 7,226
  • 16

Full instructions

A motion tracking airsoft or Nerf gun turret with autonomous and manual operation modes, controlled by a Raspberry Pi.

Temperature and humidity meter (iot)
Intermediate
  • 11
  • 1

Measuring temperature and humidity with Arduino and uploading it to the server

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog