Lesson 21

GPS Navigation and Mapping

🎯 Learning Objectives

πŸ›°οΈ Introduction to GPS

What is GPS?

GPS stands for Global Positioning System. It's a network of satellites orbiting Earth that can tell you exactly where you are anywhere on the planet! Your smartphone uses GPS to show your location on maps and give you directions.

Think of GPS like a giant game of "Marco Polo" in space. The satellites are constantly saying "Marco!" (sending signals), and your GPS receiver says "Polo!" (receives the signals). By measuring how long it takes for the signals to travel, your device can figure out exactly where you are.

How GPS Works (Simple Version)

  1. Satellites Send Signals: 24+ satellites orbit Earth, each sending time-stamped signals
  2. Your Device Receives Signals: Your GPS receiver picks up signals from at least 4 satellites
  3. Calculate Distance: By measuring signal travel time, it calculates distance to each satellite
  4. Triangulation: Using distances to multiple satellites, it pinpoints your exact location

It's like being at the center of overlapping circles - where all the circles meet is exactly where you are!

GPS Accuracy and Limitations

  • Typical Accuracy: Within 3-5 meters (10-16 feet) in open areas
  • Indoor Problems: GPS doesn't work well inside buildings
  • Weather Effects: Heavy clouds or storms can reduce accuracy
  • Urban Canyons: Tall buildings can block or reflect signals
  • Battery Usage: GPS uses more power than other sensors

πŸ—ΊοΈ Understanding Coordinates

Latitude and Longitude

GPS coordinates use two numbers to describe any location on Earth:

  • Latitude: How far north or south you are (like horizontal lines on a globe)
  • Longitude: How far east or west you are (like vertical lines on a globe)

Example: The Statue of Liberty is at 40.6892Β° North, 74.0445Β° West

Reading GPS Coordinates

GPS coordinates can be written in different formats:

// Different ways to write the same location:

// Decimal Degrees (most common for programming)
float latitude = 40.6892;
float longitude = -74.0445;

// Degrees, Minutes, Seconds (traditional)
// 40Β° 41' 21.12" N, 74Β° 2' 40.2" W

void setup() {
  Serial.begin(9600);
  Serial.print("Location: ");
  Serial.print(latitude, 6);  // Print 6 decimal places
  Serial.print(", ");
  Serial.println(longitude, 6);
}

Understanding Coordinate Precision

The number of decimal places in coordinates affects accuracy:

  • 1 decimal place: ~11 km accuracy (city level)
  • 2 decimal places: ~1.1 km accuracy (neighborhood level)
  • 3 decimal places: ~110 m accuracy (large building level)
  • 4 decimal places: ~11 m accuracy (house level)
  • 5 decimal places: ~1.1 m accuracy (tree level)
  • 6 decimal places: ~0.11 m accuracy (person level)

πŸ“ Distance Calculations

Simple Distance Formula

To find the distance between two GPS points, we can use a simplified version of the "straight line" distance formula. For short distances (like within a city), this works well:

// Simple distance calculation between two GPS points
float calculateDistance(float lat1, float lon1, float lat2, float lon2) {
  // Convert degrees to approximate meters
  float latDiff = (lat2 - lat1) * 111000;  // 1 degree β‰ˆ 111km
  float lonDiff = (lon2 - lon1) * 111000 * cos(lat1 * PI / 180);
  
  // Use Pythagorean theorem: distance = sqrt(aΒ² + bΒ²)
  float distance = sqrt(latDiff * latDiff + lonDiff * lonDiff);
  
  return distance; // Returns distance in meters
}

Direction Calculations

To navigate, your robot needs to know which direction to go. We can calculate the bearing (compass direction) from one point to another:

// Calculate direction (bearing) from point A to point B
float calculateBearing(float lat1, float lon1, float lat2, float lon2) {
  float latDiff = lat2 - lat1;
  float lonDiff = lon2 - lon1;
  
  // Use atan2 to get angle in radians, then convert to degrees
  float bearing = atan2(lonDiff, latDiff) * 180 / PI;
  
  // Make sure bearing is 0-360 degrees
  if (bearing < 0) {
    bearing += 360;
  }
  
  return bearing;
}

πŸ”¬ Hands-On Activity: GPS Treasure Hunt

Materials Needed

  • miniAuto robot with Arduino
  • GPS module (NEO-6M or NEO-8M)
  • Compass/magnetometer module (for direction)
  • Jumper wires and breadboard
  • Smartphone with GPS coordinates app
  • Large outdoor area (school yard, park, etc.)

Step-by-Step Hardware Setup

  1. Safety First:
    • Turn OFF the miniAuto robot before making any connections
    • Remove the battery pack to prevent accidental power-on
    • Handle the NEO-6M module carefully - it contains sensitive components
  2. Connect NEO-6M GPS Module to miniAuto:
    • VCC (Power): Connect to 3.3V on miniAuto expansion port (NOT 5V!)
    • GND (Ground): Connect to GND on miniAuto expansion port
    • TX (Transmit): Connect to Digital Pin 4 on miniAuto (GPS sends data to Arduino)
    • RX (Receive): Connect to Digital Pin 3 on miniAuto (GPS receives commands from Arduino)
  3. Secure the Module:
    • Use double-sided tape or small zip ties to mount GPS module on top of miniAuto
    • Position the GPS antenna (ceramic square) facing upward for best signal reception
    • Keep GPS module away from motors and other electronic components to reduce interference
  4. Upload GPS Code:
    • Connect miniAuto to computer via USB cable
    • Upload the GPS navigation code from the lesson examples
    • Open Serial Monitor to verify GPS data reception
  5. Initial Testing:
    • Reconnect battery pack and turn ON the miniAuto
    • Take robot outside to an open area (GPS doesn't work indoors)
    • Wait 2-5 minutes for GPS "fix" - you'll see coordinates appear in Serial Monitor
    • Verify coordinates match your approximate location using smartphone GPS
  6. Create Treasure Hunt:
    • Use smartphone GPS app to record coordinates of 3-4 "treasure" locations
    • Make sure locations are at least 20 meters apart for clear navigation
    • Choose open areas without obstacles for initial testing
  7. Test Navigation:
    • Program target coordinates into your robot's code
    • Start robot at a known location and activate navigation mode
    • Observe how robot calculates direction and moves toward target
    • Measure accuracy when robot reaches destination
  8. Improve and Iterate:
    • Adjust navigation parameters for better accuracy
    • Add obstacle avoidance while maintaining GPS course
    • Create multi-waypoint treasure hunt courses

⚠️ Important Safety Notes

  • Voltage Warning: NEO-6M modules are 3.3V devices. Using 5V will damage the module!
  • Antenna Orientation: Keep the ceramic GPS antenna facing upward for best satellite reception
  • Outdoor Requirement: GPS requires clear sky view - it will NOT work indoors or under cover
  • Patience Required: First GPS fix can take 2-5 minutes; subsequent fixes are faster
  • Battery Life: GPS modules consume significant power; bring extra batteries for extended activities

Troubleshooting Tips

  • No GPS Fix: Make sure you're outside with clear sky view
  • Inaccurate Position: Wait longer for GPS to stabilize
  • Robot Goes Wrong Direction: Check compass calibration
  • Battery Drain: GPS uses lots of power; bring extra batteries

πŸ“‹ Assessment & Homework

Practice Exercises

  1. Successfully get GPS coordinates from your robot and display them
  2. Calculate the distance between your school and your home using GPS coordinates
  3. Program your robot to navigate to a target location 50 meters away
  4. Create a simple waypoint navigation system with 3 stops
  5. Measure and record the accuracy of your GPS navigation system

Challenge Projects

  • Delivery Robot: Program robot to deliver items between specific GPS locations
  • Boundary Patrol: Create a GPS fence and have robot patrol the perimeter
  • Return Home: Robot explores randomly but can always navigate back to start
  • GPS Logger: Record and map the path your robot takes during navigation

Reflection Questions

  1. Why is GPS less accurate in cities with tall buildings compared to open areas?
  2. What are some advantages and disadvantages of GPS navigation for robots?
  3. How could you improve GPS navigation accuracy for your robot?
  4. What other applications use GPS navigation in the real world?
← Lesson 20: Wireless Communication πŸ“š Semester Overview Take Quiz β†’