How precise could the laser sensor be?

Hello!
I have simple project that I've found in this video: DIY Arduino Camera Shutter Speed Tester. HOW TO, less than $10! - YouTube

It actually uses a laser module and a laser sensor to check the shutter speed. I've corrected the code a bit to make it work faster. Seems like it works more or less fine. But when I check my cameras seems like all my cameras' shutters are of speed. It is more or less ok up to 1/60s or 1/125 but then it shows something about 1/200 for the speed set on my camera to 1/500 and something around 1/400 to the speed set to 1/1000. I wonder if this sensor is precise enough for speeds like so that and all my cameras are very slow or the sensor is just not able to work on speeds like that.

long Start;   // this is the time in microseconds that the shutter opens (the arduino runs a microsecond clock in the background always - it is reasonably accurate for this purpose)
long Stop;    // this is the time in microseconds that the shutter closes
bool Fired = false;  // this is a flag indicating when the shutter has been fired completely.  when fired =1, the shutter has been fired, and the computer needs to display the information related to the exposure time.
bool Risingflag = false;  // this is a flag that i set in my interrupt routine, Rising flag is set to = 1 when the voltage INCREASES in the interrupt
bool Fallingflag = false; // this is a flag that i set in the interrupt routine, Fallingflag is set to =1 when the voltage DECREASES in the interrupt
float SS1;
float SS2;
long Speed;
int pin = 2;



void setup() {                                                  //This part of the program is run exactly once on boot

  Serial.begin(115200);                                          //opens a serial connection.
  attachInterrupt(digitalPinToInterrupt(pin), CLOCK, CHANGE);    //run the function CLOCK, every time the voltage on pin 2 changes.

}

void loop() {                                                  // this part of the program is run, in order, over and over again, start to finish, unless INTERRUPTED by our interrupt
  if(Risingflag){                       
    Start = micros();       //set the variable Start to current microseconds
  Risingflag=false;           //reset the rising flag to 0, so that this function isnt called again until the shutter actually fires
  }
  if(Fallingflag){
  Stop = micros();      // set the variable Stop to current microseconds
  Fallingflag = false;      //reset the falling flag to 0, so that this function isnt called again untill the shutter fires again.
  Fired = true;            // set the fired flag to 1, triggering the calculation of a shutter speed, and its display over the serial monitor.
  }
  if(Fired){                            //if the flag Fired = 1, print this information to the serial monitor"
    Speed = (Stop - Start); 
    SS1 = (float) Speed/1000000;    // make a variable SS, which is how many seconds that the shutter open for
    SS2 = 1/SS1; 
    
    Serial.print("Start: ");
    Serial.println(Start);
    Serial.print("Stop: ");
    Serial.println(Stop);
        
    Serial.print("Microseconds: ");
    Serial.println(Speed);               //display total microseconds in shutter interval
  

                     // make a variable SS2, which is the inverse of the SS, or 1/ the shutter speed
    Serial.print("shutter speed: 1/");
    Serial.println(SS2);                //display the shutter speed
    Serial.println();
    Start = 0;                         // reset Start to 0
    Stop = 0;                           //reset Stop to 0 . *** these are not necessarily needed, but makes errors more evident should they occur
    Fired = false;                          //reset Fired flag to 0, so that the shutter speed will not be calclulated and displayed, until the next full interrupt cycle, where a start and stop time are generated.
  } 
}

void CLOCK(){                     //this is the interrupt function, which is called everytime the voltage on pin 2 changes, no matter where in the main program loop that the computer is currently in
  if(digitalRead(pin) == LOW){
    Serial.println("HIGH");
    Risingflag = true;                // if the voltage on pin 2 is high, set the Risingflag to 1 : this will trigger the function called Rising from the main loop, which will set a start time
  }
  if(digitalRead(pin) == HIGH){        // . if the voltage on pin 2 is low, set the Fallingflag to 1 : this will trigger the function called Falling from the main loop, which will set the stop time, and also set the Fired flag to 1.
    Fallingflag = true;
    Serial.println("LOW");
  }
}

Don't print in interrupt context.
Qualify shared variables as "volatile".
You can read micros() in interrupt context.

Hint: if a digitalRead doesn't read LOW, you can be certain it returns HIGH.

thanks) I've deleted "print" it wasn't there... was checking if it works at all

New code is here:

long Start;   
long Stop; 
bool Fired = false;  
bool Risingflag = false;  
bool Fallingflag = false; 
float SS1;
float SS2;
long Speed;
int pin = 2;



void setup() {                                        

  Serial.begin(115200); 
  attachInterrupt(digitalPinToInterrupt(pin), CLOCK, CHANGE);    

}

void loop() {               
  if(Risingflag){                       
    Start = micros();       
  Risingflag=false;          
  }
  if(Fallingflag){
  Stop = micros();     
  Fallingflag = false;      
  Fired = true;           
  }
  if(Fired){                         
    Speed = (Stop - Start); 
    SS1 = (float) Speed/1000000;    
    SS2 = 1/SS1; 
    
    Serial.print("Start: ");
    Serial.println(Start);
    Serial.print("Stop: ");
    Serial.println(Stop);
        
    Serial.print("Microseconds: ");
    Serial.println(Speed);               
  

                    
    Serial.print("shutter speed: 1/");
    Serial.println(SS2);                
    Serial.println();
    Start = 0;                        
    Stop = 0;                          
    Fired = false;                         
  } 
}

void CLOCK(){
  if(digitalRead(pin) == LOW){
    
    Risingflag = true;                
  }
  else{        
    Fallingflag = true;
    
  }
}

MUST be

unsigned long Start;   
unsigned long Stop; 

and these:

bool Risingflag = false;  
bool Fallingflag = false; 

MUST be declared volatile.

Have you retested the shutter measurement after changing the code?

Are you using a modulated laser source or a CW, continuous wave, laser?

This one: KY-008 650nm

I did tested the shutter again after changing code - tiny improvements, but it is the same.

Could you make a simple calibration rig, using some baffles and a record turntable?

May I suggest you eliminate all the convoluted logic. In the clock interrupt, once you determine the reason for the interrupt. just save the appropriate microsecond time in the appropriate variable.

In loop(), if both microsecond variables are NOT zero, find the difference, then set both back to zero.
Then proceed with your time calculation and display.

Like this?

long Start;   
long Stop; 

bool Fired = false;  

float SS1;
float SS2;
long Speed;
int pin = 2;



void setup() {                                        

  Serial.begin(115200); 
  attachInterrupt(digitalPinToInterrupt(pin), CLOCK, CHANGE);    

}

void loop() {               
  
  if(Fired){                         
    Speed = (Stop - Start); 
    SS1 = (float) Speed/1000000;    
    SS2 = 1/SS1; 
    
    Serial.print("Start: ");
    Serial.println(Start);
    Serial.print("Stop: ");
    Serial.println(Stop);
        
    Serial.print("Microseconds: ");
    Serial.println(Speed);               
  

                    
    Serial.print("shutter speed: 1/");
    Serial.println(SS2);                
    Serial.println();
    Start = 0;                        
    Stop = 0;                          
    Fired = false;                         
  } 
}

void CLOCK(){
  if(digitalRead(pin) == LOW){
    Start = micros(); 
                   
  }
  else{        
     Stop = micros(); 
     Fired = true;
  }
}

I guess, now the code is the fastest of what it can be. It looks like the 1/500 is more or less close to the reality, but 1/1000 is still off. I guess the latency of code execution is not that big. The question is about the sensor. It has a capacitor on board. Can it increase the sensor latency?

I don't have a turntable((

No. See post #4.

Add to it, long Start = 0;
long Stop - 0;

Change to : if ((Start !=0) && (Stop != 0))
{
Speed = (Stop - Start);
SS1 = Speed/1000000.0;
Stop = 0;
Start = 0;
}

Thank you! I did it and it all gives very tiny improvements. My main question is how fast the sensor is in detecting laser light? If it has a latency in let's say 1/200 or 1/300 sec, then I should try something else like photodiodes.

What are you using now?

this sensor: https://sl.aliexpress.ru/p?key=ISnQwXo
and this laser: https://sl.aliexpress.ru/p?key=H3MvwIQ

You may read the state of your digital pin straight from the register. That saves quite some clock cycles.
Maybe it doesn't matter as start and stop will both have the same lag...

There is a 1uf capacitor on this sensor board between VCC and GND. Can it affect the results. When the sensor goes to low from high the cap starts to give the current into a circuit and it may cause some latency. Is there any formula to calculate this latency? Or Should I just cut this cap off?

I've checked another camera and it seems to work fine. It shows 1/1000 - 1/1016 respectfully. But it looks like there is still room for errors somewhere. Sometimes it shows results very close to what it should be but sometimes it is 10-15% off. No idea if it is camera or my measuring device.