So I have 3 Ping)) sensors... I have 2 set up as receivers and 1 as a transmitter. I'm trying to get the distance(inches) for both of them on the serial monitor, but I keep receiving only 1 of the distances and not the other, but when I turn off one of them the other works. The problem seems to be when I need to read the signal from the PINGS))) it only reads one, what am I doing wrong?

// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); pinMode(pingPin2, INPUT); duration1 = pulseIn(pingPin2, HIGH); //THE PROBLEM SEEMS TO BE HERE duration = pulseIn(pingPin, HIGH); //THE PROBLEM SEEMS TO BE HERE

long microsecondsToInches(long microseconds){ // According to Parallax's datasheet for the PING))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf return microseconds / 74 / 2;}

So I figured it out, I did it like this:....... But now I'm trying to figure out how I can run a motor when the transmitter is in a certain direction, does anyone know a certain calculation that will allow me to dictate what the direction the transmitter is, so it can drive to it?

So I figured it out, I did it like this:....... But now I'm trying to figure out how I can run a motor when the transmitter is in a certain direction, does anyone know a certain calculation that will allow me to dictate what the direction the transmitter is, so it can drive to it?

For that, you can try which ever signal is the closest.

The main problem is that the pings)) signal is very narrow, so the receivers have to be close.

So what do you mean? how would it know which one is closer? for an example, receiver 1 is at 12 inch and receiver 2 is at 20 inch.. How would I know how far the robot has to drive or turn?

I don't understand what you're trying to achieve or how multiple ping sensors helps you achieve it. Are you trying to detect obstacles in multiple directions, or something? If so, the easiest way to read from multiple receivers is to pretend you have one sender and one receiver and do one 'ping' in the usual way, then do exactly the same thing with the sender and the other receiver. This means you will send out a separate ping for each receiver, but I don't see any harm in that.

The alternative is to use a completely different method to get the response from the receiver, which enables you to receive from two inputs simultaneously. That's going to be much harder to do, and is not the approach I'd recommend. But if you have a remote sender and you're trying to use stereo receivers to determine the direction to the source, then you will need to read them both simultaneously to see which one receives the pulse first. In this case the exact timing might not matter (you can't determine range unless you know when the pulse was sent) and all you'd care about was which receiver picked the pulse up first. I suspect you could do that using interrupts and direct port access to grab the state of both inputs with minimal latency, but it's going to need an approach that's very different to the conventional ping range finder.

I only provide help via the forum - please do not contact me for private consultancy.

Sorry about that I kinda figured it would work being that arduino has port manipulation. I thought it would be able to read and write to multiple pins that way, but NO. Yea go with normal method of just getting the data from one at a time.

It should be made into a new feature. It would be so much easier access multiple pins, if it were possible.

Sorry about that I kinda figured it would work being that arduino has port manipulation. I thought it would be able to read and write to multiple pins that way, but NO. Yea go with normal method of just getting the data from one at a time.

It should be made into a new feature. It would be so much easier access multiple pins, if it were possible.

It is possible to read and write to multiple ports simultaneously, but it requires direct access to the port registers rather than inventing a new language syntax. When you access the port registers directly you lose the benefits of the high level functions provided by Arduino, so it's the sort of thing you only want to do when really necessary. Trying to detect very small timing differences between inputs on different pins might be one of those situations where it was necessary.

I only provide help via the forum - please do not contact me for private consultancy.

I don't understand what you're trying to achieve or how multiple ping sensors helps you achieve it. Are you trying to detect obstacles in multiple directions, or something? If so, the easiest way to read from multiple receivers is to pretend you have one sender and one receiver and do one 'ping' in the usual way, then do exactly the same thing with the sender and the other receiver. This means you will send out a separate ping for each receiver, but I don't see any harm in that.

The alternative is to use a completely different method to get the response from the receiver, which enables you to receive from two inputs simultaneously. That's going to be much harder to do, and is not the approach I'd recommend. But if you have a remote sender and you're trying to use stereo receivers to determine the direction to the source, then you will need to read them both simultaneously to see which one receives the pulse first. In this case the exact timing might not matter (you can't determine range unless you know when the pulse was sent) and all you'd care about was which receiver picked the pulse up first. I suspect you could do that using interrupts and direct port access to grab the state of both inputs with minimal latency, but it's going to need an approach that's very different to the conventional ping range finder.

I'm not an expert at Arduino(how do you do direct port access), can you please help me figure out how to do that? Are you referring to something like this:(code)

The main goal is, I'm trying to figure out what's the distance(or time) difference of the 2 receivers that are located on the robot, so I can adjust the motors and drive.

The main goal is, I'm trying to figure out what's the distance(or time) difference of the 2 receivers that are located on the robot, so I can adjust the motors and drive.

So the sender itself is not being controlled by the robot, you're only trying to detect the timing difference between the pings being received by two receivers?

Perhaps just knowing which receiver was triggered first would be enough and you may not need to know the precise timing difference between the two receivers. In that case I guess your best bet would be to try to get the receivers to trigger a pin change interrupt, and in each ISR register which receiver was triggered and what time it was triggered at. The time value would enable you to ignore subsequent signals from the 'other' receiver which would presumably be caused by the same incoming ping. I don't know how reliable this would be and you may need to be smarter about how you treat the inputs from the two receivers (for example you might require both receivers to have detected the signal before you pay any attention to which one was first) but that would take more effort - I'd try the simplest approaches first.

I only provide help via the forum - please do not contact me for private consultancy.

The main goal is, I'm trying to figure out what's the distance(or time) difference of the 2 receivers that are located on the robot, so I can adjust the motors and drive.

So the sender itself is not being controlled by the robot, you're only trying to detect the timing difference between the pings being received by two receivers?

Perhaps just knowing which receiver was triggered first would be enough and you may not need to know the precise timing difference between the two receivers. In that case I guess your best bet would be to try to get the receivers to trigger a pin change interrupt, and in each ISR register which receiver was triggered and what time it was triggered at. The time value would enable you to ignore subsequent signals from the 'other' receiver which would presumably be caused by the same incoming ping. I don't know how reliable this would be and you may need to be smarter about how you treat the inputs from the two receivers (for example you might require both receivers to have detected the signal before you pay any attention to which one was first) but that would take more effort - I'd try the simplest approaches first.

I have 3 ping)) sensors... I detached the transmitter from 2, making them receivers. And detached the receiver from one making it a transmitter. So I have 2 receivers on the robot and I'm holding a transmitter I signal a ping to the transmitter and the receivers "think" they also sent out a ping, but in reality it's the transmitters. Then both receivers will wait for the echo, Im trying to configure it so both receivers receive something, that way I can calculate in what direction the transmitter is in.

For example: Ping request sentreceiver 1 10 inchesreceiver 2 15 inchesnow I know the transmitter is to the right and i can adjust the motors.

But the problem I'm facing is with my code shown earlier in the first post, I'm only getting one reading of receiver 1 and nothing for receiver 2 (and I think its because receiver 1 is getting called up first, because when I interchange and make receiver 2 read first it works and receiver 1 doesnt)

If you're trying to detect which of the receivers has responded first, you can't use pulseIn() because this will only wait for a response on one input at a time. I suggest you follow the interrupt based approach I outlined earlier.

I only provide help via the forum - please do not contact me for private consultancy.