Saturday, July 30, 2011

GPS datalogger with Arduino and SD card

I recently finished making a GPS datalogger with an Arduino, a micro-SD card, and an old USB GPS unit. It continuously logs the position from a GPS unit to an SD card.

The connections are trivial with a 3.3V Arduino, since the micro-SD card has an SPI interface which the ATmega328 supports natively. I used a SiRF GPS unit, which outputs NMEA sentences at 4800bps. This was connected directly to the serial pins on the Arduino. With a 2GB SD card, we can log everything that the GPS outputs for well over a year, so I didn't bother filtering the GPS output.

The bill of materials is:
  1. 3.3V Arduino, or appropriate level shifters for the SD card
  2. GPS unit with a serial interface
  3. SD card or micro-SD card slot and memory card
  4. Some power source: car 12V plug, or USB, 9V battery
You can download the entire GPS datalogger Fritzing project. The connections and the schematic are shown below:

The associated Arduino program is trivial:
#include "FileLogger.h"

#define HEADER "Starting GPS logging.\r\n"
unsigned long header_length = sizeof(HEADER)-1;
byte header[] = HEADER;
unsigned long data_length;
byte gpsdata[128];

void setup(void) {
  FileLogger::append("data.log", header, header_length);
  data_length = 0;

void loop(void) {
  if (Serial.available() > 0) {
    gpsdata[data_length] =;
    if(data_length > 127) { 
      FileLogger::append("data.log", gpsdata, data_length);
      data_length = 0;

The Seeduino Stalker is an excellent Arduino-SD card combination that can be used for this project.

This GPS datalogger can be powered from a 12V car plug for continuous logging of a car's position. This is useful to monitor the driving habits of your teenage child, or to log the route of a long cross-country drive. Another use is for logging bicycle trips automatically (powered from solar energy and a 9V battery for backup).

This device requires no user interaction. It starts logging when the device is powered on. If the Arduino has an LED connected to pin 13, it will blink when new data is being written to the card. At the end of a month, you can copy the contents of the SD card to a computer for analysis.

Most of the Arduino pins are unused, so there is hacking potential.