Time interval between two signals

Hii,

I want to measure the time interval between the signal transmitted and received in an arduino.
As I am new to arduino I don't know how to write the code for this. So please anybody can provide a sample code for this.

Thanks...

Google "Time interval between two signals arduino".

I not got any thing.

time interval between the signal transmitted and received

Until you receive it, how do you know it was sent?

You are going to have to provide more information to get any useful answers here. Start with giving us the best thing you found so far with the Google and a long description of what you want to do differently.

I not got any thing.

What nothing? A Google whack?
No you got loads.
If you understood nothing that is another matter. Have you read how to use this forum sticky post?

We need details of these pulses, how wide are they, how frequent are they?

Basically when one goes high you make a note of the time using the millis timer. When the other goes high you make a note of the time with the millis timer. Then by subtracting one from the other you get the time between the pulses in millisecond.

But what are you actually trying to do?

Or micros() for shorter time periods. Then you might want interrupt routine to record the times as
less time-jitter is tolerable.

I would imagine code something along these lines:

unsigned long when_sent, when_received ;

void send()
{
  when_sent = micros() ;
  actually_send () ;
}

void check_received()
{
  if (received())
  {
    when_received = micros () ;
    Serial.println (when_received - when_sent);
  }
}

void loop ()
{
  check_received () ;

  if (<whatever condition>)
    send () ;
}

No sir it is not accurate.
Is there any timer that when I will send a signal start the timer and when another signal is received stop it.

neeladrinath:
No sir it is not accurate.
Is there any timer that when I will send a signal start the timer and when another signal is received stop it.

Again you are not telling us enough information about your project, just how accurate do you need it to be?

The answer to that question is, no their is no such hardware timer.

neeladrinath:
No sir it is not accurate.
Is there any timer that when I will send a signal start the timer and when another signal is received stop it.

No, and don't be a clot. All REAL accuracy is within limits. You record the time and then send the message --which will take TIME to send-- then you have a marker of the start only MICROSECONDS before the send started. You can do similar with time of reply and you need to be aware of and code for time of start receiving the reply or finish receiving reply.

With a 16MHz clock, the micros() value is good to the nearest 4 rounded up. You can look at that as "only good to 4" but if your app doesn't require closer timing and you can't engineer a solution that doesn't then you need a much faster controller.

Start by stating how exact the timing must be, there is no thing as exact-exact except in concept-land where the impossible roams freely. In the real world where nothing can be measured "exactly", working things are made as closely as needed.

You can buy resistors labeled as 220 ohm but the full spec includes the + or - tolerance as well. Like 220 ohms plus or minus 5% resistors that can be 209 to 231 ohms which are cheaper than 1% tolerance (gold band) resistors. Most circuits don't need the gold band resistor.

You can get controllers that run 10x faster than AVR's if you need much closer timing but there IS NO EXACT.

But wait... hold on. You could build a circuit external to your board using a fast Counter Timer Chip to get a closer than a microsecond timing. Even Arduino pulseIn() is only good to 4us. There's probably a TI555 circuit that's as tight on-time as you need.

Two arduino boards are there. First board will transmit a rf signal that will be received by the second board through rf receiver then the second board will transmit a signal that will received by the first board. I want to measure the time interval between the signal transmitted from first board and again received in it. From that I am going to calculate distance. I am using HC-12.
Transmitting and receiving is done. Now the problem is to calculate the time interval. after that I can calculate the distance.

. I want to measure the time interval between the signal transmitted from first board and again received in it. From that I am going to calculate distance

No you're not, you will measure the time it takes to turn arround the signal, the time of flight from one board to the other is an insignificant fraction of that time. Unless these two boards are miles away you stand no chance.

You still have not given enough information, how far are these boards apart? You know that, but we don't, what sort of time of flight does that give you? Do that calculation and see what sort of time difference you are talking about. Then compair that time with the clock speed of the Arduino.

The distance is around 200 to 300 meters.
I don't know how to calculate time.
please give some example code.

Time equals distance over velocity
T = distance / velocity

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.

So now tell me if there are any thing that can do this in arduino.

So now tell me if there are any thing that can do this in arduino.

You have already been told no several times before.

Now when you do the time calculations what time do you get that you are trying to measure?

But arduino don't know the distance no. From the time it will calculate that.

Look you seem to be not getting this.
You calculate the time it takes for a round trip to an Arduino at 300 meters.
I have given you the formula.

Look at that time and tell me if your project is feasible.

You not understood.

The system is like this.
Arduino 1
using the start button the arduino 1 will transmit signal and also a timer will start.

Arduino 2
the arduino 2 will receive the transmitted signal by arduino 1 once the arduino 2 received the signal it will transmit another signal back to the arduino 1.

Arduino 1
the arduino 1 will received that signal then stop the timer. Then the arduino 1 will determine the time.
then using formula we can get the distance.

In this system only my doubt is how to know time. I don't know about arduino timers. So please say that if there any function or instruction is available to hold this time in arduino.

You not understood.

Yes I do, I understand a lot more than you.

OK let me spell this out exactly:-

Time equals distance over velocity
T = distance / velocity
You said:-

The distance is around 200 to 300 meters.

So let's assume the distance is 200 meters. The radio wave has to go their and back so we are looking for how long it takes a radio wave to go 400 meters.

The speed of a radio wave is = 299792458 m / s, so the time it takes to travel this distance in seconds is:-
T = 400 / 299792458
so
T = 1.33uS

The Arduino's clock is 16MHz, that is the time you are trying to measure is 21 clock cycles long.
For a moment let us assume you can measure this time exactly ( you can't ) then in one clock cycle is the equivalent of radio waves traveling 19 meters. Half that for a round trip and you only get the distance to an accuracy 9.5 meters. Is that enough?

If it is enough then you have the very real problem of a computer receiving a signal and sending it back. This can not happen in zero time. This time will be way longer than 21 clock cycles you have to factor that into any measurement of the return time.

In case you want to turn a distance into time then rearranging the above formula will give you
distance = time / velocity
in fact that will be twice the distance between your two Arduinos, so you have to use:-
distance = (time / velocity) / 2

In case you do not still get it read these words:-
YOU CAN NOT DO THIS PROJECT WITH YOUR ARDUINO

OK....

I UNDERSTOOD.

Now please say how can i measure that time.