Go Down

Topic: speedometer code using to photosensors for arduino (Read 494 times) previous topic - next topic

rowin

Feb 14, 2013, 11:15 am Last Edit: Feb 14, 2013, 12:02 pm by rowin Reason: 1
I am actually trying to measure the speed of a simulated raindrop. Being new to arduino, any help to obtain the speed of the raindrop would be welcomed.
Thanks in advance
//Speedometer
/*This program computes the speed of a projectile using photo interrupter LED/transistor pairs,
   and displays the result on the serial monitor.
   The time elapsed between activation of two successive photo interrupters is measured.
   The distance between the respective sensors is divided by the time elapsed.
   The resulting value corresponds to the average speed during the interval between the two sensors.
   There are two photo interrupter pairs used to obtain average speed data.
   
   -------------------------------------
   |Sensor|               |Sensor |               
   |  1   |               |   2   |               
   -------------------------------------
      |<-----gateDist-------->|
*/

//Constants
const int gate1Pin = 2;  //assigns the first photointerrupter to digital I/O pin 2
const int gate2Pin = 3;  //assigns the second photointerrupter to digital I/O pin 3

//Variables
long startTime;
long travelTime;
float gateDist = 0.03;   //This is the spacing between gates in meters. The default
                         //is 0.03 m or 3 cm. This value should be adjusted accordingly
                         //if the gates are spaced closer or further apart. For example, for
                         //a gate spacing of 2.5 cm spacing you would need to
                         //replace 0.03 with 0.025, etc. for accurate result.
float travelSpeed = 0;   //the speed of traversing the two gates

void setup(){
  pinMode(gate1Pin, INPUT);
  pinMode(gate2Pin, INPUT);
  Serial.begin(19200);
}

void loop(){
  if(digitalRead(gate1Pin)<1)
  {
    startTime = micros();
    while(digitalRead(gate2Pin)>0);
    travelTime = micros() - startTime;
    travelSpeed = gateDist / travelTime * 100000000
    ;
    Serial.print("The last velocity was ");
    Serial.print(travelSpeed,0);
    Serial.print(" centimeters per second");
  } 
}

will this program work???

AWOL

Note the time your first beam is interrupted. (T0)
Note the time your second beam is interrupted. (T1)
Telapsed = T1 - T0
Approximate speed (not accounting for any acceleration) = separation of sensors in metres / Telapsed in seconds
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0AlphaOmega

#2
Feb 14, 2013, 11:28 am Last Edit: Feb 14, 2013, 11:31 am by 0AlphaOmega Reason: 1
You may also want to colour your "raindrop" with dye (food colouring?) so that it obscures the beams.

What do you have, what do you know? you can purchase optical sensors that may work if you can get your drop to fit....

Here available from ebay of course.
For whom does the clock pulse? It pulses for you!

PeterH

I only provide help via the forum - please do not contact me for private consultancy.

0AlphaOmega

You may want to use uS rather than mS, depends on your apparatus, but it will give you better resolution. Taking g and your distances, how quickly do you anticipate your droplet passing between the gates?
is it usual to measure in m/s  rather than cm (which i think are only valid in dressmaking)/s?

Did you write this code?

If you don't have a board, download a simulator for now.
For whom does the clock pulse? It pulses for you!

Go Up