wrighi
Published

GPS Distance and Speed Logger

A simple project to make a GPS log station with data speed, max speed, distance trip and altitude. data are write on SD card

BeginnerFull instructions provided561
GPS Distance and Speed Logger

Things used in this project

Hardware components

GPS Module (Generic)
generic gps neo6m u-blox (better with usb socket as to setup in u-blox center)
×1
Arduino Nano R3
Arduino Nano R3
×1
Graphic OLED, 128 x 64
Graphic OLED, 128 x 64
0,96'' monocromatic 128x64 oled display (better white)
×1
Memory Socket, SD Card
Memory Socket, SD Card
SD card writer/reader for micro or normal SD cards
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

schematics

connect wires by colors

gps_mgebcsszu1_5rDBAfZKUE.fzz

Code

gps unit code

Arduino
  #include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
#include <NMEAGPS.h>
#include <SoftwareSerial.h>
//#include <NeoSWSerial.h>
const int cs_sd=2;
#define I2C_ADDRESS 0x3C
#define RST_PIN -1
SSD1306AsciiWire lcd;
NMEAGPS gps;
gps_fix fix;
File myFile;
float odo;
float Speed; 
int alt;
NeoGPS::Location_t    lastLoc;
bool                  lastLocOK = false;
static const int RXPin = 5, TXPin = 4; //-- gps pin
static const uint32_t GPSBaud = 9600;
SoftwareSerial gpsPort(RXPin, TXPin);
const int SHOW_INTERVAL = 1;
const int INITIAL_SHOW  = (2 * SHOW_INTERVAL) - 1; 
    int show          = INITIAL_SHOW;
const int   LED_PIN  = 3;  //-- led on at speed limit
const float SPEED_LIMIT = 0.0; // --setup speed limit value es: 55.0; kmh
int maxs = 0; 
void setup(){
  pinMode (LED_PIN, OUTPUT);
Serial.begin(9600);
gpsPort.begin(GPSBaud);
Wire.begin();
lcd.begin(&Adafruit128x64, I2C_ADDRESS);
lcd.setFont(TimesNewRoman16_bold);
lcd.clear();
lcd.println("  GPS LOGGER");
lcd.println(" ");
lcd.println("   WELCOME");
delay(3000);
lcd.clear();
if(!SD.begin(cs_sd)){
lcd.clear();
lcd.println(" ");
lcd.print("NO SD");
delay(3000);
return;}
lcd.println(" ");
lcd.print("SD Card OK");
delay(2000);
lcd.clear();
File data = SD.open("log.csv",FILE_WRITE);              
data.println(""); 
data.println("Date  Hr+  Lat  Lon  Alt  Vel  Dis" ); //-- Hr+ add your local time difference   
data.close();}
void loop(){
if (gps.available( gpsPort )) {  
gps_fix fix = gps.read();  
show = (show + 1) % SHOW_INTERVAL;
if (fix.valid.speed && (fix.speed_kph() > SPEED_LIMIT)) {
    digitalWrite( LED_PIN, HIGH );   
 } else {
 digitalWrite( LED_PIN, LOW ); } 
 if (fix.valid.location) { 
 if (lastLocOK) {
 odo += fix.location.DistanceKm( lastLoc );
 Speed = (fix.speed_kph());}
lastLoc   = fix.location;
lastLocOK = true;}
if ( Speed > maxs) 
maxs = Speed;
if (fix.valid.altitude)
 alt = ( fix.altitude () );
if (show == 0) {
#define MAX_CHARS 22
char displayBufffer[MAX_CHARS];
lcd.setCursor(0,0);   
snprintf(displayBufffer, MAX_CHARS, " Km  :  %  3d.%02d", (int)odo, (int)(odo * 100)%100);
lcd.println(displayBufffer);   
snprintf(displayBufffer, MAX_CHARS, "Kmh:  %  3d.%02d", (int)Speed, (int)(Speed * 100)%100);
lcd.println(displayBufffer);
snprintf(displayBufffer, MAX_CHARS, "Vmx:  %  3d.%02d", (int)maxs, (int)(maxs * 100)%100);
lcd.println(displayBufffer);
snprintf(displayBufffer, MAX_CHARS, " Alt   :  %  3d.%02d", (int)alt, (int)(alt * 100)%100);
lcd.println(displayBufffer);}    
String Temps=String(fix.dateTime.hours +1)+(":")+(fix.dateTime.minutes)+(":")+(fix.dateTime.seconds);
String Date=String(fix.dateTime.day)+("/")+(fix.dateTime.month)+("/")+(fix.dateTime.year);  
File data=SD.open("log.csv",FILE_WRITE);
data.println(Date +("  ")+ Temps +("  ")+ String(fix.latitude(), 6)+("  ")+String(fix.longitude(), 6)+("  ")+String(alt)+("  ") +String(Speed)+("  ")+ String(odo)); 
data.close();}}

Credits

wrighi

wrighi

1 project • 0 followers

Comments