I wonder if anyone has written a code for GPS time stamping of voltages from seismic geophone (or any other sensors) digitized by internal or better external ADC connected to Arduino? Since the accuracy of at least 1 millisecond is required I believe using 1 PPS signal of the GPS is the only solution.

  • What's your application? There have been questions from... ahem... other people asking how to locate an elephant using this technique.
    – slash-dev
    Commented May 20, 2016 at 16:55
  • I am sorry for being vague. The application is to read acceleration or any other vibration monitoring sensor data in three components which has analog output in terms of voltage. The voltage readings need to be digitized and accurately time stamped and stored on microsd card. For now I am concentrated on millisecond accuracy of data stored. The next phase is to use external ADC since Arduino built in ADC has only 10 bits of resolution. Commented Jul 4, 2016 at 9:39

2 Answers 2


To tackle the time resolution and accuracy issue you could:

  1. Attach the 1PPS signal to an interrupt pin
  2. In the interrupt routine record the millis() value at the time the 1PPS signal is activated
  3. In the main loop do a non-blocking read of the GPS data to find and build up the time string as it is sent from the GPS (shortly after the 1PPS is triggered).

You now know what the millis() count was the last time a 1PPS pulse arrived, and you know the current time to within a second. The 1PPS pulse will be at HH:MM:SS.000 (or as near as damnit) so if you subtract the current millis() from your recorded 1PPS millis() value it gives you the number of milliseconds since the 1PPS pulse. Add that to the current time, and you have 1ms accuracy in the time: HH:MM:SS.iii.

  • 1
    The OP could probably use micros() instead of millis(). Along with using an Input Capture pin for the PPS, he should be able to get sub-millisecond resolution. And for a non-blocking GPS library, you can't get any better than NeoGPS. It's smaller and faster than anything else out there.
    – slash-dev
    Commented May 20, 2016 at 16:53

I doubt anyone has written software for your exact situation but you should be able to cobble something together if we break down the problem.

  1. You want to read a value from an Analog port (or external ADC)
  2. You want to read the time from a GPS.
  3. You want to write these two readings to 'somewhere'.

Looking at the Arduino IDE tutorials there are some Analog ones that would be relevant. But the only line you need is int sensorValue = analogRead(analogInPin); which reads a value between 0 and 1024 which relates to the output range of your sensor.

Now you want to read from a GPS, looking at the Software Serial Library Examples there is an example of how to setup a second serial port to read the GPS data. The GPS data will arrive once every 2 seconds. The PPS signal will arrive once every 1 second. So I'm not sure how you are going to use this to get millisecond accuracy. To get millisecond accuracy I would use the GPS data to correct a Real Time Clock connected over either the I2C or SPI bus. There are lots of example programs on reading from an RTC over these busses.

Write them to somewhere, well initially I would write them to the hardware serial port, back to you PC via USB, but then you might want to start looking at writing them to a SD card or via WIFI or GSM to a cloud storage solution.

Here are a list of the examples I looked at:

https://www.arduino.cc/en/Tutorial/AnalogInOutSerial# https://www.arduino.cc/en/Tutorial/SoftwareSerialExample# https://www.arduino.cc/en/Tutorial/Datalogger

Hope that helps

  • 1
    I would not recommend SoftwareSerial for this particular application, because it blocks interrupts for an entire character time, about 1ms. For more information, checkout the AltSoftSerial home page. AltSoftSerial is the best software serial library, if the required pins are available (depends on which Arduino you're using). A library I maintain, NeoSWSerial, is the next best choice, and it works on any two pins.
    – slash-dev
    Commented May 20, 2016 at 16:52
  • Thank you so much for your reply. This comment also applies to Majenko who answered my question promptly. Since I got your response I have had the help of an able and enthusiastic engineer colleague who wrote a code for using Adafruit GPS logger connected to Arduino Lenonado. The link to the code is: github.com/Zapalot/SynchronousSdLogger. The problem is that some data points are lost and my colleague believes it has to do with low SRAM of Leonardo. I will appreciate your opinion on this. Commented Jul 4, 2016 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.