Brian Moreau

Search my site

    Maker Portfolio   
Particle Electron GPS receiver (Location plotted on Google Map)
March 2016

Particle Electron GPS

The Particle Electron

The Particle Electron is a new prototype device for the Internet of things (IoT)
Theirs plenty of these about but this one boasts cellular connectivity.
Yes it can connect to mobile telephone networks allowing your devices to become truly mobile.

The device is based on a powerful 32 Bit processor running at 120MHz.
It is easily programmable using an Arduino like programming language.


Electron GPS


As this devise is best suited to projects that can be mobile the first thing I decided that would be needed was to know its location. I thus set about adding a GPS Receiver.

GPS Receiver
Many of these devices exist for various IoT platforms so I decided to select one that is Arduino compatible thus ensuring program and connectivity compatibility.
These units vary in price greatly and are generally anywhere between £30 to £60.
I found one that was only £15 and from the specification looked to be a pretty good unit which actually exceeded specifications of some more expensive alternatives.

GP-20U7 GPS Receiver
This is a high sensitivity -163dBm, 56 channel search and 22 channel tracking.
Additionally it only requires 3.3V power @ 30mA which the Electron can supply adequately.

I got mine from Proto-PIC and they even gave me a free packet of sweets :)

The Data Sheet is here

Electron Programming

OTA Programming
The particle website allows you to write programs and flash them over the air (OTA) direct to your device. This uses data bandwidth but for testing a few programs its very convenient and easy.

Serial Programming
To program the device by serial is not quite a easy as programming the Arduino.
First you have to install NODE.JS and then the driver.
You must still use the Particle website to write your programs but instead of flashing them OTA you can compile and download the binary file, you then issue a command line instruction to transfer the binary file to the device.

Here is the connecting and programming guide:

Project Overview
The only hardware parts of the project are the Particle Electron, GPS Unit, 220Ohm Resistor and LED.
The Electron runs a program that reads the required line of GPS data via the Serial port.

If the Data is valid i.e the GPS Unit is LOCKED then an LED is turned on. This enables debugging and gives visual indication of GPS LOCK.

The Data contains the Latitude and Longitude and soem other data which is made available as a web accessible variable.

The variable or data is then grabbed and decoded by the code embedded into a web page.

In order to achieve this you will need to be able to publish a webpage in some webspace somewhere.
I wrote my code in PHP but I guess you would be able to use ASP and or JavaScript.
The last bit of code required on the webpage is the Google Map Embed Function which places a Map Marker at the location of the device.

The Electron comes with it own bread board so connecting up is easy.

Simply connect the positive of the GPS unit to +3.3V on the Electron and GND to GND and the TX from the GPS Receive to the RX of Serial Port on the Electron.

For the LOCK LED connect the 220Ohm Resistor from D1 to the Anode of the LED and the Cathode of the LED to GND.

Electron Code

// GPSTest

String inWord;
char inByte;
String data;
int LockLED = D1;  

void setup() {
    // cloud variable
    Particle.variable("STU", data);
    // GPS Serial
    pinMode(LockLED, OUTPUT);
    digitalWrite(LockLED, HIGH);
    digitalWrite(LockLED, LOW);

void loop() {
    while (Serial1.available() > 0) {
        inByte =;
        if (inByte == '\n') {
            // END OF LINE
            // check is data we want
            // you can change this to get any data line values
            if (inWord.startsWith("$GPRMC")) {
                // put data string in variable
                data = inWord;
                // clear the inword variable
                inWord = "";
                // does the GPS Receiver have lock?
                // get the char at pos 17 and test to see if it is an A i.e VALID V = INVALID
                char lock = data.charAt(17);
                if (lock == 'A') {
                    // YES Switch on Lock LED
                    digitalWrite(LockLED, HIGH);
                } else {
                    // NO turn off lock led
                    digitalWrite(LockLED, LOW);  
            } else {
                // clear the inword variable as not the data we want
                inWord = "";
        } else {
            // build data string
            inWord += inByte;   
    } // end if serial
} // end loop


Website Code

# particle-map.php


$url = "$deviceID/";
$formed_url ='?access_token='.$access_token;
$variable_name = "STU";

$headers = array( 
  	"GET /v1/devices/".$variable_name.$formed_url." HTTP/1.1",

  	// setup and make HTTP GET REQUEST
	$ch = curl_init();  
	curl_setopt($ch, CURLOPT_URL,$url.$variable_name.$formed_url);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output
	$retrievedhtml = curl_exec ($ch); 
	$json = json_decode($retrievedhtml,true);

	// see if there was an error connecting with electron
	if ($json['error'] != "") {
	    echo ("ERROR = " . $json['error'] . "<br>");
	} else {
	   // read the data into a variable
	   $DATA = $json['result'];
	   // output to screen
	   echo ("<b>result: </b>" . $DATA . "<br>");
	   // split data into array  is comma delimited
	   $pieces = explode(",", $DATA);
	   // A = valid, V = not valid
	   $status = $pieces[2];
	   if ($status == "V") {
			echo ("Data not valid<br>Can the GPS unit see the sky?");
	   } else {
			// put data in variables
			$LAT = $pieces[3];
			$NS = $pieces[4];
			$LON = $pieces[5];
			$EW = $pieces[6];
			// Convert LAT
			$deg = substr($LAT, 0, 2);
			$min = substr($LAT, 2, 8);
			$sec = '';
			$resultLAT = $deg+((($min*60)+($sec))/3600);

			// Convert Longitude
			$deg = substr($LON, 0, 3);
			$min = substr($LON, 3, 8);
			$resultLON = $deg+((($min*60)+($sec))/3600);

			// Is it East or West
			if ($EW == "W") {
			   $resultLON = $resultLON * -1;
			// Is it North or South
			if ($NS == "S") {
				$resultLAT = $resultLAT * -1;
			print ("Latitude " . $resultLAT . "<br>");
			print ("Longitude " . $resultLON . "<br>");

frameborder="0" style="border:0"


Simply use any web browser to access the page from the internet and the GPS Location of your device will be visible on a map.

My Electron Location Map:

Sorry almost forgot to mention but to use Google MAP API which is what my project is based on you will need to sign up for an API access key.
I do understand there are alternative mapping options.

Exploring the Google Mapping options should allow for a continuous route plotting and the access webpage could be modified to automatically refresh so location plotting is continuous.

If you fail to get a map position have alook at the data coming from the GPS unit.
If it has a 'GPS LOCK' the full data string will look something like...

If 'LOCK' has not yet been acheived the data will be incomplete and look something like...
And report DATA NOT VAILID in the Browser
A Visual GPS LOCK LED is now used in the circuit

If your device is not connected to the GMS Mobile Network the no data will be received at all.


Readers comments >

Date:  04-03-2016 19:19:28
From:  David
Location: France
Thanks for this, it looks quite easy to put together. I need to make a GPS tracker.

Date:  19-04-2016 21:40:34
From:  Glen Morris
Location: Healesville
I'm getting result: $GPRMC,213749.00,V,,,,,,,190416,,,N*7C Data not valid when trying to generate location map. See URL above (field wasn't long enough for the final "p" in URL). Glen

Date:  20-04-2016 09:14:39
From:  Glen Morris
Location: Healesville, Victoria, Australia
Hi Brian, I've built this project twice and both times I get the following error: result: $GPRMC,090925.00,V,,,,,,,200416,,,N*7B Data not valid Glen

Date:  01-05-2016 16:05:12
From:  Brian Moreau
Location: London
Glen it looks like your GPS unit is not locked as the data is missing the LAT and LONG CORDS. Try taking it outside :)

Date:  11-11-2016 15:37:40
From:  majdi nab
Location: liverpool
hi i am new on this field and im trying to build a particle electron with GPS shield ASSET TRACKER i want to locate my car as an example on google map so please if you could help me with that i down load your electron cod but i dont understand the website code where to put it and how thank you

Date:  16-02-2017 18:01:19
From:  Gareth Thomas
Location: Wetherby
I've made this and really like it. However, when the webpage first loads it waits for an event to be published which can take up to 10 minutes. How could we get the page opening to force the particle to publish (I think the function is already built in) so that it got a fix immediately.

Date:  18-02-2017 14:34:44
From:  Brian
@Gareth It does take a while to load yes but should only be seconds not minuets! The publish variable function is not used. The delay is the time it takes Particle to request the data from your device which should be instant or only a few milliseconds in theory. Working on a new version using TCPClient where the device sends data to a sever. Cutting out the Particle server side of things is much faster.


Leave a comment or ask me a question >

You don’t need to register to leave a comment because I feel people should not be forced to register to have their say.
All comments are checked prior to publishing to prevent spam.
Don’t worry this wont take long.
If you supply your email address below you will automatically be notified when I approve your comment.

Full name > *
eMail address > (not published)
Website > (http://...)
Location > (town or city)
Comment or question > *
Human *
  * feilds required  
Particle Electron GPS receiver an IOT Project 2016
© 2008 - 2016 - Brian Moreau

Valid XHTML 1.0 Transitional Valid CSS!