How to send data of neo 6m gps with the help of hc-05 bluetooth

Hi ! I am working on a project, where I am controlling Arduino car with the help of Bluetooth and local android app and have to send real time location of car ( through bluetooth ). I am able to control my car with bluetooth and my gps is also locating the location. But I am not able to transmit the gps data through bluetooth to a local android app. May be the problem is that bluetooth is in the receive mode (bt_RX → unoTX0 pin , bt_TX-> unoRX0 pin).

I am using Arduino uno ,L293D motor driver shield ( for controlling two motors ),
Hc-05 bluetooth and Neo 6m GPS ( gps_RX → pin 3 , gps_TX → pin 4 ).

Here is the code…

#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 gps_ss(RXPin, TXPin);

char c;
String lg,lt;

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  gps_ss.begin(GPSBaud);
}

void loop()
{  
  //Bluetooth signals 
  while(Serial.available()){ 
    c = Serial.read();
    Serial.println(c);
   
    if(c=='S')
    {
    // Stop();
      Serial.println(c);
     }

     else if(c=='F')
     {
      Serial.println("case F");
      //forward();
     }
     
      else if(c=='B')
      {
        Serial.println("case b");          
       //back();
      }
      
      else if(c=='L')  
      {
        Serial.println("case l");
      //left();
      }
      
      else if(c=='R')
      {
        Serial.println("case r");
      //right();
      }

   }
   
  //GPS signals
    gps_ss.listen();
    //Serial.println("In GPS");
  while (gps_ss.available() > 0)
  {
    gps.encode(gps_ss.read());
  
    if (gps.location.isUpdated())
    {
      Serial.print("Latitude= "); 
      lt=(gps.location.lat(),6);
      Serial.println(lt);
      Serial.print(" Longitude= "); 
      lg=(gps.location.lng(), 6);
      Serial.println(lg);
    }
  }

  
}

Any help appreciated. Thanks.

The way you are wired with the HC05 on hardware serial, you should be able to receive BT from the phone, and send to both the monitor and phone(through BT) from the Arduino.

Do you see your cases printed on the phone and monitor?
Do you see the gps data on the monitor?

Have you tried using a standard BT Serial Terminal App on the phone?

I have just tested your sketch using Kai Morich’s
Bluetooth Serial Terminal app and I can see the lat/lon being printed on both the phone and monitor with the BT wiring through hardware serial.

There are some issues with your sketch and the use of String for lt and lg. TinyGPSPlus is returning a float, and is is printed and received as ascii without any need for conversion. If for some reason, you do convert, your syntax was not correct.

#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 gps_ss(RXPin, TXPin);

char c;
//String lg,lt;


void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  gps_ss.begin(GPSBaud);
}

void loop()
{  
  //Bluetooth signals 
  while(Serial.available()){ 
    c = Serial.read();
    Serial.println(c);
   
    if(c=='S')
    {
    // Stop();
      Serial.println(c);
     }

     else if(c=='F')
     {
      Serial.println("case F");
      //forward();
     }
     
      else if(c=='B')
      {
        Serial.println("case b");          
       //back();
      }
      
      else if(c=='L')  
      {
        Serial.println("case l");
      //left();
      }
      
      else if(c=='R')
      {
        Serial.println("case r");
      //right();
      }

   }
   
  //GPS signals
    gps_ss.listen();
    //Serial.println("In GPS");
  while (gps_ss.available() > 0)
  {
    gps.encode(gps_ss.read());
  
    if (gps.location.isUpdated())
    {
      Serial.print("Latitude= "); 
      //lt= String(gps.location.lat(),6);
      //Serial.println(lt);
      Serial.println(gps.location.lat());
      Serial.print(" Longitude= "); 
      //lg=String(gps.location.lng(), 6);
      //Serial.println(lg);
      Serial.println(gps.location.lng());
    }
  }

  
}

@cattledog Thanks for sparing your time to correct my mistake.

Now, for transmitting Latitude and Longitude do I have to write Serial.write(gps.location.lat()); Serial.write(gps.location.lng()); ?? is it correct?

No. Serial.println(gps.location.lat()) will be fine.

@cattledog thanks! It is working perfectly.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.