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???