This post shows how to connect the Arduino with GPS module in order to receive data from satellites where the GPS module used in this project is u-blox NEO-6M (other modules also should work). With the NEO-6M GPS module we can measure position (latitude, longitude and altitude), time, date, speed and some other data. GPS: Global Positioning System.
The NEO-6M GPS module which I’m using is similar to the one shown below:
Generally the GPS module has 4 pins: VCC, RX, TX and GND. It uses serial communication (UART protocol) to communicate with the microcontroller where RX/TX pins are for receiving/transmitting data from/to the microcontroller.
Hardware Required:
- Arduino board —> Arduino board details
- NEO-6M GPS module
- Breadboard
- Jumper wires
Interfacing Arduino with NEO-6M GPS module circuit:
The connection of the Arduino with the NE0-6M GPS module is shown below.
NEO-6M GPS board GND pin goes to Arduino GND
TX pin goes to Arduino digital pin 4
RX pin is not connected
VCC pin goes to Arduino 5V pin (can be connected to 3.3V pin)
Note that the RX pin of the GPS module is not connected because there is no need to send data from the Arduino to it, in this project the Arduino just receives data from the GPS module (the GPS module receives data only from the satellites).
Arduino Code:
With the code below we can get the following data from the NEO-6M GPS module:
latitude, longitude, altitude, time, date and number of satellites in use. After I uploaded the sketch into my Arduino I got the result shown below (you’ve to wait for some time if the position is not displayed):
Actually the NEO-6M GPS module sends raw data to the microcontroller repeatedly, this raw data is known as NMEA sentences. NMEA: National Marine Electronics Association.
We can read NEMA sentences but it’s better to (if I can say) decode (or parse) it, for that reason used an Arduino library called TinyGPS++ (TinyGPSPlus). As they said: “this library provides compact and easy-to-use methods for extracting position, date, time, altitude, speed, and course from consumer GPS devices” —> TinyGPS library.
The TinyGPS++ library can be downloaded using the link below. After downloading the library, unzip the folder and add it to Arduino libraries folder (for example: C:\Program Files\Arduino\libraries). You should rename the folder “TinyGPSPlus”.
TinyGPS++ Library — direct link
Also, I used another library named SoftwareSerial (SoftwareSerial.h) because the Arduino UNO has 1 hardware UART module which is used for the communication between it and the laptop, we need an other serial interface for the communication between the Arduino and the NEO-6M GPS module, here we can use software UART using the built-in library SoftwareSerial.
Full Arduino code is below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | // Interfacing Arduino with NEO-6M GPS module #include <TinyGPS++.h> // Include TinyGPS++ library #include <SoftwareSerial.h> // Include software serial library TinyGPSPlus gps; #define S_RX 4 // Define software serial RX pin #define S_TX 3 // Define software serial TX pin SoftwareSerial SoftSerial(S_RX, S_TX); // Configure SoftSerial library void setup(void) { Serial.begin(9600); SoftSerial.begin(9600); } void loop() { while (SoftSerial.available() > 0) { if (gps.encode(SoftSerial.read())) { if (gps.location.isValid()) { Serial.print("Latitude = "); Serial.println(gps.location.lat(), 6); Serial.print("Longitude = "); Serial.println(gps.location.lng(), 6); } else Serial.println("Location Invalid"); if (gps.altitude.isValid()) { Serial.print("Altitude = "); Serial.print(gps.altitude.meters()); Serial.println(" meters"); } else Serial.println("Altitude Invalid"); if (gps.speed.isValid()) { Serial.print("Speed = "); Serial.print(gps.speed.kmph()); Serial.println(" kmph"); } else Serial.println("Speed Invalid"); if (gps.time.isValid()) { Serial.print("Time (GMT) : "); if(gps.time.hour() < 10) Serial.print("0"); Serial.print(gps.time.hour()); Serial.print(":"); if(gps.time.minute() < 10) Serial.print("0"); Serial.print(gps.time.minute()); Serial.print(":"); if(gps.time.second() < 10) Serial.print("0"); Serial.println(gps.time.second()); } else Serial.println("Time Invalid"); if (gps.date.isValid()) { Serial.print("Date : "); if(gps.date.day() < 10) Serial.print("0"); Serial.print(gps.date.day()); Serial.print("/"); if(gps.date.month() < 10) Serial.print("0"); Serial.print(gps.date.month()); Serial.print("/"); Serial.println(gps.date.year()); } else Serial.println("Date Invalid"); if (gps.satellites.isValid()) { Serial.print("Satellites = "); Serial.println(gps.satellites.value()); } else Serial.println("Satellites Invalid"); } } } |
GPS Module Proteus simulation:
This project can be simulated with Proteus, a small library for the GPS module is included in version 8.6 (and higher) of the software. The small video below shows the simulation of the project.
Proteus simulation file download (for version 8.6 or higher):
Arduino GPS
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.
I am getting like this could you please help me.
20:16:20.840 -> Date Invalid
20:16:20.840 -> Satellites Invalid
20:16:20.840 -> Location Invalid
20:16:20.840 -> Altitude Invalid
20:16:20.889 -> Speed Invalid
20:16:20.889 -> Time Invalid
didnt print any result? can you help this problem
plz can u help me same problem with me
Iam doing a project using neo 6m GPS ,900 a GSM,16*2lcd,an emergency switch. The theme of the project is that on pressing the switch the location must be sent to the predefined mobile number in the code and the same to be displayed on the lcd. Please help me with the code.
proteus gives me a Geocode error and didn’t print any result…can u help me?