Measuring speed using phototransistors in Arduino

AI Thread Summary
The discussion revolves around a project using two photo-transistors to measure the speed of a paintball. The user reports mixed results, with accurate readings for slow-moving objects but inconsistencies for fast-moving projectiles. The sensors are positioned four inches apart, which factors into the speed calculation. Suggestions for improvement include increasing the sampling rate of the analogRead() function to capture more data points, implementing a timer interrupt for precise timing, and potentially using more sensitive photo-transistors to enhance detection accuracy. Overall, the project shows promise, and with adjustments, more reliable results are anticipated.
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:
Technology news 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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
9
Views
2K
Replies
1
Views
7K
Replies
5
Views
4K
Replies
2
Views
15K
Replies
1
Views
3K
Back
Top