Sunday, 8 February 2015

GSM AND GPS TRACKER USING SIM908 WITH GOOGLE MAP

After working for some days on this project then i decided to write an article on how to build  a GSM and GPS car tracker with Google map link. i which i will be able to touch many Engineer lives after going through this article.

Nowadays that the population of cars has increased people will find it very difficult to locate a stolen car easily, then i decided to work on a car tracking device.

Before going to the construction of the device i assume that you have gotten yourself acquainted with PIC microcontroller made  by microchip Technology. The controller i used is the PIC18F2550 with the SIM908 MODULE which contain GSM and GPS AT commands.

The project is designed in a way that when message "LOCATION" is sent to the Sim module number(note that you can insert any sim card network into the SIM908 module) then the device display "Incoming ,Message" on lcd screen to notify that message Received, it microcontroller then send AT commands to read GPS coordinates from the SIM908, when all coordinate location are received then the microcontroller send AT commands to send message which consist of the Google link with LATITUDE AND LONGITUDE cordinates in degrees and minutes.


The components used:

1.  sim908 
2.  PIC18F2550
3.  LCD 16X2
4. 7805
5.  max232


the program is written in mikroC compiler 


#define D4  PORTB.B3
#define D5  PORTB.B2
#define D6  PORTB.B1
#define D7  PORTB.B0
#define EN  PORTB.B4
#define RS  PORTB.B6

#define xtal 12000000
#include <Pulsetronics_LCD.h>
#include <GPS.h>

// LCD module connections
sbit LCD_RS at RB6_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;


sbit LCD_RS_Direction at TRISB6_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;
// End LCD module connections

              unsigned char mont,chk,chk2,loc,loc1,kep;
              unsigned char stor[10],lat[12],lon[12],lat1[4],lon1[4],lon2[7],lat2[7];
              unsigned int resul,pntw,CAP;
              float flat,flon,resul2;
              unsigned char a1,b11;
incoming(char waste){
                                  if(waste == '+'){
                                   while(!RCIF_bit);
                                   RCIF_bit =0;
                                   waste = RCREG ;

                                  if(waste == 'C'){
                                   while(!RCIF_bit);
                                   RCIF_bit =0;
                                   waste = RCREG ;

                                   if(waste == 'M'){
                                    while(!RCIF_bit);
                                     RCIF_bit =0;
                                   waste = RCREG ;
                                   pnt_waste =9;

                                   if(waste == 'T'){
                                    pnt_waste =2;
                            }
                              return pnt_waste ;
                     }

                  }
             }

 }
 read_msg(char waste){
                                    if(waste == 'G') {
                                 while(RCREG !=  '\r');//\r
                                    RCIF_bit =0;
                                    waste = RCREG;
                                 while(RCREG !=  '\n');
                                    RCIF_bit =0;
                                    waste = RCREG;
                                    while (!RCIF_bit);
                                     RCIF_bit =0;
                                     waste = RCREG;
                                    return 'm';

                          }
                 }






GPS_INFO(){
           int vz;
           for(vz=0; vz<2; vz++){
              UART1_WRITE_TEXT2("AT+CGPSINF=4\r");
              DELAY_MS(2000);
              }
             }
LOCATION(unsigned char waste){
                              int pnnt=0  ;
                           while(waste != '\r'){
                                    stor[pnnt] = waste;
                                    while (!RCIF_bit);
                                    RCIF_bit =0;
                                    waste = RCREG;
                                     pnnt++;
                                     }
           return 'r';


}

GPS_read(unsigned char waste){
                          int pnnt=0;
                             if(waste=='4'){
                                   while (!RCIF_bit);
                                    RCIF_bit =0;
                                    waste = RCREG;
                                    if(waste==','){
//*************************************************************************** lat
                                    pntw=0;
                                    while(waste != '.'){
                                    while (!RCIF_bit);
                                    RCIF_bit =0;
                                    lat1[pntw++] = RCREG;
                                    waste=RCREG;
                                   }
                                   pntw=0;
                                   lat[pnnt++]= RCREG;
                                    while(waste != ','){
                                    while (!RCIF_bit);
                                    RCIF_bit =0;
                                    lat2[pntw++] = RCREG;
                                    waste= RCREG;
                                   }
                                      while (!RCIF_bit);
                                    RCIF_bit =0;
                                    waste = RCREG;
                                    a1= waste;
                                    while (!RCIF_bit);
                                    RCIF_bit =0;
                                    waste = RCREG;
                                      pnnt=0;
  //*********************************************************************long

                                    pntw=0;
                                    while(waste != '.'){
                                    while (!RCIF_bit);
                                    RCIF_bit =0;
                                    lon1[pntw++] = RCREG;

                                    waste= RCREG;
                                   }
                                   pntw=0;
                                   lon[pnnt++]= RCREG;
                                    while(waste != ','){
                                    while (!RCIF_bit);
                                    RCIF_bit =0;
                                    lon2[pntw++] = RCREG;
                                    waste=RCREG;
                                   }
                                      while (!RCIF_bit);
                                    RCIF_bit =0;
                                    waste = RCREG;
                                      pnnt=0;
                                      b11= waste;
                                   }
                             }
                          }
void interrupt(void){
             if(RCIF_bit){
                               RCIF_bit =0;
                                mont = RCREG;
                                GPS_read(mont);
                                    chk = incoming(mont);     //check incoming message
                                    if (chk ==9){
                                    mont = RCREG;
                                    chk = read_msg(mont);
                                    if(chk =='m'){
                                    mont = RCREG;
                                    loc = LOCATION(mont);
                                    }
             }

               if(chk==2) kep=1;
              RCIF_bit =0;
     }

}

GPS_CONFIGURE(){
               int cal;
               for(cal=0; cal<2; cal++){
                  UART1_WRITE_TEXT2("AT+CGPSPWR=1\r");
                  DELAY_1SEC();
                  UART1_WRITE_TEXT2("AT+CGPSRST=0\r");
                  DELAY_1SEC();
                  }
                  }
void main() {
             TRISB=0; TRISC.F0=0; PORTC.F0=0;
             LATB=0;
             ADCON1=0x0E;
             CMCON =0x07;
             LCD2_INIT();
             LCD_INIT();
             LCD_CMD(_LCD_CURSOR_OFF);
             UART1_INIT2(9600);  //Default 9600 baudrate
             UART1_INIT(9600);
             RCON.IPEN=0;
             chk2=0;
             lcd2_out(1,0,"Initialising ...");
             delay_ms(5000);
              configure();
               GPS_CONFIGURE();

             delete1();

              while(1){
                    GPS_INFO();
                     LCD_CMD(_LCD_CLEAR);
                     lat1[3] =0;
                     lat2[6]=0;
                     lon1[3] =0;
                     lon2[6]=0;
                   resul=atoi(lat1);
                   flat = (int)(resul/100)+ ((resul%100)/60.0) ;
                   resul2 = atof(lat2);
                   flat = flat  +  (float)(resul2/1000000.0)/60.0 ;
                   resul= atof(lon1);
                   flon = (int)(resul/100)+ ((resul%100)/60.0);
                   resul2 = atof(lon2);
                   flon =  flon + (float)(resul2 / 1000000.0)/60.0;
                   floattostr(flat,lat);
                   floattostr(flon,lon);
                   stor[10]=0;
                  LCD2_OUT(1,0,"Rec: ");
                  LCD_OUT_CP(stor);
                  delay_ms(3000);
              // UART1_INIT2(9600);
                  if(kep ==1){
                   LCD_CMD(_LCD_CLEAR);
                    LCD2_OUT(1,0,"Incoming Message");
                    configure();
                    read();
                    delete1();
                    kep=0;
                    
                  if(loc=='r'){
                  delay_ms(10000);

                   UART1_WRITE_TEXT2("AT+CMGS=\"08188515146\"\r");
                   DELAY_MS(4000);
                   UART1_Write_Text2("https://google.com/maps/place/\r");//addds google link
                   UART1_Write_Text2(lat);
                   UART1_Write('+');
                   UART1_Write_Text2(lon);
                   UART1_Write(26); //sends the composed text message
                   loc=0;
                   }
                }

                  LCD_CMD(_LCD_CLEAR);
                  LCD2_OUT(1,0,"lat: ");
                  LCD_OUT_CP(lat);
                   LCD_CHR_CP(a1);
                  LCD2_OUT(2,0,"lon: ");
                  LCD_OUT_CP(lon);
                  LCD_CHR_CP(b11);
                  delay_ms(1000);
                  
}

}



for more information please call me on +2348188515146


                                                                     




     

                                                                                                                                                                  






                                     



1 comment:

  1. Hi Olayiwola Ayinde, nice to meet you.

    I'm currently designing a car tracker with the SIM908 with a PIC microcontroller.
    I wonder if I can ask you some questions about the hardware design.

    Really thanks a lot from already.
    My best regards.

    ReplyDelete