probleme with monitoring

hy im using a phone app sensoduino gps using blutooth hc05 to get coordinate of potholes that i detected with ultrasonic sensor but on serial it showonly 1 number of gps cordinate per time i dont know why this is the sketch

#include <NewPing.h>
#include <SoftwareSerial.h>
int trig = 2;
int echo = 3;
int max_dis = 200;
NewPing sonic(trig, echo, max_dis);
SoftwareSerial myserial(5, 6);
void setup()
{
  myserial.begin(9600);
  Serial.begin(9600);
  // put your setup code here, to run once:
}

void loop()
{
  int us = sonic.ping();
  int dis = us / US_ROUNDTRIP_CM;
  int depth = dis - 6;
  if (dis > 6 && myserial.available())
  {
    Serial.write(myserial.read());
    // put your main code here, to run repeatedly:
    Serial.print("pothole:");
    Serial.println(depth);
    delay(500);
  } // put your main code here, to run repeatedly:
}
  if (dis > 6 && myserial.available())
  {

Two questions.

  1. Do you really have a myserial attached to the Arduino? If not, and I highly doubt that you do, why are you using such a dumb name for the instance? If you used a name like gps, we’d know what you were reading from.

  2. Why do you only care what whatever you are reading from has to say when the distance is greater than 6 cm?

I suspect that you want to read, and print(), not write(), any data coming from the myserial you connected, and, independently, read and print information from distance sensor.

PaulS:

  if (dis > 6 && myserial.available())

{



Two questions.

1) Do you really have a myserial attached to the Arduino? If not, and I highly doubt that you do, why are you using such a dumb name for the instance? If you used a name like gps, we'd know what you were reading from.

2) Why do you only care what whatever you are reading from has to say when the distance is greater than 6 cm?

I suspect that you want to read, and print(), not write(), any data coming from the myserial you connected, and, independently, read and print information from distance sensor.
  1. i'm using blutooth module hc05 as myserial the name dosen't matter .
    2)i want the serial monitor to display what my phone sending (gps cordinate) when my sensor detect the pothole.
  1. i'm using blutooth module hc05 as myserial the name dosen't matter .

The name DOES matter, if you want us to help you with the code.

What you think you want, and what you actually want, are not the same thing.

Your Arduino needs to read all the incoming data ALL THE TIME. It should display the latest (GPS) data when the distance BECOMES greater than 6 cm.

It should NOT start reading, for only a few nanoseconds, when the distance IS greater than 6 cm.

There is a huge difference between the distance being more than 6 cm, and the distance becoming more than 6 cm, that you need to comprehend and deal with.

PaulS:
The name DOES matter, if you want us to help you with the code.

It is certainly better to use meaningful names but it is not essential.

…R

Robin2:
It is certainly better to use meaningful names but it is not essential.

...R

You're clearly more patient than I am.

PaulS:
The name DOES matter, if you want us to help you with the code.

What you think you want, and what you actually want, are not the same thing.

Your Arduino needs to read all the incoming data ALL THE TIME. It should display the latest (GPS) data when the distance BECOMES greater than 6 cm.

It should NOT start reading, for only a few nanoseconds, when the distance IS greater than 6 cm.

There is a huge difference between the distance being more than 6 cm, and the distance becoming more than 6 cm, that you need to comprehend and deal with.

this is another problem my main problem is how to display gps cordinate on serial monitor after detecting the distance>6. what you suggest me to do ?

chabane09:
this is another problem … what you suggest me to do ?

Solve one problem at a time.

…R

There ARE GPS data collecting/parsing libraries available. Since you seem to be in over your head, use one of them. I like TinyGPS++, except that the examples that come with it are crap.

You have two tasks on every pass through loop(). Read the GPS data, and parse it if it is complete. Read the distance sensor and show the GPS data, if you have any, when the distance is greater than 6cm.
They are independent tasks. Do not try to nest them.

PaulS:
There ARE GPS data collecting/parsing libraries available. Since you seem to be in over your head, use one of them. I like TinyGPS++, except that the examples that come with it are crap.

You have two tasks on every pass through loop(). Read the GPS data, and parse it if it is complete. Read the distance sensor and show the GPS data, if you have any, when the distance is greater than 6cm.
They are independent tasks. Do not try to nest them.

i didn't understand how can You give me the sketch ?

You give me the sketch ?

I'll give you part of it.

void loop()
{
   if(readGPSData())
   {
      if(readDistance() > 6)
      {
         showWhereThePotHoleIs();
      }
   }
}

Now, all you have to do is write three simple functions.