Measuring speed using phototransistors in Arduino

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 3K views
HHOboy
Messages
32
Reaction score
0
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

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:
on Phys.org


Hello there! It sounds like you have a very interesting project on your hands. Using photo-transistors to detect the speed of a projectile is definitely a creative approach. However, it is not surprising that you are getting mixed results when trying to measure the speed of a fast-moving object like a paintball.

One way to potentially improve the efficiency of your setup is to use a higher sampling rate for your analogRead() function. This will allow you to capture more data points and potentially get a more accurate reading for the speed of the projectile. Additionally, you may want to consider using a more precise timing mechanism, such as a timer interrupt, to accurately measure the time between the two sensors being triggered.

Another potential issue could be the sensitivity of your photo-transistors. If they are not sensitive enough, they may not be able to accurately detect the fast-moving paintball. You may want to experiment with different types of sensors or adjust the sensitivity settings to see if that improves the accuracy of your readings.

Overall, it seems like you have a good starting point for your project and with some fine-tuning and adjustments, you should be able to get more consistent and accurate results. Keep up the good work and don't hesitate to reach out if you have any further questions or need more assistance. Good luck with your project!