GPS With Arduino, Tutorial Step by Step

by akramslab in Circuits > Arduino

341 Views, 2 Favorites, 0 Comments

GPS With Arduino, Tutorial Step by Step

WhatsApp Image 2024-03-31 at 11.31.01 PM.jpeg
تجارب عملية في مختبر اكرم #1

This project involves utilizing the NEO-6M GPS sensor with Arduino to gather geographical data. The aim is to test and verify the accuracy of the latitude and longitude values extracted from the sensor. By ensuring the correctness of these coordinates, the project aims to establish the reliability of GPS data acquisition using Arduino for diverse applications.

Supplies

FIJ9O9MLUFJ77GK.jpg
WhatsApp Image 2024-03-31 at 11.31.01 PM (1).jpeg
WhatsApp Image 2024-03-31 at 11.30.59 PM.jpeg

Tools Required:

Arduino Board with Cable: The Arduino microcontroller serves as the central processing unit for interfacing with the GPS module and processing the data received from it. The cable facilitates the connection between the Arduino board and the computer for programming and power supply.

GPS NEO-6M Sensor: The NEO-6M GPS module is a compact and cost-effective device capable of providing accurate positioning data through satellite communication. It receives signals from GPS satellites to determine latitude, longitude, altitude, and time information.

4 Wires Female to Male: These wires are essential for establishing connections between the Arduino board and the NEO-6M GPS sensor. They enable the transmission of data and power between the two components, facilitating communication and functionality.

Circuit Setup and Wiring

circuit_edit.jpg
WhatsApp Image 2024-03-31 at 11.31.01 PM (1).jpeg
WhatsApp Image 2024-03-31 at 11.30.59 PM.jpeg

TX and RX Connections: Connect TX pin of NEO-6M to Arduino's digital pin 2 (RX), and RX pin of NEO-6M to Arduino's digital pin 3 (TX).

Voltage Connection: Ensure VCC pin of NEO-6M is linked to Arduino's 3.3V output to supply the correct voltage, preventing potential module damage.


Install TinyGPSPlus Library

library.png
step2.png
step3.jpg

Open Arduino IDE: Launch the Arduino Integrated Development Environment (IDE) on your computer.

Navigate to Sketch Menu: Click on the "Sketch" menu at the top of the Arduino IDE window.

Select Include Library: From the Sketch menu, navigate to "Include Library" submenu.

Manage Libraries: In the "Include Library" submenu, select "Manage Libraries...".

Library Manager: The Library Manager window will open, displaying a list of available libraries.

Search for TinyGPSPlus: In the search bar at the top right corner of the Library Manager window, type "TinyGPSPlus" and press Enter.

Locate TinyGPSPlus: The search results will display the TinyGPSPlus library. Click on the entry for TinyGPS to select it.

Install the Library: Click on the "Install" button next to the TinyGPSPlus library entry. The Arduino IDE will download and install the library automatically.

Close Library Manager: Once the installation is complete, close the Library Manager window.

Verify Installation: To verify that the TinyGPSPlus library has been successfully installed, navigate back to the "Include Library" submenu under the Sketch menu. You should now see "TinyGPSPlus" listed as one of the included libraries.

Begin Using TinyGPSPlus: Now that the TinyGPSPlus library is installed, you can begin using its functions and classes in your Arduino sketches. You can include the library in your sketch by adding the line #include <TinyGPSPlus.h> at the beginning of your code.

With the TinyGPSPlus library successfully installed, you can now proceed with coding your Arduino sketch to interface with the NEO-6M GPS module and parse the NMEA data using the TinyGPSPlus library functions.

Code Setup and Explain

Begin by including the TinyGPSPlus library at the top of your Arduino sketch. This library provides functions for parsing GPS data efficiently.

Additionally, include the SoftwareSerial library, which allows you to create software-based serial communication ports on Arduino.

#include<TinyGPSPlus.h>
#include <SoftwareSerial.h>

Use the SoftwareSerial library to create a software serial connection. Initialize an object named serial_connection, specifying pin 2 as RX and pin 3 as TX.

SoftwareSerial serial_connection(2,3); 

Instantiate a TinyGPS++ object named gps. This object will be used to interact with the GPS module and parse incoming GPS data.

TinyGPSPlus gps;

in the void setup() section, you establish serial communication for monitoring and interaction, initialize the software serial connection with the GPS module, and print a startup message to confirm the initialization process.

void setup() {
Serial.begin(9600);
serial_connection.begin(9600);
Serial.println("GPS Start, by akramslab");
}

In the loop() function, we have create a while loop to continuously read incoming data from the GPS module using the SoftwareSerial connection. Within this loop, you'll use serial_connection.available() to check if there's data available to be read. Then, we will read the data using serial_connection.read() and pass it to gps.encode() for parsing.

while(serial_connection.available()){
  gps.encode(serial_connection.read());}

we use an if condition to check if the GPS location is updated, and if so, print the latitude and longitude values with a specific number of decimal places.

  • the if condition checks if the GPS location is updated using gps.location.isUpdated().
  • If the location is updated, it prints the latitude with 6 decimal places using Serial.print(gps.location.lat(), 6).
  • Then, it prints a comma as a separator using Serial.print(", ").
  • Finally, it prints the longitude with 6 decimal places using Serial.println(gps.location.lng(), 6).
 if (gps.location.isUpdated()){
  Serial.print(gps.location.lat(), 6);
  Serial.print(", ");
  Serial.println(gps.location.lng(), 6);
  }


Full Code

full code.jpg
#include<TinyGPSPlus.h>
#include <SoftwareSerial.h>
SoftwareSerial serial_connection(2,3);
TinyGPSPlus gps;
void setup() {
 
Serial.begin(9600);
serial_connection.begin(9600);
Serial.println("GPS Start, by akramslab");


 
  }

void loop() {
while(serial_connection.available()){
  gps.encode(serial_connection.read());}
  if (gps.location.isUpdated()){
  Serial.print(gps.location.lat(), 6);
  Serial.print(", ");
  Serial.println(gps.location.lng(), 6);
  }
}


Result

تجارب عملية في مختبر اكرم #1
  1. Open Serial Monitor: Connect your Arduino board to your computer, open the Arduino IDE, and navigate to Tools > Serial Monitor (or press Ctrl+Shift+M). This will open the Serial Monitor window, where you'll see the output from your Arduino.
  2. Wait for Data: Allow the Arduino to run for approximately 3 minutes. This gives the GPS module enough time to acquire satellite signals and determine its position.
  3. Move Outdoors: Ensure you're in an outdoor location with clear visibility to the sky. GPS modules require a clear line of sight to satellites to function accurately.
  4. Read Latitude and Longitude: Once the Arduino begins printing latitude and longitude values to the Serial Monitor, copy these values.
  5. Search in Google Maps: Open Google Maps in your web browser or mobile app. Paste the copied latitude and longitude values into the search bar and hit Enter. Google Maps will locate the specified coordinates on the map, allowing you to see the exact outdoor location where the GPS data was obtained.

By following these steps, you'll be able to retrieve and verify the GPS coordinates provided by your Arduino setup using the NEO-6M GPS module.

Promoting Social Media Channels

Thank you for exploring GPS data retrieval with us! Stay connected and dive deeper into exciting projects like this by following us on our social media channels. Don't miss out on valuable content, tutorials, and updates. Join our Telegram channel for exclusive insights and discussions. Let's continue this journey together!

Our pages: https://lnk.bio/akramslab

Our channel on Telegram: https://t.me/akramslab