-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGetLocation.ino
37 lines (32 loc) · 1.13 KB
/
GetLocation.ino
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
/**
* This example demonstrates how to get the current GPS location using the ArduinoCellular library.
*
* Instructions:
* 1. Move the Arduino Pro 4G Module to an outdoor location with a clear view of the sky.
* 2. Provide sufficient power to the Arduino Pro 4G Module. Ideally, use a 5V power supply
* 3. Upload the sketch to the connected Arduino board.
* 4. Open the serial monitor to view the output.
*
* Initial author: Sebastian Romero
*/
#include "ArduinoCellular.h"
ArduinoCellular cellular = ArduinoCellular();
void setup(){
Serial.begin(115200);
while (!Serial);
cellular.setDebugStream(Serial);
cellular.begin();
if(!cellular.enableGPS()){
Serial.println("Failed to enable GPS");
while(true); // Stop the program
}
delay(2000); // Give the modem some time to initialize
}
void loop(){
Location location = cellular.getGPSLocation();
Serial.println("GPS Location:");
Serial.print("* Latitude: "); Serial.println(location.latitude, 6);
Serial.print("* Longitude: "); Serial.println(location.longitude, 6);
Serial.println("--------------------\n");
delay(10000);
}