- #1

- 32

- 0

## Main Question or Discussion Point

Hey guys, I am working on a project where I am using two photo-transistors to detect the speed of a projectile. I am trying to measure the speed of a paintball but I am getting mixed results. When a slow moving object passes through the sensors the correct speed is displayed but extremely fast objects can sometimes trick it.

Here is the sketch... It works but if you know any ways to make it more efficient please let me know, Thanks for your help!

FYI: The two sensors are 4 inches apart that is where the constant "333333" comes from the distance between the sensors in the FPS calculation

Here is the sketch... It works but if you know any ways to make it more efficient please let me know, Thanks for your help!

FYI: The two sensors are 4 inches apart that is where the constant "333333" comes from the distance between the sensors in the FPS calculation

C:

```
int firstsens = 4;
int secondsens = 5;
unsigned long time, time2;
float fps, elap;
int val;
int val2;
void setup()
{
Serial.begin(9600);
pinMode (firstsens, INPUT);
pinMode (secondsens, INPUT);
}
void loop()
{
Serial.println("Waiting for projectile...");
val = analogRead(firstsens);
val2 = analogRead(secondsens);
while (val > 1)
{
val = analogRead(firstsens);
}
while (val <= 1)
{
time = micros();
val = analogRead(firstsens);
}
while (val2 > 1)
{
val2 = analogRead(secondsens);
}
while (val2 <= 1)
{
time2 = micros();
val2 = analogRead(secondsens);
}
elap = time2 - time;
fps = 333333/elap;
Serial.println(fps );
}
```

Last edited by a moderator: