How to calculate speed

Okay guys, need some help here.

I'm currently trying to figure out how to calculate speed at which an object crosses my x-band radar sensor, calculate speed, and with taking speed into consideration, add or subtract time to trigger an output.

Here is my code:

int calibrationTime = 15;   
int resetPin = 12;
int sensorpin = 0;                 // analog pin used to connect the radar
int val = 0;                 // variable to store the values from sensor(initially zero)
int ledPin = 6; // choose the pin for the LED 
const int threshold = 140
;   // an arbitrary threshold level that's in the range of the analog input
const int analogPin = 0;    // pin that the sensor is attached to


// AVERAGING PROTOCOL CODE
const int numReadings = 2;

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int inputPin = A0;

void setup()
{
  // initialize serial communication with computer:
  Serial.begin(9600);                   
  // initialize all the readings to 0: 
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;          
pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop() {
  // subtract the last reading:
  total= total - readings[index];         
  // read from the sensor:  
  readings[index] = analogRead(inputPin); 
  // add the reading to the total:
  total= total + readings[index];       
  // advance to the next position in the array:  
  index = index + 1;                    

  // if we're at the end of the array...
  if (index >= numReadings)              
    // ...wrap around to the beginning: 
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
  
  // added output module  
  // triggering protocol
  // if the analog value is high enough, turn on the LED:
  if (average >= threshold) {
    digitalWrite(ledPin, HIGH);
    Serial.println("Triggered");
    delay(1000);   
  } 
  else {
    digitalWrite(ledPin,LOW); 
    delay(0);   
  }
  // send it to the computer as ASCII digits
  Serial.println(average);   
  delay(0);        // delay in between reads for stability            
}

I'm thinking i probably need to consider what a car looks like approaching the xband sensor and then leaving it. Depending on the speed of the car, the serial monitor looks something like 0,0,20,45,70,150,190,190,150,70,40,20,0,0 etc. I suppose if I can figure out the exact time it takes to read each interval from the sensor??? Does anyone know what this exact number is? If I can figure out an exact time between each reading, i can calculate the time an object enters the field and exits the field, which would then give me instantaneous speed of the object, which I could then use to add or subtract time to the output (say a camera) i'm using to snap a picture in the exact same spot every time.
Any help would be infinitely appreciated.

Can't you use millis() just before or after each sensor read? Then you know the time between each read in msecs

I suppose I could, but do to my limited programming ability... I don't know how to do that. Help?

voodooman79:
I suppose I could, but do to my limited programming ability... I don't know how to do that. Help?

When you take the first recording. Assign the value of millis() to a variable:

someTime = millis();

The next time around, you can determine the time by subtracting previouisly assigned value from the current value of millis():

unsigned long elapsed = millis() - someTime;