gps based real time vehicle tracking system

47
2012 STUDENTS: DEBALINA CHATTERJEE (CSE/2008/032) SAURABH KUMAR (CSE/2008/033) NILOTPAL MAHADANI (CSE/2008/035) RCC INSTITUTE OF INFORMATION TECHNOLOGY, KOLKATA GPS BASED REAL TIME VEHICLE TRACKING SYSTEM Guide: Prof. Sujit Kumar Ghosh Head of Computer Science & Engineering Department

Upload: debalina-chatterjee

Post on 07-Nov-2014

128 views

Category:

Documents


7 download

DESCRIPTION

Detailed project report

TRANSCRIPT

Page 1: Gps Based Real Time Vehicle Tracking System

2012

STUDENTS:

DEBALINA CHATTERJEE (CSE/2008/032)

SAURABH KUMAR (CSE/2008/033)

NILOTPAL MAHADANI (CSE/2008/035)

RCC INSTITUTE OF INFORMATION

TECHNOLOGY, KOLKATA

GPS BASED REAL TIME VEHICLE TRACKING SYSTEM

Guide: Prof. Sujit Kumar Ghosh

Head of Computer Science &

Engineering Department

Page 2: Gps Based Real Time Vehicle Tracking System

2 | P a g e

GPS BASED REAL TIME VEHICLE TRACKING SYSTEM

REPORT OF PROJECT SUBMITTED FOR FULFILLMENT OF THE

REQUIREMENT FOR THE DEGREE OF BACHELOR OF TECHNOLOGY

In COMPUTER SCIENCE & ENGINEERING

By

DEBALINA CHATTERJEE [REGISTRATION NO- 081170110018, UNIVERSITY ROLLNO- 08117001016]

SAURABH KUMAR [REGISTRATION NO- 081170110044, UNIVERSITY ROLLNO- 08117001038]

& NILOTPAL MAHADANI

[REGISTRATION NO- 081170110031, UNIVERSITY ROLLNO- 08117001035]

UNDER THE SUPERVISION OF

PROF. SUJIT KUMAR GHOSH HEAD OF COMPUTER SCIENCE & ENGINEERING DEPARTMENT

RCC INSTITUTE OF INFORMATION TECHNOLOGY

AT

RCC INSTITUTE OF INFORMATION TECHNOLOGY [AFFILIATED TO WEST BENGAL UNIVERSITY OF TECHNOLOGY]

CANAL SOUTH ROAD, BELIAGHATA, KOLKATA – 700015

Page 3: Gps Based Real Time Vehicle Tracking System

3 | P a g e

RCC INSTITUTE OF INFORMATION TECHNOLOGY KOLKATA – 7OOO15, INDIA

CERTIFICATE The report of the Project titled ‚GPS BASED REAL TIME VEHICLE TRACKING SYSTEM‛ submitted by Debalina Chatterjee (Roll No.:08117001016 of B.Tech. CSE 8th

Semester of 2012), Saurabh Kumar (Roll No.:08117001038 of B.Tech. CSE 8th

Semester of 2012),Nilotpal Mahadani (Roll No.:08117001035 of B.Tech. CSE 8th

Semester of 2012)has been prepared under my supervision for the fulfillment of the requirements for B.Tech CSE degree in West Bengal University of Technology. The report is hereby forwarded. Prof. Sujit Kumar Ghosh Head of Computer Science & Engineering Department RCC Institute of Information Technology, Kolkata – 700 015.

Page 4: Gps Based Real Time Vehicle Tracking System

4 | P a g e

ACKNOWLEDGEMENT We express our sincere gratitude to Prof. Sujit Kumar Ghosh of Department of Computer Science & Engineering, RCCIIT and for extending his valuable time for us to take up this problem as a Project.Last but not the least We would like to express our gratitude to all other faculties of our department who helped us in their own way whenever needed. Date: Name of Students Reg.No. RollNo. Debalina Chatterjee 081170110018 08117001016 Saurabh Kumar 081170110044 08117001038 Nilotpal Mahadani 081170110031 08117001035 B. Tech CSE 8th Semester, 2012 RCCIIT,Kolkata.

Page 5: Gps Based Real Time Vehicle Tracking System

5 | P a g e

RCC INSTITUTE OF INFORMATION TECHNOLOGY

KOLKATA – 7OOO15, INDIA

CERTIFICATE of ACCEPTANCE The report of the Project titled ‚GPS BASED REAL TIME VEHICLE TRACKING SYSTEM‛ submitted by by Debalina Chatterjee (Roll No.:08117001016 of B.Tech. CSE 8th

Semester of 2012), Saurabh Kumar (Roll No.:08117001038 of B.Tech . CSE 8th

Semester of 2012), Nilotpal Mahadani (Roll No.:08117001035 of B.Tech. CSE 8th

Semester of 2012) is hereby recommended to be accepted for the fulfillment of the requirements for B.Tech CSE degree in West Bengal University of Technology. Name of the Examiner Signature with Date 1. …………………………………… 2. …………………………………… 3. …………………………………… 4. ……………………………………

Page 6: Gps Based Real Time Vehicle Tracking System

6 | P a g e

TABLE OF CONTENTS

Abstract ------------------------------------------------ 7

Purpose ------------------------------------------------- 8

Review of Literature ------------------------------------ 9

Abstract view & Functional Units ------------------------ 10

Technologies Used --------------------------------------- 12

Logical View -------------------------------------------- 13

Implementation Details ---------------------------------- 15

UART Communication & RS232 ------------------------------ 16

Signal Definitions -------------------------------------- 17

Asynchronous Communication ------------------------------ 18

Hardware Requirements ----------------------------------- 19

MAX232 Interfacing with MIC ----------------------------- 20

8051 UART programming ----------------------------------- 21

C Code For UART Programming In 8051 --------------------- 24

Interfacing LCD Module With 8051 ------------------------ 27

Design of LCD circuit with 8051 ------------------------- 28

Code For Controlling LCD Functions ---------------------- 30

Global Positioning System ------------------------------- 33

GPRMC sentence ------------------------------------------ 38

GSM MODEM ----------------------------------------------- 40

Implementing Tracking Server ---------------------------- 42 CODE for Tracking server -------------------------------- 44 Conclusion ---------------------------------------------- 46 Future Scope & Reference -------------------------------- 47

Page 7: Gps Based Real Time Vehicle Tracking System

7 | P a g e

GPS BASED REAL TIME VEHICLE TRACKING SYSTEM

ABSTRACT Many vehicle systems that are in use now days provide some sort of Automatic Vehicle Location (AVL) information. In this project we strived to design and implement Automatic Vehicle Location system that can transmit the location information in real time. The hardware device (In-vehicle unit) runs an embedded program which constantly receives & displays the present geographic location of the vehicle by GPS system installed in it. The information is transmitted to Tracking server using GSM/GPRS modem on GSM network by using SMS or using direct TCP/IP connection with Tracking server through GPRS. Tracking server also has GSM/GPRS modem that receives vehicle location information via GSM network and stores this information in a central database. This information is available to authorized users of the system via website over the internet.

INTRODUCTION Vehicle Tracking Systems were used from past as a part of Navigation systems .Ships used to hold a device which recorded a log of all positions and directions the ship moved over the sea. These were called passive vehicle tracking systems. These tracking systems were crude and very less accurate. As communication systems developed day by day, a demand for real time vehicle tracking with advanced communication techniques rose. This need increased as the number of vehicles on road/rail and their safety requirement increased. Hence forth the development of GPS Satellites and its freely available broadcast messages triggered the need to manufacture precision instruments. Thus this project aims at providing a mobile device attached to vehicle's pilot cabin, constantly broadcasting Position, Velocity and Time (Real Time) for live monitoring and logging of these information to nearest Base Station. Keeping in mind the cost of standalone GPS Navigators available in the market, the design of this Vehicle tracker is made in such a way that it can be easily affordable and robust for use by Public Transport Sectors.

Page 8: Gps Based Real Time Vehicle Tracking System

8 | P a g e

OBJECTIVE i)Exploring the GPS receiver module for study of data formats and configuring it properly. ii)Developing Automatic Vehicle Location system using GPS for positioning information and GSM/GPRS for information transmission with following features:

a) Acquisition of vehicle’s location information (latitude & longitude) and speed after specified time interval from a GPS reciever module.

b) Transmission of vehicle’s location and other

information to the monitoring station/Tracking server after specified interval of time.

c) Display of this information to the attached Display

unit onboard. iii)Developing a Central Server which will request for positional information of a particular vehicle by sending its unique vehicle identification number and storing that information in their corresponding database. iv)Developing a Web based Graphical User Interface to read real time data arriving at the Base Station and displaying it on a web browser. There will be a provision for fetching past recorded log data for performance monitoring and troubleshooting.

PURPOSE OF THE PROJECT

This project provides Real time Vehicle tracking solutions to any Transport sytems, Personal vehicles, in a very accurate manner. This will support any mobile platform. Though this Device will be developed as a general purpose GPS Tracking System , but there is a provision made especially for applying it over Railway network for monitoring trains along their routes. Thus it will help the railway to enhance passenger security by trafficking exact location of trains running adjacently. In this way the density of trains per track can be considerably increased serving better extra rush in Urban Areas. This service will provide passengers on station with exact information about the the position of trains route. This project keeps a provision of providing information to passengers on their mobile phones and also on the internet. Their is another provision of controlling the train remotely from a base station in cases of emergency which will provide a platform with almost no chances of accidents .

Page 9: Gps Based Real Time Vehicle Tracking System

9 | P a g e

REVIEW OF LITERATURE

GPS - The Global Positioning System (GPS) is a space-based global

navigation satellite system (GNSS) that provides location and time information in all weather, anywhere on or near the Earth, where there is an unobstructed line of sight to four or more GPS satellites.

GSM - GSM (Global System for Mobile Communications, originally Groupe Spécial Mobile), is a standard set developed by the European Telecommunications Standards Institute (ETSI) to describe technologies for second generation (or "2G") digital cellular networks. Developed as a replacement for first generation analog cellular networks, the GSM standard originally described a digital, circuit switched network optimized for full duplex voice telephony.It provides moderate-speed data/voice transfer, by using unused time division multiple access (TDMA) channels.

GPRS - General packet radio service (GPRS) is a packet oriented mobile data service on the 2G and 3G cellular communication system's global system for mobile communications (GSM).GPRS usage charging is based on volume of data . This contrasts with circuit switching data, which is typically billed per minute of connection time, regardless of whether or not the user transfers data during that period.It supports TCP/IP , PPP , X.25 network protocols for data communication.

SMS - Short Message Service (SMS) is a text messaging service component of phone, web, or mobile communication systems, using standardized communications protocols that allow the exchange of short text messages between fixed line or mobile phone devices.Most SMS messages are mobile-to-mobile text messages though the standard supports other types of broadcast messaging as well.

USSD - Unstructured Supplementary Service Data (USSD) is a protocol used by GSM cellular telephones to communicate with the service provider's computers. USSD can be used for WAP browsing, prepaid callback service, mobile-money services, location-based content services, menu-based information services, and as part of configuring the phone on the network. Unlike Short Message Service (SMS) messages, USSD messages create a real-time connection during a USSD session. The connection remains open, allowing a two-way exchange of a sequence of data.

Page 10: Gps Based Real Time Vehicle Tracking System

10 | P a g e

BLOCK DIAGRAM (ABSTRACT VIEW)

FUNCTIONAL BLOCKS

Page 11: Gps Based Real Time Vehicle Tracking System

11 | P a g e

The prime functional blocks are:

i) IN – VEHICLE UNIT ii) TRACKING SERVER

The corresponding steps involved for this project are broadly subdivided as:

i) Data Acquisition : The device used for Data acquisition from Satellite is a GPS antennae . The antennae brings up the analog signals from multiple satellites at a time (8 to 12) depending upon the signal strength. The data available here will be following the standard NMEA protocol. This is converted to TTL logic level by a hardware circuitry and data is available on its SPI (Serial Port Interface).

ii) Data Processing : The data available from the GPS module is read serially and stored in the stack memory of the Microcontroller (MCU). The currently stored sentence is read by a program running on MCU and it is parsed to get values for different attributes. The information from the GPS as GPRMC format (Recommended Minimum Specific GNSS Data). This is one of the standard format given by Global Navigation satellite System(GNSS). The attributes are then converted to their specified SI units.

iii) Data Forwarding and Display : The parsed data which has been processed is displayed onto a LCD by an interfacing program module. Simultaneously a subroutine sets up a RF Transmitter to connect to a network for wireless transmission of the same data to the Base Station (Central Server). This is done using a GPRS Modem which uses 2G GSM Network. Alternatively a TCP/IP Hence the retrieved information from a mobile Vehicle (for ex a moving train) is available on the Database of the Base Station. A predefined Station Look-Up Table finds out the Approaching Station from the (Latitude, Longitude) value set and displays it on a Web browser. The whole phenomena is repeated at a certain frequency and the web page is refreshed at a certain interval for updating to the latest available information.

Page 12: Gps Based Real Time Vehicle Tracking System

12 | P a g e

TECHNOLOGIES USED

The major components used for building the hardware and software of the two functional units are given below :

1) IN-VEHICLE UNIT :

Hardware resources : a) GPS Receiver module with antennae b) GSM Modem with antennae c) 8051 P89V51RD2 d) Vero Board for installing all components e) Regulated Power Supply circuit f) 8051 Programmer g) Serial Cable with DB9 Interface h) 16 * 2 LCD Display i) MAX 232 logic converter Software resources : a) Proteus Emulator for Schematic Circuit Design. b) KEIL C compiler c) Flash Magic

2) TRACKING SERVER :

Hardware resources : a) GSM Modem with antennae b) DB9 connector to connect to serial port c) Power supply for GSM Modem Software resources : a) MySQL Server b) PHP MYADMIN c) Apache Web Server d) GCC

HRDWARE & SOFTWARE REQUIREMENT Operating system used: Windows 7, Linux (Ubuntu) Processor: Intel core 2 duo or above, AMD RAM : 256 MB or above

Page 13: Gps Based Real Time Vehicle Tracking System

13 | P a g e

LOGICAL VIEW

1) CLASS DIAGRAM: These are the two classes to be used for displaying the logged data to passenger information system. The tracking server runs the program to fetch data from Internet/GSM Modem and sets it to class GPS_INFO . Another class TRAIN_DETAILS reads the last logged record and displays it to User Interface.

2) STRUCTURE CHART : This is the actual flow of control within varios software modules.

Page 14: Gps Based Real Time Vehicle Tracking System

14 | P a g e

EVENT CHART :

TIMING DIAGRAM :

Page 15: Gps Based Real Time Vehicle Tracking System

15 | P a g e

IMPLEMENTATION DETAILS

A) IN-VEHICLE UNIT : Attached to the vehicle & collects information from GPS

OVERALL CIRCUIT DIAGRAM

In this project we are using Serial Communication to receive/send data serially from/to 8051 MIC and communicate serially with the DB9 COM port. The 8051 MIC follows TTL logic (+3V to +5V for Logic 1 & 0V to +0.5V for Logic 0) But DB9 COM port uses RS232 logic (-3V to -20V Logic 1 and +3V to +20V for Logic 0). Thus MAX232 is used to convert TTL logic to RS232 logic and vice versa.

Page 16: Gps Based Real Time Vehicle Tracking System

16 | P a g e

UART COMMUNICATION UART (Universal Asynchronous Receiver Transmitter) or USART (Universal Synchronous Asynchronous Receiver Transmitter) are one of the basic interface which is found in almost all the controllers available in the market till date. This interface provide a cost effective simple and reliable communication between one controller to another controller or between a controller and PC. It is a process of ICP or In Circuit Programming. What is Serial Communication? Computers transfer information (data) one or more bits at a time. Serial refers to the transfer of data one bit at a time. Serial communications include most network devices, keyboards, mice, MODEMs, and terminals. When doing serial communications each word (i.e. byte or character) of data we send or receive is sent one bit at a time. Each bit is either on or off. The speed of the serial data is most often expressed as bits-per-second ("bps") or baudrate ("baud"). This just represents the number of ones and zeroes that can be sent in one second. Back at the dawn of the computer age, 300 baud was considered fast, but today computers can handle RS-232 speeds as high as 430,800 baud. For rates above 1,000,000 that rate is shown in megabaud, or Mbps (e.g. 1.5Mbps). When referring to serial devices or ports, they are either labeled as Data Communications Equipment ("DCE") or Data Terminal Equipment ("DTE"). The difference between these is simple - every signal pair, like transmit and receive, is swapped. When connecting two DTE or two DCE interfaces together, a serial Null-MODEM cable or adapter is used that swaps the signal pairs. What Is RS-232? RS-232 is a standard electrical interface for serial communications defined by the Electronic Industries Association ("EIA"). RS-232 actually comes in 3 different flavors (A, B, and C) with each one defining a different voltage range for the on and off levels. The most commonly used variety is RS-232C, which defines a mark (on) bit as a voltage between -3V and -12V and a space (off) bit as a voltage between +3V and +12V. The RS-232C specification says these signals can go about 25 feet (8m) before they become unusable. We can usually send signals a bit farther than this as long as the baud is low enough.

Page 17: Gps Based Real Time Vehicle Tracking System

17 | P a g e

SIGNAL DEFINITIONS

The RS-232 standard defines some 18 different signals for serial communications. Of these, only six are generally available in the UNIX environment. GND - Logic Ground Technically the logic ground is not a signal, but without it none of the other signals will operate. Basically, the logic ground acts as a reference voltage so that the electronics know which voltages are positive or negative. TXD - Transmitted Data The TXD signal carries data transmitted from wer workstation to the computer or device on the other end (like a MODEM). A mark voltage is interpreted as a value of 1, while a space voltage is interpreted as a value of 0. RXD - Received Data The RXD signal carries data transmitted from the computer or device on the other end to wer workstation. Like TXD, mark and space voltages are interpreted as 1 and 0, respectively. DCD - Data Carrier Detect The DCD signal is received from the computer or device on the other end of wer serial cable. A space voltage on this signal line indicates that the computer or device is currently connected or on line. DCD is not always used or available. DTR - Data Terminal Ready The DTR signal is generated by wer workstation and tells the computer or device on the other end that we are ready (a space voltage) or not-ready (a mark voltage). DTR is usually enabled automatically whenever we open the serial interface on the workstation. CTS - Clear To Send The CTS signal is received from the other end of the serial cable. A space voltage indicates that it is alright to send more serial data from wer workstation. CTS is usually used to regulate the flow of serial data from wer workstation to the other end. RTS - Request To Send The RTS signal is set to the space voltage by wer workstation to indicate that more data is ready to be sent. Like CTS, RTS helps to regulate the flow of data between wer workstation and the computer or device on the other end of the serial cable. Most workstations leave this signal set to the space voltage all the time.

Page 18: Gps Based Real Time Vehicle Tracking System

18 | P a g e

ASYNCHRONOUS COMMUNICATIONS For the computer to understand the serial data coming into it, it needs some way to determine where one character ends and the next begins. This guide deals exclusively with asynchronous serial data. In asynchronous mode the serial data line stays in the mark (1) state until a character is transmitted. A start bit preceeds each character and is followed immediately by each bit in the character, an optional parity bit, and one or more stop bits. The start bit is always a space (0) and tells the computer that new serial data is available. Data can be sent or received at any time, thus the name asynchronous. The optional parity bit is a simple sum of the data bits indicating whether or not the data contains an even or odd number of 1 bits. With even parity, the parity bit is 0 if there is an even number of 1's in the character. With odd parity, the parity bit is 0 if there is an odd number of 1's in the data. Space parity means that the parity bit is always 0, while mark parity means the bit is always 1. No parity means that no parity bit is present or transmitted.

The remaining bits are called stop bits. There can be 1, 1.5, or 2 stop bits between characters and they always have a value of 1. Stop bits traditionally were used to give the computer time to process the previous character, but now only serve to synchronize the receiving computer to the incoming characters. Asynchronous data formats are usually expressed as "8N1", "7E1", and so forth. These stand for "8 data bits, no parity, 1 stop bit" and "7 data bits, even parity, 1 stop bit" respectively. How to use UART in a 8051 MCU? One of the 8051s most powerful features is its integrated UART, otherwise known as a serial port. The fact that the 8051 has an integrated serial port means that we may very easily read and write values to the serial port. If it were not for the integrated serial port, writing a byte to a serial line would be a rather tedious process requiring turning on and off one of the I/O lines in rapid succession to properly "clock out" each individual bit, including start bits, stop bits, and parity bits.

Page 19: Gps Based Real Time Vehicle Tracking System

19 | P a g e

HARDWARE SETUP AND CIRCUIT REQUIREMENTS Voltage Levels: The RS-232 standard defines the voltage levels that correspond to logical one and logical zero levels. Valid signals are plus or minus 3 to 25 volts. The range near zero volts is not a valid RS-232 level; logic one is defined as a negative voltage, the signal condition is called marking, and has the functional significance of OFF. Logic zero is positive, the signal condition is spacing, and has the function ON. So a Logic Zero represented as +3V to +25V and Logic One represented as -3V to -25V. RS-232 Level Converters: Usually all the digital ICs work on TTL or CMOS voltage levels which cannot be used to communicate over RS-232 protocol. So a voltage or level converter is needed which can convert TTL to RS232 and RS232 to TTL voltage levels. The most commonly used RS-232 level converter is MAX232. This IC includes charge pump which can generate RS232 voltage levels (-10V and +10V) from 5V power supply. It also includes two receiver and two transmitters and is capable of full-duplex UART/USART communication.

PIN DESCRIPTION OF MAX232

Page 20: Gps Based Real Time Vehicle Tracking System

20 | P a g e

MAX232 INTERFACING WITH MICROCONTROLLERS

To communicate over UART or USART, we just need three basic signals which are namely, RXD (receive), TXD (transmit), GND (common ground). So to interface MAX232 with any microcontroller (AVR, ARM, 8051, PIC etc..) we just need the basic signals. A simple design of connections between a microcontroller and MAX232 is shown using PROTEUS SOFTWARE

Page 21: Gps Based Real Time Vehicle Tracking System

21 | P a g e

8051 PROGRAMMING FOR UART However, we do not have to do this. Instead, we simply need to configure the serial ports operation mode and baud rate. Once configured, all we have to do is write to an SFR to write a value to the serial port or read the same SFR to read a value from the serial port. The 8051 will automatically let us know when it has finished sending the character we wrote and will also let us know whenever it has received a byte so that we can process it. We do not have to worry about transmission at the bit level--which saves us quite a bit of coding and processing time.

In 8051, we make use of Timer 1 to generate the required baud rate. Following are the registers that are need to be configured to communicate over UART. · TMOD · SCON · TH1 · TL1 · TCON TMOD: This register is used to set the mode of Timer0 and Timer1. It is also used to select whether the timers are used as Timer or Counter. SCON: Serial Control register has various functions like.. it has flags for Framing error, Transmit interrupt and receive interrupt. Its used to select the serial port mode, to enable or disable the reception etc. TCON: This register has various flag and control bits e. g. Timer overflow flags, interrupt edge flags, timer control bits to start/stop the timer. TH1 & TL1: Timer registers for Timer 1 determines the baud rate of UART. Setting the Serial Port Mode The first thing we must do when using the 8051s integrated serial port is, obviously, configure it. This lets us tell the 8051 how many data bits we want, the baud rate we will be using, and how the baud rate will be determined. First, let us present the "Serial Control" (SCON) SFR and define what each bit of the SFR represents: Bit Name Bit Address Explanation of Function 7 SM0 9Fh Serial port mode bit 0 6 SM1 9Eh Serial port mode bit 1. 5 SM2 9Dh Multi processor Communications Enable 4 REN 9Ch Receiver Enable. This bit must be set in order to receive characters. 3 TB8 9Bh Transmit bit 8. The 9th bit to transmit in mode 2 and 3. 2 RB8 9Ah Receive bit 8. The 9th bit received in mode 2 and 3. 1 TI 99h Transmit Flag. Set when a byte has been completely transmitted. 0 RI 98h Receive Flag. Set when a byte has been completely received.

Page 22: Gps Based Real Time Vehicle Tracking System

22 | P a g e

Additionally, it is necessary to define the function of SM0 and SM1 by an additional table: SM0 SM1 Serial Mode Explanation Baud Rate 0 0 0 8-bit Shift Register Oscillator / 12 0 1 1 8-bit UART Set by Timer 1 (*) 1 0 2 9-bit UART Oscillator / 64 (*) 1 1 3 9-bit UART Set by Timer 1 (*) (*) Note: The baud rate indicated in this table is doubled if PCON.7 (SMOD) is set. The SCON SFR allows us to configure the Serial Port. The first four bits (bits 4 through 7) are configuration bits. Bits SM0 and SM1 let us set the serial mode to a value between 0 and 3, inclusive. The four modes are defined in the chart immediately above. As we can see, selecting the Serial Mode selects the mode of operation (8-bit/9-bit, UART or Shift Register) and also determines how the baud rate will be calculated. In modes 0 and 2 the baud rate is fixed based on the oscillator’s frequency. In modes 1 and 3 the baud rate is variable based on how often Timer 1 overflows. The next bit, SM2, is a flag for "Multiprocessor communication." Generally, whenever a byte has been received the 8051 will set the "RI" (Receive Interrupt) flag. This lets the program know that a byte has been received and that it needs to be processed. However, when SM2 is set the "RI" flag will only be triggered if the 9th bit received was a "1". That is to say, if SM2 is set and a byte is received whose 9th bit is clear, the RI flag will never be set. This can be useful in certain advanced serial applications. For now it is safe to say that we will almost always want to clear this bit so that the flag is set upon reception of any character. The next bit, REN, is "Receiver Enable." This bit is very straightforward: If we want to receive data via the serial port, set this bit. We will almost always want to set this bit. The last four bits (bits 0 through 3) are operational bits. They are used when actually sending and receiving data--they are not used to configure the serial port. The TB8 bit is used in modes 2 and 3. In modes 2 and 3, a total of nine data bits are transmitted. The first 8 data bits are the 8 bits of the main value, and the ninth bit is taken from TB8. If TB8 is set and a value is written to the serial port, the data bits will be written to the serial line followed by a "set" ninth bit. If TB8 is clear the ninth bit will be "clear." The RB8 also operates in modes 2 and 3 and functions essentially the same way as TB8, but on the reception side. When a byte is received in modes 2 or 3, a total of nine bits are received. In this case, the first eight bits received are the data of the serial byte received and the value of the ninth bit received will be placed in RB8.

Page 23: Gps Based Real Time Vehicle Tracking System

23 | P a g e

TI means "Transmit Interrupt" When a program writes a value to the serial port, a certain amount of time will pass before the individual bits of the byte are "clocked out" the serial port. If the program were to write another byte to the serial port before the first byte was completely output, the data being sent would be garbled. Thus, the 8051 lets the program know that it has "clocked out" the last byte by setting the TI bit. When the TI bit is set, the program may assume that the serial port is "free" and ready to send the next byte. Finally, the RI bit means "Receive Interrupt" It functions similarly to the "TI" bit, but it indicates that a byte has been received. That is to say, whenever the 8051 has received a complete byte it will trigger the RI bit to let the program know that it needs to read the value quickly, before another byte is read. Setting the Serial Port Baud Rate Once the Serial Port Mode has been configured, as explained above, the program must configure the serial ports baud rate. This only applies to Serial Port modes 1 and 3. The Baud Rate is determined based on the oscillator’s frequency when in mode 0 and 2. In mode 0, the baud rate is always the oscillator frequency divided by 12. This means if crystal is 11.059 Mhz, mode 0 baud rate will always be 921,583 baud. In mode 2 the baud rate is always the oscillator frequency divided by 64, so a 11.059Mhz crystal speed will yield a baud rate of 172,797. In modes 1 and 3, the baud rate is determined by how frequently timer 1 overflows. The more frequently timer 1 overflows, the higher the baud rate. There are many ways one can cause timer 1 to overflow at a rate that determines a baud rate, but the most common method is to put timer 1 in 8-bit auto-reload mode (timer mode 2) and set a reload value (TH1) that causes Timer 1 to overflow at a frequency appropriate to generate a baud rate. Use of Timer is to generate the required Baud rate. Timer's 8 Bit Auto Reload mode: Timer mode "2" is an 8-bit auto-reload mode. What is that, we may ask? Simple. When a timer is in mode 2, THx holds the "reload value" and TLx is the timer itself. Thus, TLx starts counting up. When TLx reaches 255 and is subsequently incremented, instead of resetting to 0 (as in the case of modes 0 and 1), it will be reset to the value stored in THx. For example, let’s say TH0 holds the value FDh and TL0 holds the value FEh. If we were to watch the values of TH0 and TL0 for a few machine cycles this is what we would see: Machine Cycle TH0 Value TL0 Value 1 FDh FEh 2 FDh FFh 3 FDh FDh 4 FDh FEh 5 FDh FFh 6 FDh FDh 7 FDh FEh

Page 24: Gps Based Real Time Vehicle Tracking System

24 | P a g e

As we can see, the value of TH0 never changed. In fact, when we use mode 2 we almost always set THx to a known value and TLx is the SFR that is constantly incremented. What is the benefit of auto-reload mode? Perhaps we want the timer to always have a value from 200 to 255. If we use mode 0 or 1, we’d have to check in code to see if the timer had overflowed and, if so, reset the timer to 200. This takes precious instructions of execution time to check the value and/or to reload it. When we use mode 2 the microcontroller takes care of this for we. Once we’ve configured a timer in mode 2 we don’t have to worry about checking to see if the timer has overflowed nor do we have to worry about resetting the value--the microcontroller hardware will do it all automatically. The auto-reload mode is very commonly used for establishing a baud rate which we will use in the Serial Communications. To determine the value that must be placed in TH1 to generate a given baud rate, we may use the following equation (assuming PCON.7 is clear). TH1 = 256 - ((Crystal / 384) / Baud) If PCON.7 is set then the baud rate is effectively doubled, thus the equation becomes: TH1 = 256 - ((Crystal / 192) / Baud) For example, if we have an 11.059Mhz crystal and we want to configure the serial port to 19,200 baud we try plugging it in the first equation: TH1 = 256 - ((Crystal / 384) / Baud) TH1 = 256 - ((11059000 / 384) / 19200 ) TH1 = 256 - ((28,799) / 19200) TH1 = 256 - 1.5 = 254.5 As we can see, to obtain 19,200 baud on a 11.059Mhz crystal we’d have to set TH1 to 254.5. If we set it to 254 we will have achieved 14,400 baud and if we set it to 255 we will have achieved 28,800 baud. To achieve 19,200 baud we simply need to set PCON.7 (SMOD). When we do this we double the baud rate and utilize the second equation mentioned above. Thus we have: TH1 = 256 - ((Crystal / 192) / Baud) TH1 = 256 - ((11059000 / 192) / 19200) TH1 = 256 - ((57699) / 19200) TH1 = 256 - 3 = 253 Here we are able to calculate a nice, even TH1 value. Therefore, to obtain 19,200 baud with an 11.059MHz crystal we must: 1. Configure Serial Port mode 1 or 3. 2. Configure Timer 1 to timer mode 2 (8-bit auto-reload). 3. Set TH1 to 253 to reflect the correct frequency for 19,200 baud. 4. Set PCON.7 (SMOD) to double the baud rate.

Page 25: Gps Based Real Time Vehicle Tracking System

25 | P a g e

C CODE FOR UART PROGRAMMING IN 8051 USING KEIL C COMPILER

Initializing UART #include <reg51.h>

void serial_init() { TMOD = 0x20; // put timer 1 in mode 2 interval timing (known as 8 bit auto reload mode) counting overflows SCON = 0x50; // serial port mode 1 and enable reception TH1 = 0xFD; //9600 baud rate and 11.0592 MHz external crystal TL1 = 0xFD; TR1 = 1; //Start Timer 1 }

Reading data from UART

unsigned char serial_read() { while(!RI); // Wait until reading is complete RI = 0; // Reset RI flag return SBUF; }

Reading data received by the serial port is easy. To read a byte from the serial port one just needs to read the value stored in the SBUF (99h) SFR after the 8051 has automatically set the RI flag in SCON. For example, if our program wants to wait for a character to be received and subsequently read it into the Accumulator, the following code segment may be used: JNB RI, $; Wait for the 8051 to set the RI flag MOV A, SBUF; read the character from the serial port The first line of the above code segment waits for the 8051 to set the RI flag; again, the 8051 sets the RI flag automatically when it receives a character via the serial port. So as long as the bit is not set the program repeats the "JNB" instruction continuously. Once the RI bit is set upon character reception the above condition automatically fails and program flow falls through to the "MOV" instruction which reads the value.

Page 26: Gps Based Real Time Vehicle Tracking System

26 | P a g e

Writing data in UART:

void serial_write_c(unsigned char dat) { SBUF = dat; while(!TI); // wait till the transmission completes TI = 0; // Reset TI flag }

Once the Serial Port has been properly configured as explained above, the serial port is ready to be used to send data and receive data. If we thought that configuring the serial port was simple, using the serial port will be a breeze. To write a byte to the serial port one must simply write the value to the SBUF (99h) SFR. For example, if we wanted to send the letter "A" to the serial port, it could be accomplished as easily as: MOV SBUF, #A Upon execution of the above instruction the 8051 will begin transmitting the character via the serial port. Obviously transmission is not instantaneous--it takes a measureable amount of time to transmit. And since the 8051 does not have a serial output buffer we need to be sure that a character is completely transmitted before we try to transmit the next character. The 8051 lets us know when it is done transmitting a character by setting the TI bit in SCON. When this bit is set we know that the last character has been transmitted and that we may send the next character, if any. Consider the following code segment: CLR TI; Be sure the bit is initially clear MOV SBUF, #A; Send the letter A to the serial port JNB TI, $; Pause until the TI bit is set. The above three instructions will successfully transmit a character and wait for the TI bit to be set before continuing. The last instruction says "Jump if the TI bit is not set to $"--$, in most assemblers, means "the same address of the current instruction." Thus the 8051 will pause on the JNB instruction until the TI bit is set by the 8051 upon successful transmission of the character.

Page 27: Gps Based Real Time Vehicle Tracking System

27 | P a g e

INTERFACING LCD MODULE WITH 8051 MCU The most commonly used Character based LCDs are based on Hitachi's HD44780 controller or other which are compatible with HD44580. we will discuss about character based LCDs, their interfacing with microcontroller, various interfaces (8-bit/4-bit), programming, special stuff and tricks we can do with these simple looking LCDs which can give a new look to our application. Pin Description: The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDs which have only 1 controller and support at most of 80 charachers, whereas LCDs supporting more than 80 characters make use of 2 HD44780 controllers. Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two pins are extra in both for back-light LED connections). Pin description is shown in the table below. Details of LCD Interfacing: Pin No. Name Description Pin no. 1 VSS Power supply (GND) Pin no. 2 VCC Power supply (+5V) Pin no. 3 VEE Contrast adjust Pin no. 4 RS 0 = Instruction input 1 = Data input Pin no. 5 R/W 0 = Write to LCD module 1 = Read from LCD module Pin no. 6 EN Enable signal Pin no. 7 D0 Data bus line 0 (LSB) Pin no. 8 D1 Data bus line 1 Pin no. 9 D2 Data bus line 2 Pin no. 10 D3 Data bus line 3 Pin no. 11 D4 Data bus line 4 Pin no. 12 D5 Data bus line 5 Pin no. 13 D6 Data bus line 6 Pin no. 14 D7 Data bus line 7 (MSB)

Page 28: Gps Based Real Time Vehicle Tracking System

28 | P a g e

DESIGN OF 8051-LCD CIRCUIT IN PROTEUS

DDRAM - Display Data RAM Display data RAM (DDRAM) stores display data represented in 8-bit character codes. Its extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM (DDRAM) that is not used for display can be used as general data RAM. So whatever we send on the DDRAM is actually displayed on the LCD. For LCDs like 1x16, only 16 characters are visible, so whatever we write after 16 chars is written in DDRAM but is not visible to the user.

Instruction Register and Data Register There are two 8-bit registers in HD44780 controller Instruction and Data register. Instruction register corresponds to the register where we send commands to LCD e. g. LCD shift command, LCD clear, LCD address etc. and Data register is used for storing data which is to be displayed on LCD. When send the enable signal of the LCD is asserted, the data on the pins is latched in to the data register and data is then moved automatically to the DDRAM and hence is displayed on the LCD. Data Register is not only used for sending data to DDRAM but also for CGRAM, the address where we want to send the data, is decided by the instruction we send to LCD.

Page 29: Gps Based Real Time Vehicle Tracking System

29 | P a g e

LCD Commands and Instructions Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by the MCU. Before starting the internal operation of the LCD, control information is temporarily stored into these registers to allow interfacing with various MCUs, which operate at different speeds, or various peripheral control devices. The internal operation of the LCD is determined by signals sent from the MCU. These signals, which include register selection signal (RS), read/write signal (R/W), and the data bus (DB0 to DB7), make up the LCD instructions. BF - Busy Flag Busy Flag is an status indicator flag for LCD. When we send a command or data to the LCD for processing, this flag is set (i.e BF =1) and as soon as the instruction is executed successfully this flag is cleared (BF = 0). This is helpful in producing an exact amount of delay. for the LCD processing. To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and The MSB of the LCDdata bus (D7) act as busy flag. When BF = 1 means LCD is busy and will not accept next command or data and BF = 0 means LCD is ready for the next command or data to process.

Instruction Register (IR) and Data Register (DR) There are two 8-bit registers in HD44780 controller Instruction and Data register. Instruction register corresponds to the register where we send commands to LCD e. g. LCD shift command, LCD clear, LCD address etc. and Data register is used for storing data which is to be displayed on LCD. When send the enable signal of the LCD is asserted, the data on the pins is latched in to the data register and data is then moved automatically to the DDRAM and hence is displayed on the LCD.

Commands and Instruction set Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by the MCU. Before starting the internal operation of the LCD, control information is temporarily stored into these registers to allow interfacing with various MCUs, which operate at different speeds, or various peripheral control devices. The internal operation of the LCD is determined by signals sent from the MCU. These signals, which include register selection signal (RS), read/write signal (R/W), and the data bus (DB0 to DB7), make up the LCD instructions.

Page 30: Gps Based Real Time Vehicle Tracking System

30 | P a g e

There are four categories of instructions that: Designate LCD functions, such as display format, data length, etc. Set internal RAM addresses Perform data transfer with internal RAM Perform miscellaneous functions

No. Instruction Hex Decimal 1 Function Set: 8-bit, 1 Line, 5x7 Dots 0x30 48 2 Function Set: 8-bit, 2 Line, 5x7 Dots 0x38 56 3 Function Set: 4-bit, 1 Line, 5x7 Dots 0x20 32 4 Function Set: 4-bit, 2 Line, 5x7 Dots 0x28 40 5 Entry Mode 0x06 6 6 Display off Cursor off 0x08 8 (clearing display without clearing DDRAM content) 7 Display on Cursor on 0x0E 14 8 Display on Cursor off 0x0C 12 9 Display on Cursor blinking 0x0F 15 10 Shift entire display left 0x18 24 12 Shift entire display right 0x1C 30 13 Move cursor left by one character 0x10 16 14 Move cursor right by one character 0x14 20 15 Clear Display (also clear DDRAM content) 0x01 1 16 Set DDRAM address or coursor position on 0x80+add* 128+add* Display Initializing LCD Controller Before using the LCD for display purpose, LCD has to be initialized either by the internal reset circuit or sending set of commands to initialize the LCD. Initialization by instructions Initializing LCD with instructions is really simple. Given below is a flowchart that describes the step to follow, to initialize the LCD: 1) Delay 20ms 2) Send command 0x30 - 8-bit interface 3) Delay 20ms 4) Send command 0x30 - 8-bit interface 5) Delay 20ms 6) Send Function set - see Table 4 for more information 7) Display Clear command 8) Set entry mode command - explained below

Page 31: Gps Based Real Time Vehicle Tracking System

31 | P a g e

The first 3 commands are usually not required but are recommended when using 4-bit interface. So we can program the LCD starting from step 7 when working with 8-bit interface. Function set command depends on what kind of LCD we are using and what kind of interface are are using as given above. LCD Entry mode There are two entry modes for LCD, these bits are: a) I/D - Increment/Decrement bit b) S - Display shift. So we get different results with these different entry modes. Normally entry mode 0x06 is used which is No shift and auto increment.

Sending Commands to LCD To send commands we simply need to select the command register. Everything is same as we have done in the initialization routine. But we will summarize the common steps and put them in a single subroutine. Following are the steps:

Move data to LCD port select command register select write operation send enable signal wait for LCD to process the command

Sending Data to LCD To send data we simply need to select the data register. Everything is same as the command routine. Following are the steps:

Move data to LCD port select data register select write operation send enable signal wait for LCD to process the data

Page 32: Gps Based Real Time Vehicle Tracking System

32 | P a g e

CODE FOR CONTROLLING LCD FUNCTIONS

INITIALIZING LCD #include <reg51.h> #define lcd_db P2 #define delay_const 1500 sbit lcd_rs = P1^0; // Register Select sbit lcd_rw = P1^1; // Read Write sbit lcd_en = P1^2; // Enable

void lcd_init() {

lcd_command(0x38); // 8 bit 2 line mode function set delay_ms(5); lcd_command(0x0F); // display on cursor blinking delay_ms(5); lcd_command(0x80); // set DDRAM and Cursor position on 0x00 address and first line home position delay_ms(5); } SENDING COMMANDS TO LCD

void lcd_command(unsigned char comm) { lcd_db = comm; lcd_en = 1; lcd_rs = 0; lcd_rw = 0; delay_ms(5); lcd_en = 0; } DISPLAYING CHARACTER ON LCD

void lcd_putc(unsigned char ch) { lcd_db = ch; lcd_en = 1; lcd_rs=1; lcd_rw=0; delay_ms(5); lcd_en=0; }

Page 33: Gps Based Real Time Vehicle Tracking System

33 | P a g e

GLOBAL POSITIONING SYSTEM

The Global Positioning System (GPS) is a space-based satellite navigation system that provides location and time information in all weather, anywhere on or near the Earth, where there is an unobstructed line of sight to four or more GPS satellites. It is maintained by the United States government and is freely accessible to anyone with a GPS receiver.

The GPS program provides critical capabilities to military, civil and commercial users around the world. In addition, GPS is the backbone for modernizing the global air traffic system.

The GPS project was developed in 1973 to overcome the limitations of

previous navigation systems,[1] integrating ideas from several predecessors, including a number of classified engineering design studies from the 1960s. GPS was created and realized by the U.S. Department of Defense (DoD) and was originally run with 24 satellites. It became fully operational in 1994.

Basic Concept

A GPS receiver calculates its position by precisely timing the signals sent by GPS satellites high above the Earth. Each satellite continually transmits messages that include

1. The time the message was transmitted 2. Satellite position at time of message transmission The receiver uses the messages it receives to determine the transit

time of each message and computes the distance to each satellite. These distances along with the satellites' locations are used with the possible aid of trilateration, depending on which algorithm is used, to compute the position of the receiver. This position is then displayed, perhaps with a moving map display or latitude and longitude; elevation information may be included. Many GPS units show derived information such as direction and speed, calculated from position changes. How GPS works? A satellite is the space segment. A constellation of 24 GPS satellites (21 operational and 3 spares) orbits about 12,000 miles above the Earth. The satellites zoom through the heavens at around 7,000 miles per hour. It takes about 12 hours for a satellite to completely orbit the Earth, passing over the exact same spot approximately every 24 hours. The satellites are positioned where a GPS receiver can receive signals from at least six of the satellites at any time, at any location on the Earth (if nothing obstructs the signals). All GPS satellites since 1980 carry NUDET sensors. NUDET is an acronym for NUclear DETonation; GPS satellites have sensors to detect nuclear-weapon explosions, assess the threat of nuclear attack, and help evaluate nuclear strike damage. The solar-powered GPS satellites have a limited life span (around 10 years). When they start to fail, spares are activated or new

Page 34: Gps Based Real Time Vehicle Tracking System

34 | P a g e

satellites are sent into orbit to replace the old ones. This gives the government a chance to upgrade the GPS system by putting hardware with new features into space.

GPS receivers provide our location and other useful information: Time: A GPS receiver receives time information from atomic clocks, so it’s much more accurate than our wristwatch.

Location: GPS provides our location in three dimensions: • Latitude (x coordinate) • Longitude (y coordinate) • Elevation The vertical (elevation) accuracy of consumer GPS receivers isn’t that great. It can be within 15 meters, 95 percent of time. Some GPS units incorporate more accurate barometric altimeters for better elevation information. our location can be displayed in a number of coordinate systems, such as: • Latitude/longitude • Universal Transverse Mercator (UTM)

Page 35: Gps Based Real Time Vehicle Tracking System

35 | P a g e

Speed: When we’re moving, a GPS receiver displays our speed. Direction of travel: A GPS receiver can display our direction of travel if we’re moving. If we’re stationary, the unit can’t use satellite signals to determine which direction we’re facing.Some GPS units have electronic compasses that show the direction the receiver is pointed whether we’re moving or standing still. Stored locations: We can store locations where we’ve been or want to go with a GPS receiver. These location positions are waypoints. Waypoints are important because a GPS unit can supply we with directions and information on how to get to a waypoint. A collection of waypoints that plots a course of travel is a route, which can also be stored. GPS receivers also store tracks (which are like an electronic collection of breadcrumb trails that show where we’re been). Cumulative data: A GPS receiver can also keep track of information such as the total distance traveled, average speed, maximum speed, minimum speed, elapsed time, and time to arrival at a specified location. All this information is displayed on different pages of the GPS receiver’s display screen. One page shows satellite status, another page displays a map, another displays trip data, and so on. With buttons on the receiver, we can scroll to an information page to view the data that we’re interested in seeing.

INTERFACING A GPS MODULE

Page 36: Gps Based Real Time Vehicle Tracking System

36 | P a g e

GPS Receivers In general, GPS receivers are composed of an antenna, tuned to the frequencies transmitted by the satellites, receiver-processors, and a highly stable clock (often a crystal oscillator). They may also include a display for providing location and speed information to the user. A receiver is often described by its number of channels: this signifies how many satellites it can monitor simultaneously. Originally limited to four or five, this has progressively increased over the years so that, as of 2007, receivers typically have between 12 and 20 channels. GPS receivers may include an input for differential corrections, using the RTCM SC-104 format. This is typically in the form of an RS-232 port at 4,800 bit/s speed. Many GPS receivers can relay position data to a PC or other device using the NMEA 0183 protocol. Although this protocol is officially defined by the National Marine Electronics Association (NMEA),[60] references to this protocol have been compiled from public records, allowing open source tools like GPSD to read the protocol without violating intellectual property laws. Other proprietary protocols exist as well, such as the SIRF and MTK protocols. Receivers can interface with other devices using methods including a serial connection, USB, or Bluetooth. NMEA Protocol NMEA 0183 is a combined electrical and data specification for communication between marine electronic devices such as echo sounder, sonars, anemometer, gyrocompass, autopilot, GPS receivers and many other types of instruments. It has been defined by, and is controlled by, the U.S.-based National Marine Electronics Association. The NMEA 0183 standard uses a simple ASCII, serial communications protocol that defines how data is transmitted in a "sentence" from one "talker" to multiple "listeners" at a time. Through the use of intermediate expanders, a talker can have a unidirectional conversation with a nearly unlimited number of listeners, and using multiplexers, multiple sensors can talk to a single computer port.

At the application layer, the standard also defines the contents of each sentence (message) type so that all listeners can parse messages accurately. Serial configuration (data link layer) Typical Baud rate 4800 Data bits 8 Parity None Stop bits 1 Handshake None

Page 37: Gps Based Real Time Vehicle Tracking System

37 | P a g e

Application layer protocol rules:

1. Each message's starting character is a dollar sign.

2. The next five characters identify the talker (two characters) and the type of message (three characters).

3. All data fields that follow are comma-delimited.

4. Where data is unavailable, the corresponding field contains NULL

bytes (e.g., in "123, , 456", The double comma between 3 and 4 is telling the listener the second field's data is unavailable).

5. The first character that immediately follows the last data field character is an asterisk, but it is only included if a checksum is supplied.

6. The asterisk is immediately followed by a two-digit checksum representing a hexadecimal number. The checksum is the exclusive OR of all characters between the $ and *. According to the official specification, the checksum is optional or most data sentences, but is compulsory for RMA, RMB, and RMC (among others).<CR><LF> ends the message.

As an example, a waypoint arrival alarm has the form: $GPAAM, A, A, 0.10, N, WPTNME*32 where: GP Talker ID (GP for a GPS unit, GL for a GLONASS) AAM Arrival alarm A Arrival circle entered A Perpendicular passed 0.10 Circle radius N Nautical miles WPTNME Waypoint name *32 Checksum data

Here we are going to use GPRMC Sentences only as it is the most efficient format to retrieve Latitude, Longitude, Altitude, Time and Velocity.

Page 38: Gps Based Real Time Vehicle Tracking System

38 | P a g e

THE GPRMC SENTENCE

This sentence, known as the "Recommended Minimum" sentence, is the most common sentence transmitted by GPS devices. This one sentence contains nearly everything a GPS application needs: latitude, longitude, speed, bearing, satellite-derived time, fix status and magnetic variation. Sentence Example: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A Sentence Contents: The GPRMC sentence consists of twelve comma-delimited words: The Command Word: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A The command word indicates that the sentence is to be interpreted as a recommended minimum message. Satellite-Derived Time: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A GPS devices are able to calculate the current date and time using GPS satellites (and not the computer's own clock, making it useful for synchronization). This word stores the current time, in UTC, in a compressed form "HHMMSS.XXX," where HH represents hours, MM represents minutes, SS represents seconds, and XXX represents milliseconds. The above value represents 04:03:02.663 AM UTC. Satellite Fix Status: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A When the signals of at least three GPS satellites become stable, the device can use the signals to calculate the current location. The device is said to be "fixed" when calculations of the current location are taking place. Similarly, the phrases "obtaining a fix" or "losing a fix" speak of situations where three signals become stable or obscured, respectively.

A value of "A" (for "active") indicates that a fix is currently obtained, whereas a value of "V" (for "inValid") indicates that a fix is not obtained.

Latitude Decimal Degrees: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A The latitude represents the current distance north or south of the equator. This word is in the format "HHMM.M" where HH represents hours and MM.M represents minutes. A comma is implied after the second character. This value is used in conjunction with the longitude to mark a specific point on Earth's surface. This sentence says that the current latitude is "39°39.7'N".

Page 39: Gps Based Real Time Vehicle Tracking System

39 | P a g e

Latitude Hemisphere: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A This word indicates if the latitude is measuring a distance north or south of the equator. A value of "N" indicates north and "S" indicates south. This sentence says that the current latitude is "39°39.7'N". Longitude Decimal Degrees: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A The longitude represents the current distance east or west of the Prime Meridian. This word is in the format "HHHMM.M" where HHH represents hours and MM.M represents minutes. A comma is implied after the third character. This value is used in conjunction with the latitude to mark a specific point on Earth's surface. This sentence says that the current longitude is "105°06.6'W". Longitude Hemisphere: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A This word indicates if the longitude is measuring a distance east or west of the Prime Meridian. A value of "E" indicates east and "W" indicates west. This sentence says that the current longitude is "105°06.6'W". Speed: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A This word indicates the current rate of travel over land, measured in knots. Bearing: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A This word indicates the current direction of travel over, measured as an "azimuth." An azimuth is a horizontal angle around the horizon measure in degrees between 0 and 360, where 0 represents north, 90 represents east, 180 represents south, and 270 represents west. This word indicates that the direction of travel is 358.86°, or close to north. UTC Date: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A GPS devices maintain their own date and time calculated from GPS satellite signals. This makes GPS devices useful for clock synchronization since the date and time are independent of the local machine's internal clock. This word contains two-digit numbers for days, followed by months and years. In the example above, the date is August (08) 20th (20), 2004 (04). The two-digit year is added to 2000 to make a full year value. The Checksum: $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A The checksum is used to identify errors in the data which may have occurred during transmission. For more information on NMEA checksums, please refer to Calculating and Validating NMEA Checksums.

Page 40: Gps Based Real Time Vehicle Tracking System

40 | P a g e

GSM MODEM A GSM modem is a specialized type of modem which accepts a SIM card, and operates over a subscription to a mobile operator, just like a mobile phone. From the mobile operator perspective, a GSM modem looks just like a mobile phone. When a GSM modem is connected to a computer, this allows the computer to use the GSM modem to communicate over the mobile network. While these GSM modems are most frequently used to provide mobile internet connectivity, many of them can also be used for sending and receiving SMS and MMS messages. A GSM modem can be a dedicated modem device with a serial, USB or Bluetooth connection, or it can be a mobile phone that provides GSM modem capabilities. A GSM modem exposes an interface that allows user applications to send and receive messages over the modem interface. The mobile operator charges for this message sending and receiving as if it was performed directly on a mobile phone. To perform these tasks, a GSM modem must support an ‚extended AT command set‛ for sending/receiving SMS messages, as defined in the ETSI GSM 07.05 and 3GPP TS 27.005 specifications. GSM modems can be a quick and efficient way to get started with SMS, because a special subscription to an SMS service provider is not required. In most parts of the world, GSM modems are a cost effective solution for receiving SMS messages, because the sender is paying for the message delivery. A GSM modem can be a dedicated modem device with a serial, USB or Bluetooth connection. To begin, a standard GSM SIM card is inserted into the modem and connected to an available Serial port on a computer. The purpose of these GSM Modem is to link the In-Vehicle Device with Central Server wirelessly through RF Link. This is done in the following manner: Here we interface the mobile device with a GSM Modem (M1 say) and the central server with another GSM Modem (M2 say). 1. The modem M1 will send the GPRMC sentences received from GPS Module through an SMS to the modem M2.

2. Whenever the SMS at M2 is received at the central server end, it will be pushed to the serial port of a computer. 3. A program waiting for the string will read it from serial port and write it to a file in plain text. 4. A php web based program will read that file at regular intervals and display the parsed message to the web browser.

Page 41: Gps Based Real Time Vehicle Tracking System

41 | P a g e

Sending SMS A sample AT Command to send GPRMC sentence to the remote server bearing a subscriber number. AT+CMGW="9477056987"\n > $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A\z Recieving SMS A sample AT Command to send GPRMC sentence to the remote server bearing a subscriber number. AT+CMGL="ALL" This lists all recieved SMS in the inbox. Response from the modem : +CMGL: 1,"REC READ","+919477056987",,"06/11/11,00:30:29+32" $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A

Page 42: Gps Based Real Time Vehicle Tracking System

42 | P a g e

B) TRACKING SERVER: Receives information from IN-VEHICLE unit and displays it on the browser. It can also store the location information on a log file at different times. The server also provides a TABLE LOOKUP mechanism for quick retrieval of information.

IMPLEMENTATION OF SERVER

Page 43: Gps Based Real Time Vehicle Tracking System

43 | P a g e

TIMING DIAGRAM FOR DATA STORE AND DISPLAY IN SERVER

Page 44: Gps Based Real Time Vehicle Tracking System

44 | P a g e

CODE FOR INSERTION OF DATA INTO DATABASE

<?php $link=mysql_connect("localhost","root",""); if(mysql_select_db("gprmc",$link)) { echo "Connected to localhost"; $file = "data.txt"; $data; $fp = fopen($file, "r+"); /*Reading from file where output of GPS is written*/ while(!feof($fp)) { $data = fgets($fp, 1024); } fclose($fp); if($data) { /*Inserting into database*/ $query="Insert into gpsdata "."(data)"."values "."('$data')"; if(mysql_query($query,$link)) { echo "Successfully inserted "; mysql_close($link); } } } else die ("Connection failed"); ?>

CODE FOR RETRIEVING FROM DATABASE & DISPLAYING ON BROWSER

<?php $link=mysql_connect("localhost","root",""); if(mysql_select_db("gprmc",$link)) { echo "Connected to localhost"; /*Reteiving from database*/ $result=mysql_query("Select * from gpsdata order by id DESC",$link); if ($ro = mysql_fetch_assoc($result)) { echo $ro['data'] . "<br />\n"; $str=explode(",",$ro['data']); $var = array(0=>'Format',1=>'Time Stamp hhmmss', 2=>'validity - A-ok, V-invalid‘,3=>'current Latitude',4=>'North/South',5=>'current Longitude‘,6=>'East/West',7=>'Speed in knots',8=>'True course‘

Page 45: Gps Based Real Time Vehicle Tracking System

45 | P a g e

,9=>'Date Stamp ddmmyy‘,10=>'Magnetic variation degrees (Easterly var. subtracts from true course)‘,11=>'East/West*checksum'); /*displaying GPS data on user interface */ for($i=0;$i<count($str);$i++) echo "$var[$i] = $str[$i] <br>"; } mysql_close($link); } else die ("Connection failed"); ?>

SAMPLE OUTPUT OF TRACKING SERVER

Page 46: Gps Based Real Time Vehicle Tracking System

46 | P a g e

CONCLUSION

This project has been done with proper understanding of Embedded Systems, use of Microcontrollers and various equipments to fulfill the prime objective of Development of a low cost GPS based Vehicle Tracking System' to be used in a fixed path Railway tracks. A good knowledge on 8051 microcontrollers, Hardware programming techniques, construction of a programmer circuit and concepts of In Application Programming (IAP) and programming the peripherals like LCD and UART has been acquired.

The practical use of a GPS Receiver module which would provide us with GPRMC sentences would cost around twenty six hundred rupees. Moreover this module was currently unavailable in the market. So as a substitute to this, a dummy software module generating the GPRMC sentences in accordance with standard NMEA protocol was used. Though the data generated by it might not be valid in the real world but it maintains the format specifications. The In-Vehicle device exposes a UART interface (TTL Logic Level) which can be connected with any GPS Module's UART at any moment to receive the data practically.

The logical view said that the In-Vehicle Device and the Central Tracking Server when placed remotely will be connected through RF link using the GSM network and data exchange will take place through SMS. But the high price of a generic GSM Modem made us to use wired linkage between the two. We used a standard DB9 Cable to connect the In-Vehicle Device with a Personal Computer's Serial Port. Thus any two standard GSM Modem can be connected at both ends of the system to achieve mobility of the IN-Vehicle device as both the ends expose UART interface in RS-232 Logic Level.

One software module runs on the In-Vehicle Device which gathers GPRMC sentences, Displays it into LCD Display and sends it to Serial Port. Another Software module polls the serial port for data. Whenever it receives the GPRMC Sentence, it reads it and stores it to a plain text file. Another software module checks the plain text file and reads newly arrived data and sends it to database log and parses it to display it into the web browser.

Thus the project objective has been achieved with the fulfillment criteria of building the hardware, programmer board and programming the device to work correctly as per the logical view designed.

Page 47: Gps Based Real Time Vehicle Tracking System

47 | P a g e

FUTURE SCOPE OF WORK

This project can provide a huge scope of work and research on learning Embedded System, deployment of a good product for the betterment of manking by reducing human effort, increasing accuracy and transparency in Management of Public Transport Systems. The In-Vehicle Device can be equipped with a Patch Antennae based GPS Module serially connected with the Microcontroller. It will provide us with location in terms of Latitude , Longitude , Altitude and other data like Direction of movement, speed over ground, Time etc. Another proceeding is to add one GSM Modem to In-Vehicle Device and another to Central Server. The software modules will need to be updated with AT Command set in order to communicate with these GSM Modems. This will make the device mobile and the server can track a Vehicle anywhere on earth with the help of GSM networks. With the addition of GSM modems , the In-Vehicle Device can get an Analog-To-Digital Converter and a whole set of Sensors to read basic physical entities of a vehicle to monitor its performance especially on trains. The communication between In-Vehicle Device and the Central Tracking server can be made Half-Duplex in order to send controll signals to the remote vehicle in case of an Emergency.

REFERENCES

• Wikipedia • Media Tek MT3318 Datasheet and Application Notes. • P89V51RD2 Datasheet. • GPS For Dummies by Joel McNamara-Wiley Publishing • G. T. French (1996) Understanding the GPS. 1st Edition.

Bethesda, Geo-Research Inc. • Receivers. 1st Edition. John Willey & Sons Inc • J.B. TSUI (2000) Fundamentals of Global Positioning

System • The 8051 Microcontroller And Embedded Systems by

Muhammad Ali Mazidi • Vehicle Tracking Systems Overview

http://www.roseindia.net/technology/vehicletracking/VehicleTrackingSystems.shtml