GPS Phone Location to Arduino using Bluetooth

Hi,
I am trying to send my phone location to arduino using bluetooth. I am able to connect to the app and I can see lat and long on the app but it displays as all zeros when receiving the output on arduino. Below is my code. I think it is because the coordinates are being sent as two separate texts instead of together. I am not sure how to fix this.

String a;

void loop()

{

while(bluetoothSerial.available()) {

a= Serial.readString();// read the incoming data as string

Serial.println(a);

}

This post was flagged by the community and is temporarily hidden.

If you recommend hc05 or hc06 modules and arduino code also written for these modules, do not recommend the BLE extension, because these modules do not support LE.

Here an example:

Thanks for your response. I am starting to get somewhere. I can now see data coming in but no comma to separate lat and long. I have been staring at this code for weeks and my brain is just not fresh.

String a;
void loop()
{
while (bluetoothSerial.available()) {

String a = bluetoothSerial.readString(); // Read the incoming data from Bluetooth

Serial.println(a); // Print the received data for debugging

// Split the received data into latitude and longitude

int commaIndex = a.indexOf(',');

 if (commaIndex != -1) {

  String latitudeStr = a.substring(0, commaIndex);

  String longitudeStr = a.substring(commaIndex+1);

  // Convert the latitude and longitude strings to float values

  float lat = latitudeStr.toFloat();

  float lon = longitudeStr.toFloat();

  // Now you have the latitude and longitude as separate variables (latitude and longitude)

}

// Reset for the next packet

started = false;

ended = false;

index = 0;

inData[index] = '\0';

GeoLoc phoneLoc;

phoneLoc.lat = Lat;

phoneLoc.lon = Long;

Serial.print(phoneLoc.lat, 7); Serial.print(", "); Serial.println(phoneLoc.lon, 7);

driveTo(phoneLoc, GPS_WAYPOINT_TIMEOUT);

}
}

image

That's because you did not send the comma from your AI2 code.
Use a three way text JOIN, comma in the middle.

Hi, this code actually stops the arduino from being able to receive gps data from the module I have. So, I can either receive data from gps module or phone. Not both

Hi,

I need help sending phone gps coordinates to arduino. I can see the Lat and long on the app, just not able to send the coordinates to arduino using bluetooth. Here is my code and blocks:

void loop()
{

  // Read all serial data available, as fast as possible
  while (bluetoothSerial.available() > 0)

  {

    char inChar = ((byte)bluetoothSerial.read());
    if (inChar == SOP)

    {

      index = 0;
      inData[index] = '\0';
      started = true;
      ended = false;

    }

    else if (inChar == EOP)

    {

      ended = true;
      break;

    }

    else

    {

      if (index < 79)

      {

        inData[index] = inChar;

        index++;

        inData[index] = '\0';
      }
    }

  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?

  if (started && ended)

  {

    char *token = strtok(inData, ",");

    boolean first = true;

    while (token)

    {

      double val = atof(token);

      token = strtok(NULL, ",");    

      if (first){
        Lat = val;

      }else{
        Long = val;

      }

      first = false;
    }

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';

    GeoLoc phoneLoc;
    phoneLoc.lat = Lat;
    phoneLoc.lon = Long;

    Serial.print(phoneLoc.lat, 7); Serial.print(", "); Serial.println(phoneLoc.lon, 7);
    driveTo(phoneLoc, GPS_WAYPOINT_TIMEOUT);
  }
}

This discussion might help. It shows how to send two numbers from an Android to an arduino. Note that in your example the latitude and longitude are just two numbers separated by commas by convention and this discussion shows how to do that. Try the example; if it works as shown you should be able to also transmitting the lat and lon you capture in your labels by adapting the example code.Bluetooth HC-06. Arduino. Send. Receive. Send text file. Multitouch. Image - #29 by Juan_Antonio. Juan Antonio previously sent you this link. Did you try it? Something like:
latlon will give you a start.

Hi, I thought i could help you and maybe you could help me. I can send the data via bluetooth comma delimited. However my phone app is not continuously sending updated and i have not figured that out. Does anyone want to see if they can help me? It seems it should update on every changr , but i walked around the block and it did not send new data.
I know i have to post what i have but i do not want to junk up the board with junk if there is noone reading this.

Welcome!

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

See also

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Welcome Bill.

When you walked around the block you probably walked outside the range of your device to talk to your Arduino using Bluetooth. Bluetooth has a limited range.

wow Such quick responses. Thanks guys for taking an interest.
This is the whole shooting match.. I have some other blocks that turn the text red or black that I "appropriated" from somewhere ,. I can work on that later.
So my thoughts were that every sensor long/lat change would send new data, but that is not what I see. SO... here is where I am. It works one time but I really need updates like every 500 millis so I don't lose control of my device. The vehicle essentially follows my phone.