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()
    {
    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: 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 Discussions: Arduino Sketch Help
  1. Arduino and Matlab (Replies: 1)

  2. LCD and an arduino (Replies: 4)

Loading...