enter image description here

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

const int trigPin = 9;
const int echoPin = 10;

long duration;
int distance;

void setup()

  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 

void loop()
  // This sketch displays information 
  // every time a new sentence is correctly encoded.
  if (ss.available() > 0)
    if (gps.location.isUpdated())
      Serial.print("Latitude= "); 
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= "); 
      Serial.println(gps.location.lng(), 6);

  // Clears the trigPin
  digitalWrite(trigPin, LOW);

  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);

  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

  // Calculating the distance
  distance= duration*0.034/2;

  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  • Ok, so you need to debug the problem. Do you have a question? – Duncan C Nov 18 '19 at 14:36
  • If you want help debugging it you'll need to tell us what GPS module you're using, point us to the docs on the module and its library, and tell us what you've done to debug the problem. Does a sample sketch come with the module, and have you tried that? – Duncan C Nov 18 '19 at 14:38
  • @DuncanC Im sorry as i am new in asking question and arduino. So ive been using neo 6m gps module. I solved the problem that i am facing right now. Thank you for your help sir, really appreciate it :) thank you for poitning out what i need to point in the questions :) – Afiq Azmii Nov 18 '19 at 14:45
  • 1
    It would be nice, if you could post an answer with your solution. I'm curious, what was the problem and how did you solved it? ;-) – Peter Paul Kiefer Nov 18 '19 at 15:11
  • 2
    I suggest you do the following: (1) Edit your question to provide the additional information. (2) Post an answer to your question where you explain how you resolved it. When you do that it helps others who have the same problem (And other people tend to up-vote answers that solve a problem, which will help you increase your reputation on the site.) – Duncan C Nov 18 '19 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.