[URGENT] Detect movements with calibrated photocells

Hello boys are days that I work on this project. At school we are studying the uniform motion and I thought of a little speed meter of a body. What I have available are two photocells (from what I understand others have already used them). The environment in which I have to show the project isn’t the same environment in which I am developing the project and then, working with light sensors (photocells), I decided to calibrate the two photocells. So everything is right, but the problem that persists, however, is how to determine a movement using the calibrated values. Here is my code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3, POSITIVE);

int valoreSensore = 0, valoreSensore1 = 0, led = 13, led1 = 2, minSensore = 1023, maxSensore = 0, minSensore1 = 1023, maxSensore1 = 0, a = 0, b = 0, velocita = 0, distanza = 0.112, secondi = 0, val = 0, val1 = 0;


void setup() {
  pinMode(led, OUTPUT);
  pinMode(led1, OUTPUT);
 
  lcd.begin (16,2);
  lcd.setBacklight(HIGH);
 
  lcd.print("Creato da");
  lcd.setCursor(0, 1);
  lcd.print("**********");

  delay(4000);
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("Sto calibrando");
  lcd.setCursor(0, 1);
  lcd.print("il primo sensore");
 
  digitalWrite(led, HIGH);
 
  while(millis() < 5000){
    valoreSensore = analogRead(A0);

    if(valoreSensore > maxSensore){
      maxSensore = valoreSensore;
    }

    if(valoreSensore < minSensore){
      minSensore = valoreSensore;
    }
  }

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("Primo sensore");
  lcd.setCursor(0, 1);
  lcd.print("calibrato!");

  digitalWrite(led, LOW);

  delay(2000);
  lcd.clear();

  lcd.print("Ora calibro il");
  lcd.setCursor(0, 1);
  lcd.print("secondo sensore!");
 
  digitalWrite(led1, HIGH);
 
  while(millis() < 8000){
    valoreSensore1 = analogRead(A2);

    if(valoreSensore1 > maxSensore1){
      maxSensore1 = valoreSensore1;
    }

    if(valoreSensore1 < minSensore1){
      minSensore1 = valoreSensore1;
    }
  }
 
  digitalWrite(led1, LOW);
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("Secondo sensore");
  lcd.setCursor(0, 1);
  lcd.print("calibrato!");

 

  delay(2000);
  lcd.clear();
}

void loop() {
  valoreSensore = analogRead(A0);
  val = valoreSensore;
  valoreSensore = map(valoreSensore, minSensore, maxSensore, 0, 255);
  valoreSensore = constrain(valoreSensore, 0, 255);

  valoreSensore1 = analogRead(A2);
  val1 = valoreSensore1;
  valoreSensore1 = map(valoreSensore1, minSensore1, maxSensore1, 0, 255);
  valoreSensore1 = constrain(valoreSensore1, 0, 255);
 

  if(val< valoreSensore){
    digitalWrite(led, HIGH);
    a = millis();
    if(val1< valoreSensore1){
      b = millis();
      digitalWrite(led1, HIGH);
      delay(2000);
      digitalWrite(led, LOW);
      digitalWrite(led1, LOW);
    }else{
      digitalWrite(led, LOW);
    }
  }

  a = (a != 0) ? a * 0.001 : 0;
  b = (b != 0) ? b * 0.001 : 0;

  secondi = ((a - b) > 0) ? (a-b) : 0;

  velocita = ((distanza / secondi)) ? (distanza / secondi) : 0;

  if(velocita > 0){
    lcd.clear();
    lcd.print(String(velocita));
    lcd.print(" m/s");
  }

  delay(1000);
}

In summary, what I need is to know how to determine the first and second passages, using calibrated sensors.
I’m desperate, I have to deliver the project tomorrow.

Sorry for my english,i’m italian!

Before anyone wastes any time, I suggest you look here first, to see if there are any solutions posted.

As i said i've to deliver the project tomorrow so i'm looking for an instant answer i'm waiting answers both here and there

. . . and I'm warning people to check, before wasting their time answering a problem that may be already resolved

a = (a != 0) ? a * 0.001 : 0;

Anything multiplied by zero is zero, so the two branches are identical.

ok thanks but i think that the problem is in the if statement,idk what i have to check to detect movements using calibrated values

I don't know what you're trying to do - if you're trying to measure the speed of an object as it obscures a pair of sensors, I'd wait for the first sensor to be obscured and then record the time, then I'd wait (or timeout) for the second sensor to be obscured and record the time, then I'd subtract the first time from the second.

I think he wants to do multiple passes through the code.
I don't know if the code works but assuming it does,
you need to clear the variables when you print the results
so it will capture another new sequence.
Dwight