Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Arduino Sketch Help

  1. Jul 4, 2013 #1
    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


    int firstsens = 4;
    int secondsens = 5;
    unsigned long time, time2;
    float fps, elap;
    int val;
    int val2;

    void setup()
    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: Jul 4, 2013
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted

Similar Threads - Arduino Sketch Help Date
C/++/# Help with MATLAB code? Feb 9, 2018
Reading a lot of data very quickly with Arduino? May 14, 2017
Help with an arduino project Jan 4, 2017
What do you folks think of Arduino? May 28, 2016
Arduino program Mar 21, 2016