Race Timer

This is a basic race timer that uses an ultrasonic distance sensor to determine when to start and stop timing. When the timer boots it starts in a ready mode, when a vehicle moves within 10 inches of the sensor the timer starts. Once the timer starts there is a 10 second delay before the timer will stop to allow a vehicle to move past the starting line. When the vehicle comes back an is within 10 inches of the sensor the timer stops. To reset the timer simply press the Arduino reset button.

Hardware:

  • Ultrasonic Distance Sensor
  • Arduino Uno
  • i2c 16×4 LCD Screen
  • Small Breadboard
  • Wires

Wiring:

  • Both the LCD Screen and the Distance Sensor need 5v power so we take the 5v wire from the Arduino and then split it in the breadboard.
  • i2c LCD Screen
    • ACL to A5 on Arduino
    • SDA to A4 on Arduino
    • Ground to Ground on Arduino
    • VCC to 5v split on Breadboard
  • Ultrasonic Distance Sensor
  • Trig to 9 on Arduino
  • Echo to 8 on Arduino
  • Ground to Ground on Arduino
  • VCC to 5v split on Breadboard

Code:

#include <Wire.h> #include <LCD.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7); #define trigPin 8 #define echoPin 9 long duration; float distanceCM; float distanceInch; long start_time; String race_status = "ready"; void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); lcd.begin(20, 4); lcd.setBacklightPin(3, POSITIVE); lcd.setBacklight(HIGH); lcd.setCursor(0, 0); lcd.print("RACE TIMER"); } void loop() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distanceInch = duration * 0.0133 / 2; Serial.println(" ********************* "); Serial.print("Race Status: "); Serial.println(race_status); Serial.print("Start Time: "); Serial.println(start_time); Serial.print("Current Time (millis): "); Serial.println(millis()); Serial.print("Elapsed Time: "); Serial.println(millis() - start_time); lcd.setCursor(0, 1); lcd.print("Status: "); lcd.setCursor(9, 1); lcd.print(race_status); lcd.setCursor(0, 2); lcd.print("Timer: "); if (distanceInch < 10 && race_status == "ready") { race_status = "racing"; start_time = millis(); } if (race_status == "racing") { lcd.setCursor(8, 2); lcd.print((millis() - start_time) * .001); } if ((millis() - start_time) > 10000 && distanceInch < 10) { race_status = "finished"; Serial.println(" ********************* "); Serial.print("RACE IS FINISHED at: "); Serial.println((millis() - start_time) * .001); lcd.setCursor(9, 1); lcd.print(race_status); delay(10000000); } }
Code language: PHP (php)