Alexander BarnhardtMicah Koenigsberg
Published

GPS Tracking Device

Track your car from any Wifi enabled spot!

BeginnerFull instructions provided4,992
GPS Tracking Device

Things used in this project

Hardware components

Photon
Particle Photon
×1
Electron
Particle Electron
×1
serial oled lcd 0.96
Could not find the exact specification for the OLED screen, but it is the one that comes with the Photon Particle Makers Kit.
×1
Particle Push Button
×1

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

ThingSpeak: Voltage vs Time

Here ThingSpeak was used to record the battery voltage and was plotted against time. The voltage is seen decreasing, but increasing once the device was plugged into charge.

ThingSpeak: Battery Percent vs Time

This graphs shows the percent of battery left. The upswing is when the device was connected to change in a car.

If This Than That Applets

These are the applets used. One is for collecting location data and storing in googleDocs and the other sends the location data when the button attached to the Photon Particle is held down.

GoogleDocs Records of Locations

Micro OLED Sketch

This is the wiring diagram from the Micro OLED screen and the Photon Particle.

Micro OLED Sketch Image

Code

OLED Code

C/C++
This is the code that was run on the Photon Particle connected to the OLED Screen and the push botton. It subscribed to relevant data being published by the other Particle and then displayed this information on the screen. Also, if the push button is held down it will publish an event that triggers If This Than That to send the longitude and latitude data from the gps to a phone The code is a modified versions of an example code from SparkFun, with the addition of the subscribe functions. It does include the SparkFunMicroOLED library.
#include "SparkFunMicroOLED/SparkFunMicroOLED.h"  // Include MicroOLED library
#include "math.h"
#include <string>
MicroOLED oled;

int buttonPin = D0;

float var;

String test=("var");
String voltage;
String ma100;
char volt[5];
String Gps;
char gps[25];
String Bat;
char bat[6];

void setup()
 {               
Serial.begin(9600);
  oled.begin();    // Initialize the OLED
  oled.clear(ALL); // Clear the display's internal memory
  oled.display();  // Display what's in the buffer (splashscreen)
  delay(1000);     // Delay 1000 ms
  randomSeed(analogRead(A0) + analogRead(A1));
  
  
  Particle.connect();
  Particle.subscribe("ma100", myHandler, MY_DEVICES);
  Particle.subscribe("Gps", myHandler1, MY_DEVICES);
  Particle.subscribe("%Bat", myHandler2, MY_DEVICES);
  Serial.begin(9600);
  pinMode( buttonPin , INPUT_PULLUP);
  
  
  //var=char(data);
  }
void myHandler(const char *event, const char *data)
{
    ma100=data;
   ma100.toCharArray(volt,5);

}
void myHandler1(const char *event, const char *data1)
 {
     Gps=data1;
     Gps.toCharArray(gps,25);
}

void myHandler2(const char *event, const char *data2)
 {
     Bat=data2;
     Bat.toCharArray(bat,6);
}





void loop()
{
  text();  
  setup();
    int buttonState = digitalRead( buttonPin );
     if( buttonState == LOW )
  {
 
    Particle.publish("run", gps ,PRIVATE);
  }
  
   
}
  
}

void text()
{
  oled.print("GPS Tracking Device");
  oled.display();
  oled.setFontType(0);  
  delay(2500);
  oled.clear(PAGE);     
  oled.setCursor(0, 0); 
  oled.print("GPS Coords");
  oled.display();
  delay(1500);
  oled.clear(PAGE);
  oled.setCursor(0, 0);
  oled.print(gps);
  oled.display();
  delay(2500);
  oled.clear(PAGE);     
  oled.setCursor(0, 0); 
  oled.print("Battery   Percent");
  oled.display();
  delay(1500);
  oled.clear(PAGE);
  oled.setCursor(0, 0);
  oled.print(bat);
  oled.display();
  delay(2500);
  oled.clear(PAGE);     
  oled.setCursor(0, 0); 
  oled.print("Particle  Voltage");
  oled.display();
  delay(1500);
  oled.clear(PAGE);     
  oled.setCursor(0, 0); 
  oled.print(volt);
  oled.display();
  delay(2500);

}


void printTitle(String title, int font)
{
  int middleX = oled.getLCDWidth() / 2;
  int middleY = oled.getLCDHeight() / 2;

  oled.clear(PAGE);
  oled.setFontType(font);
  oled.setCursor(middleX - (oled.getFontWidth() * (title.length()/2)),
                 middleY - (oled.getFontWidth() / 2));
  oled.print(title);
  oled.display();
  delay(1500);
  oled.clear(PAGE);
}

GPS Code

C/C++
This is the code that runs on the Particle Electron and GPS Shield. The code is a modified version of some example code from Particle and includes the AssetTracker library. In its current form it sends the Gps and battery data out every minute. If there is not a Gps fix it will only send the battery voltage and percent.
#include "AssetTracker/AssetTracker.h"


int transmittingData = 1;

long lastPublish = 0;

int delayMinutes = 1;

AssetTracker t = AssetTracker();

FuelGauge fuel;

void setup() {
    t.begin();
    t.gpsOn();
    Serial.begin(9600);
    
}

void loop() {
    t.updateGPS();
    
    

    if(millis()-lastPublish > delayMinutes*60*1000){
        lastPublish = millis();
        Particle.publish("ma100",+ String::format("%.2f",fuel.getVCell()), PRIVATE);
        Particle.publish("%Bat",+ String::format("%.2f",fuel.getSoC()), PRIVATE);
        

        Serial.println(t.preNMEA());
       
        if(t.gpsFix()){
           
            
            if(transmittingData){
                    Particle.publish("Gps", + String::format(t.readLatLon()), 60, PRIVATE);
                
            }
            Serial.println(t.readLatLon());
        }
    }
}

Credits

Alexander Barnhardt

Alexander Barnhardt

1 project • 0 followers
Micah Koenigsberg

Micah Koenigsberg

1 project • 0 followers

Comments