Circuit Documentation
Summary
This circuit involves an Arduino UNO microcontroller interfaced with a GPS NEO 6M module. The Arduino UNO provides power to the GPS module and communicates with it using serial communication. The purpose of this setup is to read GPS data and display the latitude and longitude coordinates via the Arduino's serial monitor.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
GPS NEO 6M
- Description: A GPS module used for obtaining location data.
- Pins: VCC, RX, TX, GND
Wiring Details
Arduino UNO
- 5V: Connected to VCC of GPS NEO 6M
- GND: Connected to GND of GPS NEO 6M
- D3: Connected to RX of GPS NEO 6M
- D2: Connected to TX of GPS NEO 6M
GPS NEO 6M
- VCC: Connected to 5V of Arduino UNO
- GND: Connected to GND of Arduino UNO
- RX: Connected to D3 of Arduino UNO
- TX: Connected to D2 of Arduino UNO
Code Documentation
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
// GPS NEO 6M connections
#define GPS_RX 2
#define GPS_TX 3
SoftwareSerial gpsSerial(GPS_RX, GPS_TX);
TinyGPSPlus gps;
void setup() {
Serial.begin(9600); // Start serial communication for debugging
gpsSerial.begin(9600); // Start GPS communication
Serial.println("GPS Test Started...");
}
void loop() {
// Read data from GPS module
while (gpsSerial.available()) {
char c = gpsSerial.read();
Serial.write(c); // Print raw GPS data to Serial Monitor
gps.encode(c); // Feed data to the TinyGPS++ library
// If a valid GPS fix is available, display the coordinates
if (gps.location.isUpdated()) {
displayGPSData(); // Display current GPS data (lat/lng)
}
}
// Optional: Delay to avoid flooding the serial monitor with too many updates
delay(1000);
}
void displayGPSData() {
// Only display if the GPS location is valid
if (gps.location.isValid()) {
float latitude = gps.location.lat();
float longitude = gps.location.lng();
Serial.print("Latitude: ");
Serial.print(latitude, 6); // Print latitude with 6 decimal places
Serial.print(" Longitude: ");
Serial.println(longitude, 6); // Print longitude with 6 decimal places
} else {
Serial.println("GPS signal not available.");
}
}
Code Explanation
- Libraries: The code includes
SoftwareSerialfor serial communication andTinyGPS++for parsing GPS data. - Pin Definitions:
GPS_RXandGPS_TXare defined for the GPS module's RX and TX pins. - Setup Function: Initializes serial communication for both the Arduino and the GPS module.
- Loop Function: Continuously reads data from the GPS module, prints raw data to the serial monitor, and processes the data using the TinyGPS++ library. If a valid GPS fix is available, it calls
displayGPSData()to print the latitude and longitude. - displayGPSData Function: Checks if the GPS location is valid and prints the latitude and longitude to the serial monitor. If the GPS signal is not available, it prints an error message.
