Pages: [1]   Go Down
Author Topic: speedometer code using to photosensors for arduino  (Read 378 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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???
« Last Edit: February 14, 2013, 06:02:00 am by rowin » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24318
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

"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.

Offline Offline
Full Member
***
Karma: 5
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 14, 2013, 05:31:24 am by 0AlphaOmega » Logged

For whom does the clock pulse? It pulses for you!

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11148
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

will this program work???

Why don't you find out???
Logged

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

Offline Offline
Full Member
***
Karma: 5
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

For whom does the clock pulse? It pulses for you!

Pages: [1]   Go Up
Jump to: