Hi guys, I would like to measure the velocity of a projectile by using two IR sensors. My idea is to record the time when the projectile passes through each sensor and calculate the velocity by using the formula distance/time. The distance between the sensors is fixed at 14.3cm. However, when I try to measure the velocity of the projectile, the recorded velocity is not consistent. Is it due to error in my coding or wiring?
Attached is the ir sensor that i used and also my coding.
For wiring, I am connecting 3.3V to VCC and outpin that I used are pin 3 and 5 respectively.
int firstsens = 3;
int secondsens = 5;
unsigned long time1,time2;
float fps,elap,ms;
int val;
int val2;
void setup() {
Serial.begin(9600);
pinMode(firstsens,INPUT);
pinMode(secondsens,INPUT);
}
void loop() {
val=digitalRead(firstsens);
val2=digitalRead(secondsens);
Serial.println("WAITING FOR PROJECTILE...");
while (val==1 && val2==1){
val=digitalRead(firstsens);
val2=digitalRead(secondsens);
}
while(val==1)
{
val=digitalRead(firstsens);
}
if(val==0)
{
time1=micros();
}
while(val2==1)
{
val2=digitalRead(secondsens);
}
if(val2==0)
{
time2=micros();
}
elap=time2-time1;
ms=0.143/(elap*0.000001);
Serial.print("Striker velocity = ");
Serial.println(ms);
delay(8000);
}
Did the data sheet information on your IR sensor tell the minimum reaction time for the sensor? If not, you need to characterize that for the sensor before you can think of using it for your project. The sensor looks like TWO LEDs one for IR light and one to receive the light. IS this the case?
Please describe the projectile and how fast it is moving. Give examples of what you mean by "not constant", and explain why you think the results should be constant.
Hint on coding: what is the value of "val" when it exits the while loop?
Paul_KD7HB:
Did the data sheet information on your IR sensor tell the minimum reaction time for the sensor? If not, you need to characterize that for the sensor before you can think of using it for your project. The sensor looks like TWO LEDs one for IR light and one to receive the light. IS this the case?
Paul
Hi Paul, I bought the sensors online and they did not mention about minimum reaction time. How should I find its minimum reaction time?
jremington:
Please describe the projectile and how fast it is moving. Give examples of what you mean by "not constant", and explain why you think the results should be constant.
Hint on coding: what is the value of "val" when it exits the while loop?
Please use code tags when posting, so it looks like the above.
The projectile is sliding along a metal rod and it is driven by pressurized air. Ideally, the velocity of projectile can reach up to 15m/s so I would also like to know whether it is possible to measure such high speed with ir sensors. FYI, I had increase the distance between sensors to 21.3cm and the value of "val" when it exits the while loop should be 0. val = 0 when the sensor detects the projectile. Currently, the highest velocity recorded is 6.77m/s.
HowToCODE:
the velocity of projectile can reach up to 15m/s so I would also like to know whether it is possible to measure such high speed with ir sensors.
15m/s is slow for IR sensors and an Arduino.
Even with slower modulated IR you can measure a 1cm object at that speed.
A gate with plain vanilla IR could be faster.
Code could make things slow though.
I would use interrupts for this.
Leo..