Devices & Components
Arduino Nano
Micro SD Card Module (Generic)
USB to TTL Board (Optional)
Flash Memory Card, SD Card
GPS Neo-6m Module
Jumper wires (generic)
Hardware & Tools
Soldering iron (generic)
Solder Wire, Lead Free
Software & Tools
Arduino IDE
TinyGPS++ Library
SD Card Formatter
Project description
Code
Github GPS-SD Card Code
Github GPS-SD Card Code
GPS-SD Card Data Logger Code
arduino
1// GPS Data logged into an SD Card 2// Written by Adrianos Botis e-mail:adrianosbotis@gmail.com 3 //* SD card attached to SPI bus as follows: 4 //** MOSI - pin 11 5 //** MISO - pin 12 6 //** CLK - pin 13 7 //** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN) 8 9#include <TinyGPS++.h> 10#include <SoftwareSerial.h> 11#include <SD.h> 12#include<SPI.h> 13 14// Choose two Arduino pins to use for softwarge serial 15int RXPin = 2; 16int TXPin = 3; 17const int chipSelect = 4; 18int GPSBaud = 9600; 19 20TinyGPSPlus gps; 21 22SoftwareSerial gpsSerial(RXPin, TXPin); 23 24void setup() 25{ 26 // Start the software serial port at the GPS's default baud 27 gpsSerial.begin(GPSBaud); 28 // Open serial communications and wait for port to open: 29 Serial.begin(9600); 30 Serial.print("Initializing SD card..."); 31 32 if (!SD.begin(4)) { 33 Serial.println("initialization failed!"); 34 while (1); 35 } 36 Serial.println("initialization done."); 37} 38void loop() 39{ 40 String dataString = ""; 41 String dataString2 = ""; 42 String dataString3 = ""; 43 String dataString4 = ""; 44 // This sketch displays information every time a new sentence is correctly encoded. 45 while (gpsSerial.available() > 0) 46 if (gps.encode(gpsSerial.read())) 47 displayInfo(); 48 49 if (gps.location.isValid()) 50 { 51 dataString = String(gps.altitude.meters(), 3); 52 dataString2 = String(gps.location.lat(), 6); 53 dataString3 = String(gps.location.lng(), 6); 54 55 File dataFile = SD.open("GpsDat.txt", FILE_WRITE); 56 57 // if the file is available, write to it: 58 if (dataFile) { 59 dataFile.print("Altitude: "); 60 dataFile.println(dataString); 61 dataFile.print("Longtitude: "); 62 dataFile.println(dataString2); 63 dataFile.print("Latitude: "); 64 dataFile.print(dataString3); 65 dataFile.print("Time: "); 66 if (gps.time.hour() < 10) dataFile.print(F("0")); 67 dataFile.print(gps.time.hour()); 68 dataFile.print(":"); 69 if (gps.time.minute() < 10) dataFile.print(F("0")); 70 dataFile.print(gps.time.minute()); 71 dataFile.print(":"); 72 if (gps.time.second() < 10) dataFile.print(F("0")); 73 dataFile.print(gps.time.second()); 74 dataFile.print("."); 75 if (gps.time.centisecond() < 10) dataFile.print(F("0")); 76 dataFile.println(gps.time.centisecond()); 77 dataFile.println(); 78 dataFile.close(); 79 80 } 81 else 82 { 83 Serial.println("Failed to open file"); 84 Serial.println(); 85 } 86 } 87 else 88 { 89 Serial.println("Location: Not Available"); 90 } 91 // open the file. note that only one file can be open at a time, 92 // so you have to close this one before opening another. 93 94 // If 5000 milliseconds pass and there are no characters coming in 95 // over the software serial port, show a "No GPS detected" error 96 if (millis() > 50000 && gps.charsProcessed() < 10) 97 { 98 Serial.println("No GPS detected"); 99 while(true); 100 } 101 } 102 103void displayInfo() 104{ 105 if (gps.location.isValid()) 106 { 107 Serial.print("Latitude: "); 108 Serial.println(gps.location.lat(), 6); 109 Serial.print("Longitude: "); 110 Serial.println(gps.location.lng(), 6); 111 Serial.print("Altitude: "); 112 Serial.println(gps.altitude.meters()); 113 Serial.print("Number of Satellites: "); 114 Serial.println(gps.satellites.value(), 6); 115 } 116 else 117 { 118 Serial.println("Location: Not Available"); 119 } 120 121 Serial.print("Date: "); 122 if (gps.date.isValid()) 123 { 124 Serial.print(gps.date.month()); 125 Serial.print("/"); 126 Serial.print(gps.date.day()); 127 Serial.print("/"); 128 Serial.println(gps.date.year()); 129 Serial.println(); 130 Serial.print("Number of Satellites: "); 131 Serial.println(gps.satellites.value(), 6); 132 } 133 else 134 { 135 Serial.println("Not Available"); 136 } 137 138 Serial.print("Time: "); 139 if (gps.time.isValid()) 140 { 141 if (gps.time.hour() < 10) Serial.print(F("0")); 142 Serial.print(gps.time.hour()); 143 Serial.print(":"); 144 if (gps.time.minute() < 10) Serial.print(F("0")); 145 Serial.print(gps.time.minute()); 146 Serial.print(":"); 147 if (gps.time.second() < 10) Serial.print(F("0")); 148 Serial.print(gps.time.second()); 149 Serial.print("."); 150 if (gps.time.centisecond() < 10) Serial.print(F("0")); 151 Serial.println(gps.time.centisecond()); 152 } 153 else 154 { 155 Serial.println("Not Available"); 156 } 157 158 Serial.println(); 159 Serial.println(); 160 delay(500); 161} 162
Downloadable files
Circuit Schematic Picture
Circuit Schematic Picture

Circuit Schematic
Circuit Schematic
Circuit Schematic Picture
Circuit Schematic Picture

Circuit Schematic
Circuit Schematic
Comments
Only logged in users can leave comments