Components needed:
1. ATmega328
2. Sim300 gsm module
3. GY-GPS6MV2 gps module
4. Android smartphone
5. lcd 16x2
6. back_up battery
1. ATmega328
2. Sim300 gsm module
3. GY-GPS6MV2 gps module
4. Android smartphone
5. lcd 16x2
6. back_up battery
Here in this system we are using the GSM module for sending the
coordinates of vehicle on mobile phone via message. GPS is sends the
coordinates continuously in form of string. After reading this string
using Arduino extract the required data from string and then sends it to
mobile phone using GSM module via SMS. This information is called
latitude and longitude. GPS used 3 or 4 satellite for tracking the
location of any vehicle.
Circuit diagram
Car tracker controller with Atmega328
Gsm testing
Gps module testing
Command testing
// here is the code...........
//......................................................................
#include<LiquidCrystal.h>
LiquidCrystal lcd(8,9,10,11,12,13);#include <SoftwareSerial.h>
SoftwareSerial gps(7,6); // RX, TX
char c=0;
//String str="";
char str[70];
String gpsString="";
char *test="$GPGGA";
String latitude="No Range ";
String longitude="No Range ";
int temp=0,i;
boolean gps_status=0;
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
gps.begin(9600);
lcd.print("Vehicle_Tracking");
lcd.setCursor(0,1);
lcd.print(" System ");
delay(4000);
gsm_init();
lcd.clear();
Serial.println("AT+CMGF=1");
lcd.print("Pls Wait......");
lcd.setCursor(0,1);
lcd.print("SW TO SMS MODE");
delay(2500);
lcd.clear();
lcd.print("GPS Initializing");
lcd.setCursor(0,1);
lcd.print(" No GPS Range ");
get_gps();
delay(2500);
lcd.clear();
lcd.print("GPS Range Found");
lcd.setCursor(0,1);
lcd.print("GPS is Ready");
delay(2500);
lcd.clear();
lcd.print("System Ready");
lcd.setCursor(0,1);
lcd.print("Vehicle secured");
Serial.println("AT+CMGD=1"); // DELETE READ1
delay(3000);
digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level)
delay(10); // wait for a second
digitalWrite(3, LOW);
delay(10);
}
void loop()
{
lcd.setCursor(0,1);
lcd.print("waiting 4 command");
Serial.println("AT+CMGR=1");
while (Serial.available()) {
if (Serial.find("TRACK VEHICLE")) {
digitalWrite(2, HIGH);
get_gps();
Serial.println("AT+CMGD=1"); // DELETE READ1
tracking();
}
if (Serial.find("OFF ALARM")) {
digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level)
delay(10);
digitalWrite(3, LOW);
delay(10);
Serial.println("AT+CMGD=1"); // DELETE READ1
tracking();
}
}
}
void gpsEvent()
{
gpsString="";
while(1)
{
while (gps.available()>0) //checking serial data from GPS
{
char inChar = (char)gps.read();
gpsString+= inChar; //store data from GPS into gpsString
i++;
if (i < 7)
{
if(gpsString[i-1] != test[i-1]) //checking for $GPGGA sentence
{
i=0;
gpsString="";
}
}
if(inChar=='\r')
{
if(i>65)
{
gps_status=1;
break;
}
else
{
i=0;
}
}
}
if(gps_status)
break;
}
}
void gsm_init()
{
lcd.clear();
lcd.print("Finding Module..");
boolean at_flag=1;
while(at_flag)
{
Serial.println("AT");
while(Serial.available()>0)
{
if(Serial.find("OK"))
at_flag=0;
}
delay(1000);
}
lcd.clear();
lcd.print("Module Connected..");
delay(1000);
lcd.clear();
lcd.print("Disabling ECHO");
boolean echo_flag=1;
while(echo_flag)
{
Serial.println("ATE0");
while(Serial.available()>0)
{
if(Serial.find("OK"))
echo_flag=0;
}
delay(1000);
}
lcd.clear();
lcd.print("Echo OFF");
delay(1000);
lcd.clear();
lcd.print("Finding Network..");
boolean net_flag=1;
while(net_flag)
{
Serial.println("AT+CPIN?");
while(Serial.available()>0)
{
if(Serial.find("+CPIN: READY"))
net_flag=0;
}
delay(1000);
}
lcd.clear();
lcd.print("Network Found..");
delay(1000);
lcd.clear();
}
void get_gps()
{
gps_status=0;
int x=0;
while(gps_status==0)
{
gpsEvent();
int str_lenth=i;
latitude="";
longitude="";
int comma=0;
while(x<str_lenth)
{
if(gpsString[x]==',')
comma++;
if(comma==2) //extract latitude from string
latitude+=gpsString[x+1];
else if(comma==4) //extract longitude from string
longitude+=gpsString[x+1];
x++;
}
int l1=latitude.length();
latitude[l1-1]=' ';
l1=longitude.length();
longitude[l1-1]=' ';
lcd.clear();
lcd.print("Lat:");
lcd.print(latitude);
lcd.setCursor(0,1);
lcd.print("Long:");
lcd.print(longitude);
i=0;x=0;
str_lenth=0;
delay(2000);
}
}
void init_sms()
{
Serial.write("AT+CMGF=1\r\n");
delay(1000);
Serial.write("AT+CMGS=\"+2347037557572\"\r\n"); // use your 10 digit cell no. here
delay(1000);
}
void send_data(String message)
{
Serial.println(message);
delay(200);
}
void send_sms()
{
Serial.write((char)26);
}
void lcd_status()
{
lcd.clear();
lcd.print("Message Sent");
delay(2000);
lcd.clear();
lcd.print("System Ready");
return;
}
void tracking()
{
digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(10); // wait for a second
digitalWrite(2, LOW);
init_sms();
send_data("Vehicle Tracking Alert:");
send_data("Your Vehicle Current Location is:");
Serial.print("Latitude:");
send_data(latitude);
Serial.print("Longitude:");
send_data(longitude);
send_data("Please take some action soon..\nThankyou");
send_sms();
delay(2000);
lcd_status();
Serial.println("AT+CMGD=1"); // DELETE READ1
}
// ending
If you have any question, feel free to comment on this post.... acecct.18f4550@gmail.com OR whatsapp me on : +2348123206299
Watch Youtube Video: