I created a speed detection device to calculate the speed of a hockey shot. It involved the use of a vibration sensor attached to the net and an ultrasonic sensor attached to a shooting pad. The time between the sensors was calculated and used to get speed.
I am now trying to introduce nrf24L01 radio modules to make the system wireless. This is the receiver portion of the code. The logic I am trying to implement is that if the ultrasonic sensor gets a reading, check for vibration sensor data from the transmitter, and if the vibration Sensor data is == HIGH or 1, execute the remaining code. I am currently having difficulties trying to get the receiver to execute the remaining code after detecting the sensor data.
time = millis(); //starts the stopwatch when the code is uploaded
Serial.println(time);
ultrasonic();
if (cm < 20){
timeStart = time; // timeStart is equal to time when the ultrasonic is triggered.
Serial.print("The start time is ");
Serial.println(timeStart);
} if (radio.available()) {
radio.read(&SensorData, sizeof(SensorData));
Serial.println(SensorData[0]);
if (SensorData[0] == 1){
timeEnd = time; //timeEnd is equal to time when the the vibration sensor is triggered
Serial.print("The end time is: ");
Serial.println(timeEnd);
delay(100);
int timeFinal = timeEnd - timeStart; //get the final time and print it.
Serial.print("The final time is: ");
Serial.println(timeFinal);
delay(100);
float presetMetres = 7.62; //The meters from the shooting pad and the net. Must be pre-determined.
float PreVelocity;
PreVelocity = presetMetres/timeFinal;
Serial.print("The velocity before conversions is: ");
Serial.print(PreVelocity, 8); //The 8 is how many decimal places will be shown in the float
Serial.println("m/msec");
delay(100);
FinalVelocity = PreVelocity*3600;
Serial.print("The velocity after conversions is: ");
Serial.print(FinalVelocity, 2);
Serial.print("km/h");
Serial.print("\n");
delay(100);
for (int x = 0; x < 4; x++){
lcd.setCursor(0, x);
lcd.backlight();
lcd.print("Speed: ");
lcd.print(FinalVelocity);
lcd.print("km/h");
}
//LEDshotsequences();
}
//leaderboard();
}
}