Measure the Time between two events using ardiono uno

i want to build a program that might help me to my project but i don’t have any knowledge about the arduino uno. My problem is this:

using a two arduino uno ,433Mhz transmitter/receiver , 315Mhz transmitter/receiver and LCD display. I want to measure the distance between the two arduino in meter using the time of flight. The process is that the 1st arduino will transmit 433Mhz signal then receive by the 2nd arduino, once the 2nd arduino received the first signal ,the 2nd arduino will trasnmit a 315 Mhz back to the first arduino. i want to measure the time when the first arduino transmit the 415Mhz signal and record the time once the first arduino received the 315Mhz signal. but the big problem is that i dont know how to program this one. i hope you can help me.

How do you propose measuring Rx -> Tx latency?

I don't see any possible way this could work. The clocks at each end would have to be precisely synchronized to the microsecond to start with, and then you would have to compare the two time stamps afterwards. The transmission time through the air is going to be microseconds at most, so you would need to have considerable resolution on the clocks.

And has already been noted, the latency from the time you stamped the clock at the beginning to the time the message was actually sent at the transmitter end plus the time for the receiver to process the data and stamp the clock would have to be subtracted from the result. And those times are likely to be far longer than the transmission time and the tolerance alone in those latency times would likely be far greater than the transmission time.

Why are you trying to measure the distance?

The speed of light is a foot per nanosecond. The uno clock is 16 MHz or one cycle per 62.5 ns. See a problem?

KeithRB:
The speed of light is a foot per nanosecond. The uno clock is 16 MHz or one cycle per 62.5 ns. See a problem?

Maybe this would be a good use for the delay() function ?

...R

The clocks at each end would have to be precisely synchronized to the microsecond to start with, and then you would have to compare the two time stamps afterwards.

As has been pointed out there are snags with the proposed scheme but synchronising the clocks on the 2 Arduinos is not one of them.

The OP says that he proposes to measure the time difference between Arduino 1 sending the signal initial and receiving the reply so the timing will be done on a singe Arduino.

Could you use an ultrasonic range finder instead? One Arduino with an ultrasonic device and one Arduino with a target to bounce the signal off of. Range is 2 cm to 3 m.

using the formula Distance = ( Time * Speed of light in meter) /2 . i want to measure the distance because that was our main objective in out project . Measure Distance wirlessly even with obstruction.

speed of light in meter = 299 792 458
F = 1 / Co = 3.33ns

Co/16Mhz = 18.73meters (resolution)

I know that using the 16Mhz will give me a large resolution. but it is okay. What i like to know it the time when the first arduino start to transmit then stop when it received. like a stopwatch.

I think it does not matter if the two arduino are not synchronize because only one arduino will count the time . the arduino with the display will the one that will count the time. (see the attach photo i post on my first post).

Did you read reply #3?
If not, read it again, bearing in mind the range of a 315MHz module.

(BTW, lousy thread title)

How are you intending to measure the start and stop time? What event occurs, that you can determine, that means start timing? What event occurs, that you can determine, that means stop timing?

@ AWOL : sir using the 315Mhz Rx and Tx they can communicate with in 150 meters.

The system is like this.
Arduino 1
using the start button the arduino 1 will transmit(433Mhz) signal and also the counter will start exactly once the arduino transmit the 433Mhz.

Arduino 2
the arduino 2 will receive the transmitted signal (433Mhz). once the arduino 2 received the 433Mhz signal it will transmit a new frequency which is the 315Mhz signal back to the arduino 1.

Arduino 1
the arduino 1 will received the 315Mhz signal then stop the counter. Then the arduino 1 will determine the time.

was my Idea wrong? Hope you can help me guys.

In principle, the idea is fine. But you will need to account for all the non-propagation delays.

Draw a detailed block diagram of the system and note all the delays, and determine a way to measure them.

using the start button the arduino 1 will transmit(433Mhz) signal and also the counter will start exactly once the arduino transmit the 433Mhz.

Some code? Specifically, what are you sending, using what process?

the arduino 2 will receive the transmitted signal (433Mhz). once the arduino 2 received the 433Mhz signal it will transmit a new frequency which is the 315Mhz signal back to the arduino 1.

Same questions, with the addition of how are you receiving the data? That will take time.

was my Idea wrong

Yes because you forget that the time it takes to recieve data and do something with it like start and stop a counter is way way longer than the variability you will get with the distance.

If you try this you will be back saying that no matter how far appart the two systems are you always get the same result.

That's science.

KeithRB:
That’s science.

Yes :slight_smile:
Things that work only in theory and not in practice happen when the theory is simplified to the extent of being wrong.

The uno clock is 16 MHz or one cycle per 62.5 ns. See a problem?

In case you haven't done the math, that means it travels 62.5 FEET in ONE CLOCK CYCLE. (And some instructions require 16 clock cycles (16*62.5= 1000 FEET in ONE (16-clock-cycle) INSTRUCTION CYCLE.

See a problem?

rashemel:
He already said he wasn't concerned about accuracy. I get the feeling that this is a student project and as long as he gets some kind of number, he will be happy.

There is also going to be some latency in the radios -- startup time for the SAW oscillator is not 0 and may vary on a scale of 50ns from one cycle to the next. The receiver is going to take some amount of time to lock onto the incoming 315/400MHz signal and generate the logic 1. If that's on the order of 10 cycles @ 315MHz, which I think is optimistic, that will introduce another 40 ns latency at least. Overall, the radio link would probably introduce a random latency on the scale of at least 100ns each direction, practically speaking.