GPS and Location Sensors
GPS and location sensors are used to determine where an object, person, vehicle, or device is located.
They can provide information such as:
- 📍 Latitude
- 📍 Longitude
- 🗺️ Location
- 🚗 Speed
- ⛰️ Approximate altitude
- 🧭 Time
- 🛰️ Satellite information
- 🚨 Movement/route information
They are widely used in:
- Vehicle tracking
- Navigation
- Drones
- Delivery systems
- Agriculture
- Fleet management
- IoT
- Emergency systems
- Asset tracking
- Robotics
1 What Is GPS?
GPS = Global Positioning System
GPS is a satellite-based positioning system developed and operated by the United States.
A GPS receiver determines its position by receiving signals from satellites.
Basic concept:
🛰 Satellite 1 \ \ 🛰 Satellite 2 -----> GPS Receiver / / 🛰 Satellite 3
The receiver calculates its position based on signals received from multiple satellites.
2 What Is GNSS?
GNSS = Global Navigation Satellite System
GNSS is the broader term for satellite navigation systems.
Examples include:
| System | Country/Region |
|---|---|
| GPS | United States |
| Galileo | European Union |
| GLONASS | Russia |
| BeiDou | China |
| NavIC | India |
| QZSS | Japan |
A modern GNSS receiver may be able to use signals from multiple systems.
Therefore:
GPS ⊂ GNSS
GPS is one specific satellite navigation system, while GNSS is the broader category.
3 How GPS Determines Location
A GPS receiver measures the travel time of signals from satellites.
Each satellite broadcasts information including:
- Satellite position
- Precise timing information
The receiver uses signals from multiple satellites to calculate its position.
Conceptually:
Satellite A ↓ Distance A \ \ GPS Receiver / / Distance B ↑ Satellite B
With enough satellite measurements, the receiver can determine its position.
This process is called trilateration.
It is more accurate to describe GPS positioning as trilateration rather than triangulation because the system uses measured distances.
4 Why Multiple Satellites Are Needed
One satellite:
Satellite ↓ ? ? ? ? ?
doesn't provide enough information to determine a unique 3D position.
With multiple satellites:
🛰 1 \ \ 📍 / \ / \ 🛰 2 🛰 3
the receiver can narrow down its position.
In practical GNSS positioning, the receiver typically needs signals from at least four satellites for a full position and receiver-clock solution, although more satellites can improve reliability and accuracy.
5 Latitude and Longitude
GPS commonly reports geographic coordinates using:
Latitude
Determines position north or south of the equator.
90° N │ │ 0° ───── Equator │ │ 90° S
Longitude
Determines position east or west of the prime meridian.
180° W ← 0° → 180° E
A location can therefore be represented as:
Latitude : 26.xxxx Longitude: 85.xxxx
6 GPS Coordinate Example
A GPS module may output something similar to:
Latitude : 26.XXXX Longitude: 85.XXXX
Together:
26.XXXX, 85.XXXX
can represent a geographic location.
A mapping service can use these coordinates to display the point on a map.
7 GPS Module
A GPS module is an electronic board containing a GNSS receiver and antenna.
Common hobby modules include:
- NEO-6M
- NEO-M8N
- Various u-blox GNSS modules
A typical module looks conceptually like:
┌────────────────────────┐ │ GPS MODULE │ │ │ │ GNSS Receiver │ │ + │ │ Antenna │ └──────────┬─────────────┘ │ UART │ ESP32
8 NEO-6M GPS Module
The NEO-6M is a very popular educational GPS module.
Typical pins include:
| Pin | Function |
|---|---|
| VCC | Power |
| GND | Ground |
| TX | Serial transmit |
| RX | Serial receive |
The exact voltage behavior depends on the specific breakout board, so check its documentation before powering it.
9 GPS + ESP32
GPS modules commonly communicate with microcontrollers using UART serial communication.
Example:
GPS TX ─────────→ ESP32 RX GPS RX ─────────→ ESP32 TX GND ─────────→ GND
For receiving GPS data, the most important connection is usually:
GPS TX → ESP32 RX
The ESP32 can read the serial data and extract:
- Latitude
- Longitude
- Time
- Speed
- Altitude
- Satellite information
10 UART Communication
UART is a serial communication protocol.
Conceptually:
GPS │ │ Serial data ↓ ESP32
GPS data may look like:
$GPGGA,... $GPRMC,...
These are called NMEA sentences.
11 NMEA Sentences
GPS/GNSS receivers commonly output data using NMEA-formatted sentences.
Examples:
$GPGGA $GPRMC $GPGSA $GPGSV
Different sentences contain different information.
GGA
Often contains:
- Position
- Fix information
- Number of satellites
- Altitude
RMC
Often contains:
- Position
- Time
- Date
- Speed
- Course
GSV
Contains information about satellites in view.
12 Example GPS Data
A raw NMEA sentence may look like:
$GPRMC,...
A GPS library can parse this raw information and provide easy-to-use values:
Latitude = ... Longitude = ... Speed = ... Time = ...
For beginners, using a GPS parsing library is usually much easier than manually parsing every NMEA field.
13 GPS Fix
A GPS receiver doesn't immediately know its position after powering on.
It needs to acquire satellite signals.
The process is often called obtaining a:
GPS/GNSS fix
Status may be:
Searching... Searching... Searching... Fix acquired!
Once a valid fix is obtained, the receiver can provide location information.
14 Cold Start, Warm Start and Hot Start
GPS receivers can take different amounts of time to acquire a fix.
Cold Start
The receiver has little or no recent satellite information.
Power ON ↓ Search satellites ↓ Calculate position ↓ Fix
This can take longer.
Warm/Hot Start
The receiver already has useful recent information.
Power ON ↓ Use recent information ↓ Find satellites faster ↓ Fix
Actual acquisition time depends heavily on receiver, antenna, environment, and satellite visibility.
15 GPS Accuracy
GPS accuracy isn't always the same.
Under good outdoor conditions, a basic consumer GNSS receiver may provide position accuracy on the order of a few meters.
But accuracy can become worse because of:
- Buildings
- Trees
- Mountains
- Indoor environments
- Multipath reflections
- Poor antenna placement
- Atmospheric effects
- Weak satellite geometry
Example:
Open sky ↓ Better reception ↓ Better position
Compared with:
Inside building ↓ Weak signals ↓ Poor/no fix
16 GPS Does Not Work Well Indoors
GPS/GNSS signals arriving at Earth's surface are relatively weak.
Therefore:
Outdoor + clear sky ↓ GOOD
but:
Deep indoor / basement ↓ POOR
For indoor positioning, technologies such as:
- Wi-Fi
- Bluetooth
- UWB
- RFID
- BLE beacons
may be more appropriate depending on the application.
17 GPS Speed
GPS can also estimate speed.
For example:
Speed = 42 km/h
This is useful for:
- Vehicle tracking
- Fleet monitoring
- Cycling
- Drones
- Logistics
The receiver can calculate movement based on changes in position and/or Doppler measurements.
18 GPS Altitude
GPS/GNSS receivers can also provide altitude estimates.
Example:
Latitude : ... Longitude: ... Altitude : 250 m
However, altitude from a basic GNSS receiver can be less accurate than horizontal position.
For high-precision elevation measurement, specialized systems may be required.
19 GPS Heading
When a receiver is moving, it can estimate the direction of travel.
Example:
Heading: 90°
Approximately:
0° → North 90° → East 180° → South 270° → West
Be careful:
A single stationary GPS receiver generally cannot reliably determine which direction the device itself is facing. Heading from position is most meaningful while moving.
For accurate orientation while stationary, a magnetometer/IMU is often used.
20 GPS Tracking System
A simple GPS tracker can be built with:
- ESP32
- GPS module
- Battery
- GSM/LTE or Wi-Fi connectivity
- Cloud/server
Architecture:
GPS │ ↓ ESP32 │ Location data │ ↓ Internet/Cellular │ ↓ Server │ ↓ Web/Mobile App
Example:
Vehicle ↓ GPS ↓ ESP32 ↓ Internet ↓ Server ↓ Map
21 GPS Vehicle Tracker
A vehicle tracker can send:
Latitude Longitude Speed Time
to a server.
Dashboard:
┌────────────────────────────┐ │ VEHICLE TRACKER │ ├────────────────────────────┤ │ Status : ONLINE │ │ Speed : 38 km/h │ │ Lat : xx.xxxx │ │ Long : xx.xxxx │ │ GPS : 9 satellites │ └────────────────────────────┘
A map can then display the vehicle's approximate position.
22 GPS + Geofencing
Geofencing means creating a virtual geographic boundary.
For example:
┌─────────────────┐ │ GEOFENCE │ │ │ │ 🚗 │ │ │ └─────────────────┘
If the vehicle leaves the area:
Vehicle leaves boundary ↓ ESP32 detects location ↓ Outside geofence ↓ Send alert
Applications:
- School buses
- Fleet tracking
- Delivery vehicles
- Asset monitoring
- Agricultural equipment
23 GPS Distance Calculation
Suppose we have two GPS coordinates:
Point A Latitude = ... Longitude = ... Point B Latitude = ... Longitude = ...
The distance between two geographic coordinates can be calculated using formulas such as the Haversine formula.
Conceptually:
Point A ● \ \ Distance \ ● Point B
This allows an application to determine:
- Distance traveled
- Distance from a destination
- Distance from a geofence
- Nearest location
24 GPS + IoT
GPS becomes much more powerful when combined with IoT connectivity.
GPS ↓ ESP32 ↓ Internet ↓ Cloud Server ↓ Web Dashboard
The dashboard could display:
Current Location Speed Route Time Battery GPS Status
25 GPS + Google Maps Style Link
A device can generate coordinates:
Latitude = XX.XXXX Longitude = YY.YYYY
A mapping application can use those coordinates to display a location.
Conceptually:
GPS coordinates ↓ Map service ↓ 📍 Marker
This is useful for:
- Vehicle tracking
- Delivery tracking
- Field workers
- Agriculture
- Asset tracking
26 GPS in Agriculture
GPS is extremely useful in smart agriculture.
Example:
GPS ↓ Agricultural Vehicle ↓ Field Mapping
Applications:
- Farm mapping
- Precision agriculture
- Tractor guidance
- Field surveying
- Route tracking
- Crop monitoring
For example, GPS can help record where a soil sample was collected:
Sample #01 Location: GPS coordinates Sample #02 Location: GPS coordinates
27 GPS + Soil Sensors
You can combine the previous topic with GPS.
ESP32 │ ┌────────────┼────────────┐ ↓ ↓ ↓ GPS Soil Moisture Temp │ │ │ └────────────┼────────────┘ ↓ Database
The system could record:
Location A → Soil moisture 35% Location B → Soil moisture 48% Location C → Soil moisture 22%
This is useful for creating a geographical soil-monitoring map.
28 GPS in Drones
GPS is commonly used in outdoor drones for:
- Position estimation
- Navigation
- Return-to-home
- Waypoint missions
- Geofencing
Conceptually:
GPS ↓ Flight Controller ↓ Motors ↓ Drone
The flight controller combines GPS with other sensors such as:
- IMU
- Accelerometer
- Gyroscope
- Magnetometer
- Barometer
GPS alone isn't enough for stable drone flight.
29 GPS + IMU
GPS provides global position.
An IMU provides rapid motion/orientation information.
GPS │ ↓ Position │ ├───────┐ │ │ ↓ ↓ Fusion IMU │ ↓ Motion/Orientation
Combining them is called sensor fusion.
This can provide a more robust estimate than relying on one sensor alone.
30 GPS vs Compass
These are often confused.
GPS
Answers:
Where am I?
Latitude Longitude
Compass/Magnetometer
Answers approximately:
Which direction am I facing?
North East South West
So:
GPS → Location Compass → Orientation
A smart navigation system may use both.
31 GPS vs Wi-Fi Positioning
| GPS/GNSS | Wi-Fi Positioning |
|---|---|
| Satellite-based | Network/access-point based |
| Excellent outdoors | Useful indoors |
| Works without local Wi-Fi | Requires known Wi-Fi environment |
| Can provide global coordinates | Often provides estimated location |
| Poorer indoors | Can work inside buildings |
Modern systems often combine multiple positioning technologies.
32 Simple ESP32 GPS Example
A GPS module can be connected to an ESP32 using a hardware serial port.
Example:
#include <TinyGPSPlus.h> TinyGPSPlus gps; HardwareSerial GPSSerial(1); void setup() { Serial.begin(115200); GPSSerial.begin( 9600, SERIAL_8N1, 16, // RX 17 // TX ); Serial.println("GPS Starting..."); } void loop() { while (GPSSerial.available()) { char c = GPSSerial.read(); gps.encode(c); if (gps.location.isUpdated()) { Serial.print("Latitude: "); Serial.println(gps.location.lat(), 6); Serial.print("Longitude: "); Serial.println(gps.location.lng(), 6); if (gps.speed.isValid()) { Serial.print("Speed: "); Serial.print(gps.speed.kmph()); Serial.println(" km/h"); } if (gps.altitude.isValid()) { Serial.print("Altitude: "); Serial.print(gps.altitude.meters()); Serial.println(" m"); } Serial.println("----------------"); } } }
Here:
GPS TX → ESP32 GPIO16 (RX) GPS RX → ESP32 GPIO17 (TX) GND → GND
If you only need to receive GPS data, the GPS TX → ESP32 RX connection is the essential one.
33 Why GPS Gives No Data
This is one of the most common beginner problems.
Check 1: TX/RX
Remember:
GPS TX → ESP32 RX GPS RX → ESP32 TX
not:
TX → TX RX → RX
Check 2: Baud Rate
Many modules initially use a common baud rate such as:
9600
but this can vary depending on the module configuration.
Check 3: Antenna
Make sure the antenna is properly connected and oriented as required by the module.
Check 4: Outdoor Testing
Test outdoors with a reasonably clear view of the sky.
Check 5: Power
An unstable supply can cause problems with satellite acquisition and serial communication.
34 Why GPS Is Slow to Get a Fix
Possible reasons:
- First startup
- Poor satellite visibility
- Indoor environment
- Trees/buildings
- Weak antenna
- Incorrect configuration
- Poor power supply
Try:
Outdoor ↓ Antenna facing sky ↓ Wait ↓ Satellite acquisition ↓ Fix
35 GPS Accuracy Problems
GPS can show:
Point A ↓ Point B ↓ Point C
even when the device is stationary.
This can happen due to:
- Satellite geometry
- Multipath
- Atmospheric effects
- Receiver limitations
- Signal noise
Therefore, don't assume every small coordinate change means the device physically moved.
Filtering can help.
36 GPS Data Filtering
Suppose you receive:
Location 1 Location 2 Location 3 Location 4
You can apply:
- Moving average
- Median filtering
- Outlier rejection
- Kalman filtering
- Sensor fusion
For advanced projects:
GPS + IMU ↓ Kalman Filter ↓ Better position estimate
37 GPS-Based Emergency Tracker
A useful IoT project:
GPS ↓ ESP32 ↓ Emergency Button ↓ Location ↓ Internet/Cellular ↓ Emergency Contact
When the button is pressed:
SOS button ↓ Get GPS coordinates ↓ Send location ↓ Alert
Such systems require reliable communication and careful privacy/security design.
38 GPS Sensor Comparison
| Module/Technology | Main use |
|---|---|
| NEO-6M | Beginner GPS projects |
| NEO-M8N | Multi-GNSS projects |
| Modern GNSS modules | Improved positioning |
| GPS + GSM/LTE | Remote tracking |
| GPS + ESP32 | IoT location projects |
| GPS + IMU | Navigation/robotics |
| GPS + cellular | Vehicle tracking |
39 Complete GPS IoT Tracker
A practical architecture:
GPS │ ↓ ESP32 │ ┌───────────┼───────────┐ ↓ ↓ ↓ OLED Button Battery │ │ └───────────┼───────────┘ ↓ GSM/LTE/Wi-Fi ↓ Internet ↓ Cloud Server ↓ Web Dashboard ↓ Map 📍
Dashboard:
================================= GPS VEHICLE TRACKER ================================= GPS Status : FIXED Latitude : XX.XXXXXX Longitude : YY.YYYYYY Speed : 42 km/h Altitude : XXX m Status : MOVING =================================
40 Key Points
- GPS is a satellite-based positioning system.
- GNSS is the broader category containing GPS and other satellite navigation systems.
- GPS receivers can provide:
- Latitude
- Longitude
- Speed
- Approximate altitude
- Time
- GPS positioning uses trilateration based on satellite measurements.
- Multiple satellites are required for a reliable position solution.
- NMEA is a common format for GPS receiver output.
- UART is commonly used to connect GPS modules to Arduino/ESP32.
- NEO-6M is a popular beginner GPS module.
- GPS generally works much better outdoors than indoors.
- GPS accuracy can be affected by buildings, trees, multipath, atmosphere, and satellite geometry.
- GPS can be combined with ESP32 + cellular/Wi-Fi + cloud to create tracking systems.
- Geofencing allows a system to detect when a device leaves a defined area.
- GPS and compass are different:
- GPS → location
- Magnetometer → orientation
- GPS + IMU can provide more robust navigation through sensor fusion.
- For high-precision applications, ordinary hobby GPS modules may not be sufficient; specialized GNSS techniques such as RTK may be required.