Real Time GPS Tracker with Integrated Google Maps
This project describes how you can build a mobile real time GPS tracker with integrated Google Maps. I began this project mainly to see if I can integrate all the different pieces of hardware and software to make a workable solution, and it took some time, but finally when everything was said and done, it looked pretty cool. I tore down everything and rebuilt it from scratch, making detailed notes and documenting the process.
When I started building this, I didn’t have any particular application in mind, but now that I have built it, I can see myself using it different applications, particularly if I can get to lower the cost. Even if you didn’t have any application in mind, it would be a fun weekend project, you never know, you might find the knowledge gathered during the process useful one day in some form or other.
How it works?
How much does it cost?
The costs are all associated with the hardware components. There is no software costs involved, since everything is open source. The code is licensed under Creative Commons, so you’re free to use the code in this project in whatever applications you wish.
The total estimated cost is around $200. All the components can be purchased from Sparkfun.
The hardware consists of three main components.
The micro-controller is the central controller for the whole unit. I chose the Arduino Duemilanove, which is an open source electronics prototyping board based on the Atmel ATMega328 8 bit micro-controller running at 16 hz. This newer version of this board can be purchased from here and costs around $30. It’s called Arduino Uno and works just as well.
The GSM/GPRS Module is based on SpreadTrum’s SM5100B. The SM5100B is a miniature, quad-band GSM 850/EGSM 900/DCS 1800/PCS 1900 module. This module features two UARTS, an SPI interface, and two 10-bit ADC’s. This board can be purchased from here and costs about $100.
The GPS Module is USGlobalSat EM-406A which is based on the spectacular SiRF Star III chipset. It outputs positioning and timing date in NMEA 0183 and SiRF binary protocol and has a positioning accuracy of 10 meters without and 5 meters with WAAS. You have to buy a separate interface board and the GPS unit and connect the two. The interface board can be purchased from here and costs $16. The GPS receiver can be purchased from here and costs $ This unit can be purchased from here and costs $60.
If you are using the hardware components I used, the assembly is pretty staightforward. Solder the Arduino stackable headers (can be bought from here) on the GPS shield and the GSM shield. Connect the GPS module to the GPS shield and stack it on top of the GSM board. Stack the two boards on top of the Arduino board.
This is the code for the ATMega328P microcontroller on the Arduino board. Follow the directions at http://www.arduino.cc/ on how to compile and load the code onto the Arduino board. The code uses additional libraries. They are:
All 3 libraries can be downloaded from http://arduiniana.org/libraries/. Follow the instructions to install them.
The following should be noted:
The line: cell.println(“AT+CGDCONT=1,\”IP\”,\”isp.cingular\””);establishes a PDP (Packet Data Protocol) context with AT&T‘s APN (Access Point Name). If your cellular provider is not AT&T, replace the string “isp.cingular” with the appropriate APN for your cellular provider. In the line: cell.println(“AT+SDATACONF=1,\”TCP\”,\”your_ip_address\”,32000″); Change this to the IP Address for your TCP Server.
The TCP Server is coded in python. It’s very simple in operation, basically opens up a TCP port and waits for the connection from the GPS Tracker’s GSM module. Once it receives, the connection, it accepts it and as and when the GPS packets comes, in it parses it out and stores the Latitude and Longitude in a MySQL table (which we’ll be creating in the next section). The TCP server will run on any python 2.x, download it from http://www.python.org/. It’s worth noting that Python 3 has major syntax changes, therefore the code will not run until you tweak it to make it compatible with Python 3. It uses a python library called MySQLdb, which you can download from MySQLdb from http://www.zope.org/Members/adustman/Products/MySQLdb . Follow the instructions to install it onto your python installation.
Type the following code into a file called tcpServer.py and you can run it by typing python tcpServer.py on the command prompt. Replace ‘your_ip_address’ with the IP Address of the machine you’re running the TCP Server on. Note that if your machine in on the LAN and you have a router/firewall, you might have to port forward TCP port 32000 to the IP Address of the machine on which the TCP Server is running. Otherwise, packets coming in from outside your network will never reach the TCP Server machine. Don’t run the server code now, we still have lots of coding to do. Save the file and move on to the next section.
Also note that, you don’t have to use TCP. You can also use UDP or any other transport protocol. TCP packets have a 20 byte header whereas UDP has only 8 bytes. TCP also is a complex protocol and is an overkill for this application. I used it, but feel free to use UDP.
A MySQL database is used to store the GPS Co-ordinates received. If you are using Ubuntu, as I did, you can use the apt-get utility to download and install the MySQL server as follows. I used Version 5.1 of MySQL server.
sudo apt-get install mysql-server-5.1
The Installer will ask for a root password. Enter your root password. This will be needed to log on to the MySQL database later as root.
You also need the development (header) files of the MySQL client. You can install it by entering:
sudo apt-get install libmysqlclient-dev
Now, we’ll setup the MySQL database. First log on using the username and password you set earlier. Enter
mysql -p -u user
Enter the root password when prompted.
It’s usually not a good idea to work on a MySQL database as root, so we’ll make another user, grant all privileges and than we’ll use that to make further changes. The mysql prompt is shown below as mysql>. Replace user, host and password with your values. If the mySQL database is on the same machine, you can enter ‘localhost’ for ‘host’. For example, [email protected].
msql>; GRANT ALL PRIVILEGES ON *.* TO user@’host’ IDENTIFIED BY ‘password’;
Let’s now create a database. We’ll call it gmap. Enter:
mysql>; CREATE DATABASE gmap;
Now, we can see if the database has been created, by entering:
mysql>; show databases;
You should see something like this:
The table shows the current databases in MySQL. The other entries might be different in your system, but as long as you have the gmap database, you’re doing fine so far.
Next change to the gmap database by entering:
mysql>; use gmap;
Let’s now create a table to hold our lat/long in the gmap database we created.
mysql>; CREATE TABLE gmaptracker (
->; id int(8) NOT NULL auto_increment,
->; lat double(13,10) NOT NULL default 0.0000000000,
->; lon double(13,10) NOT NULL default 0.0000000000,
->; PRIMARY KEY (id)
->; ) TYPE=InnoDB;
The table we created can be viewed by entering:
mysql>; show tables;
The output will show the table we just created.
If you want to see the fields in the gmaptracker table, enter:
mysql>; desc gmaptracker;
The output will show the fields in the table gmaptracker which we created.
Finally, since the table is now empty, when we issue:
mysql>; select * from gmaptracker;
it should show:
Congratulations! You have a working MySQL database and a table in it ready to accept the GPS co-ordinates.
For more detail: Real Time GPS Tracker with Integrated Google Maps
From Schematic to PCB Production, Just Need One Tool
Free Circuit Design Software: learn to use Editor quickly and easily
Cheapest PCB: 10pcs 2-layers 10cm×10cm only $8.21, 3-day build time, 100% E-test
This Post / Project can also be found using search terms:
- realtime gps tracker arduino google maps