Arduino Nano 33 IoT - GPS
This guide will show you how to get GPS location details like longitude, latitude, and altitude, as well as speed in kilometers per hour, from the NEO-6M GPS module. We will also explain how to calculate the distance between your current location and a set GPS point, such as the location of London.

Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .
Additionally, some of these links are for products from our own brand, DIYables .
Overview of NEO-6M GPS module
Pinout
The NEO-6M GPS module comes with four pins.
- VCC pin: This pin must be connected to the power supply (either 3.3V or 5V).
- GND pin: This pin must be connected to ground (0V).
- TX pin: This pin sends data from the GPS module to the Arduino Nano 33 IoT. It must be connected to the Serial RX pin on the Arduino Nano 33 IoT.
- RX pin: This pin receives data from the Arduino Nano 33 IoT to the GPS module. It must be connected to the Serial TX pin on the Arduino Nano 33 IoT.

Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Arduino Nano 33 IoT Code
Reading GPS coordinates, speed (km/h), and date time
/*
* This Arduino Nano 33 IoT code was developed by newbiely.com
*
* This Arduino Nano 33 IoT code is made available for public use without any restriction
*
* For comprehensive instructions and wiring diagrams, please visit:
* https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-gps
*/
#include <TinyGPS++.h>
#define RX1PIN 2 // The Arduino Nano 33 IoT pin connected to the TX of the GPS module
#define TX1PIN 3 // The Arduino Nano 33 IoT pin connected to the RX of the GPS module
TinyGPSPlus gps; // The TinyGPS++ object
void setup() {
Serial.begin(9600);
Serial1.begin(9600, SERIAL_8N1, RX1PIN, TX1PIN);
Serial.println(F("Arduino - GPS module"));
}
void loop() {
if (Serial1.available() > 0) {
if (gps.encode(Serial1.read())) {
if (gps.location.isValid()) {
Serial.print(F("- latitude: "));
Serial.println(gps.location.lat());
Serial.print(F("- longitude: "));
Serial.println(gps.location.lng());
Serial.print(F("- altitude: "));
if (gps.altitude.isValid())
Serial.println(gps.altitude.meters());
else
Serial.println(F("INVALID"));
} else {
Serial.println(F("- location: INVALID"));
}
Serial.print(F("- speed: "));
if (gps.speed.isValid()) {
Serial.print(gps.speed.kmph());
Serial.println(F(" km/h"));
} else {
Serial.println(F("INVALID"));
}
Serial.print(F("- GPS date&time: "));
if (gps.date.isValid() && gps.time.isValid()) {
Serial.print(gps.date.year());
Serial.print(F("-"));
Serial.print(gps.date.month());
Serial.print(F("-"));
Serial.print(gps.date.day());
Serial.print(F(" "));
Serial.print(gps.time.hour());
Serial.print(F(":"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
Serial.println(gps.time.second());
} else {
Serial.println(F("INVALID"));
}
Serial.println();
}
}
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F("No GPS data received: check wiring"));
}
Detailed Instructions
If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:
- Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
- Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
- Click the Libraries icon on the left side of the Arduino IDE.
- Type TinyGPSPlus in the search box and then choose the TinyGPSPlus library by Mikal Hart.
- Click the Install button to add the TinyGPSPlus library.

- Copy the code above and open it in the Arduino IDE. Press the Upload button to send the code to your Arduino Nano 33 IoT. Then, check the Serial Monitor to see the result.
COM6
Autoscroll
Clear output
9600 baud
Newline
Calculating the distance from current location to a predefined location
The code below calculates the distance from your current location to London (latitude: 51.508131, longitude: -0.128002).
/*
* This Arduino Nano 33 IoT code was developed by newbiely.com
*
* This Arduino Nano 33 IoT code is made available for public use without any restriction
*
* For comprehensive instructions and wiring diagrams, please visit:
* https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-gps
*/
#include <TinyGPS++.h>
#define RX1PIN 2 // The Arduino Nano 33 IoT pin connected to the TX of the GPS module
#define TX1PIN 3 // The Arduino Nano 33 IoT pin connected to the RX of the GPS module
TinyGPSPlus gps; // The TinyGPS++ object
const double LONDON_LAT = 51.508131;
const double LONDON_LON = -0.128002;
void setup() {
Serial.begin(9600);
Serial1.begin(9600, SERIAL_8N1, RX1PIN, TX1PIN);
Serial.println(F("Arduino - GPS module"));
}
void loop() {
if (Serial1.available() > 0) {
if (gps.encode(Serial1.read())) {
if (gps.location.isValid()) {
double latitude = gps.location.lat();
double longitude = gps.location.lng();
unsigned long distanceKm = TinyGPSPlus::distanceBetween(latitude, longitude, LONDON_LAT, LONDON_LON) / 1000;
Serial.print(F("- latitude: "));
Serial.println(latitude);
Serial.print(F("- longitude: "));
Serial.println(longitude);
Serial.print(F("- distance to London: "));
Serial.println(distanceKm);
} else {
Serial.println(F("- location: INVALID"));
}
Serial.println();
}
}
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F("No GPS data received: check wiring"));
}
Detailed Instructions
- Copy the code above and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Nano 33 IoT.
- Check the results on the Serial Monitor.
COM6
Autoscroll
Clear output
9600 baud
Newline