top of page
Writer's pictureSanskruti Ashtikar

GPS-Based Vehicle Tracking System Using PIC Microcontroller

Updated: 6 days ago

Introduction


With the advent of GPS (Global Positioning System) technology, vehicle tracking has become increasingly accessible and reliable. By integrating a GPS module with a PIC microcontroller, you can create a powerful vehicle tracking system that provides real-time location data. This article will guide you through the design, implementation, and coding aspects of a GPS-based vehicle tracking system using a PIC microcontroller.





Components Required


  1. PIC Microcontroller (e.g., PIC16F877A)

  2. GPS Module (e.g., NEO-6M)

  3. GSM Module (optional for SMS-based tracking)

  4. LCD Display (16x2)

  5. Power Supply (5V and 3.3V)

  6. Crystal Oscillator (20 MHz)

  7. Capacitors (22pF, 100µF)

  8. Resistors (1kΩ, 10kΩ)

  9. Connecting Wires

  10. PCB or Breadboard for Prototyping


System Overview


The system's core functionality revolves around the GPS module, which receives signals from satellites and calculates the geographical coordinates (latitude and longitude). The PIC microcontroller processes this data and displays it on an LCD screen. Optionally, the data can be sent via a GSM module to a mobile phone for remote tracking.


Block Diagram


  1. GPS Module: Receives and decodes satellite signals to provide location data.

  2. PIC Microcontroller: Processes GPS data and interfaces with other peripherals.

  3. LCD Display: Displays the real-time location.

  4. GSM Module (optional): Sends location data via SMS.


Circuit Diagram


[Insert a simplified circuit diagram here, showing connections between the PIC microcontroller, GPS module, LCD, and GSM module if used.]


Working Principle


  1. GPS Module: The GPS module, upon receiving satellite signals, calculates the precise geographical coordinates. The NEO-6M module, for example, outputs this data as an NMEA (National Marine Electronics Association) sentence, a standardized format for GPS data.

  2. PIC Microcontroller: The microcontroller reads the NMEA sentences from the GPS module via UART (Universal Asynchronous Receiver-Transmitter) communication. The relevant information (latitude and longitude) is parsed from these sentences.

  3. Display and Transmission:

  4. LCD Display: The parsed location data is displayed on an LCD in real-time.

  5. GSM Module (optional): The microcontroller can also interface with a GSM module to send the location data as an SMS to a predefined number, providing remote tracking capability.


Software Implementation


  1. Initializing the Microcontroller:

  2. Configure the oscillator and set up the UART communication.

  3. Initialize the LCD for displaying data.

  4. Reading GPS Data:

  5. Set up the UART to read the NMEA sentences from the GPS module.

  6. Parse the data to extract latitude and longitude information.

  7. Displaying Data:

  8. Send the extracted data to the LCD for real-time display.

  9. Optionally, format the data into an SMS message and send it using the GSM module.





Sample Code

#include <xc.h>
#include <string.h>
#include "lcd.h"
#define _XTAL_FREQ 20000000  // Define crystal frequency
// Configuration bits
#pragma config FOSC = HS   // High-speed oscillator
#pragma config WDTE = OFF  // Watchdog Timer Disable
void UART_Init(void) {
    TRISC6 = 0; // TX Pin
    TRISC7 = 1; // RX Pin
    SPBRG = 31; // Baud rate 9600 for 20MHz
    TXEN = 1;   // Enable transmitter
    SPEN = 1;   // Enable serial port
    CREN = 1;   // Enable continuous reception
}
char UART_Read(void) {
    while (!RCIF);  // Wait until data is received
    return RCREG;   // Return received byte
}
void UART_Write(char data) {
    while (!TXIF);  // Wait until the transmitter is ready
    TXREG = data;   // Transmit data
}
void GPS_Read() {
    char data;
    char buffer[100];
    int index = 0;
    
    // Clear buffer
    memset(buffer, 0, 100);
    
    while (1) {
        data = UART_Read();
        
        if (data == '$') { // Start of an NMEA sentence
            index = 0;
            memset(buffer, 0, 100); // Clear buffer
        }
        
        buffer[index++] = data;
        
        // Check if we received a GPGGA sentence (common for latitude and longitude)
        if (strstr(buffer, "$GPGGA")) {
            // Parse latitude and longitude from the buffer here
            // Display on LCD
            lcd_clear();
            lcd_goto(1, 1);
            lcd_puts("Lat:");
            // lcd_puts(parsed_latitude); // Example placeholder
            lcd_goto(2, 1);
            lcd_puts("Long:");
            // lcd_puts(parsed_longitude); // Example placeholder
            break;
        }
    }
}
void main(void) {
    UART_Init();   // Initialize UART
    lcd_init();    // Initialize LCD
    
    while (1) {
        GPS_Read(); // Continuously read and display GPS data
    }
}



Explanation of the Code


  • UART Initialization: Configures the UART for communication with the GPS module at a baud rate of 9600.

  • GPS_Read Function: Continuously reads data from the GPS module. It looks for the $GPGGA sentence, which contains latitude and longitude data.

  • LCD Display: Displays the parsed GPS data on the LCD screen.


Conclusion


A GPS-based vehicle tracking system using a PIC microcontroller is a practical project that combines embedded systems with real-time data acquisition. With a basic understanding of UART communication and GPS data parsing, this system can be expanded with additional features such as remote tracking via GSM or integration with a cloud-based platform for advanced monitoring. This project provides a foundation for building more sophisticated GPS applications.


Further Enhancements


  1. Remote Monitoring: Integrate a GSM module to send location data to a server for real-time tracking on a map.

  2. Geofencing: Program the microcontroller to trigger an alert if the vehicle exits a predefined geographical boundary.

  3. Data Logging: Store GPS data on an SD card for later analysis.

This project demonstrates how to build a GPS-based tracking system using a PIC microcontroller, providing both hands-on experience with embedded systems and a practical application of GPS technology.


Wan us to guide you through your project or make the project ?






Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 



0 views0 comments

Related Posts

See All

Comments


bottom of page