Components and supplies
Through Hole Resistor, 30 ohm
Arduino Nano R3
Resistor 10k ohm
Through Hole Resistor, 390 ohm
\t Gikfun IR LED's
RGB LCD Shield Kit, 16x2 Character Display
5 mm LED: Green
Tools and machines
Soldering iron (generic)
Project description
Code
Hot Wheels Race Timer
arduino
1//By Mike Freda - April 2020 2//Diecast electronic finish line 3//Time when start gate is open. 4//First car to break IR beam is the lane winner 5//Displays Elapsed time and winner on a 16x2 LCD. 6//times resets when start gate is closed. 7//Calculated time is in microseconds and gets converted to Seconds when displayed. Races can be that close. 8//Uses Gikfun 5mm 940nm IR LED's emitters and receivers: EK8443 9 10#include <I2CIO.h> 11#include <FastIO.h> 12#include <LCD.h> 13#include <LiquidCrystal.h> 14#include <Wire.h> 15#include <LiquidCrystal_I2C.h> 16 17LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE); // double check your LCD address first using: i2C_scanner 18 19int analogOutPin1 = A1; // finish line beam lane 1 on A1 PIN 20int analogOutPin2 = A2; // finish line beam lane 2 on A2 PIN 21 22const int ledPin1 = 11; //lane 1 winning LED on D11 PIN 23const int ledPin2 = 12; //Lane 2 winning LED in D12 PIN 24int StartSwitch = 2; 25 26int sensorValueFinish1 = 0; 27int sensorValueFinish2 = 0; 28int StartState = 0; 29 30int sensorThresh = 500; //Sets the trigger sensing threshold of the IR receivers. ~1000 = high 31 32unsigned long timeLane1; //finish line lane 1 33unsigned long timeLane2; //finish line lane 2 34float StartTime = 0; 35float ET1 = 0; 36float ET2 = 0; 37 38void setup() 39{ 40 41 Serial.begin(9600); 42 pinMode(StartSwitch, INPUT); 43 pinMode(ledPin1, OUTPUT); //lane 1 44 pinMode(ledPin2, OUTPUT); //lane 2 45 digitalWrite(ledPin1, HIGH); 46 digitalWrite(ledPin2, HIGH); 47 delay(1000); 48 digitalWrite(ledPin1, LOW); 49 digitalWrite(ledPin2, LOW); 50 StartTime = 0; 51 52 lcd.begin(16,2); 53 lcd.setCursor(0,0); 54 lcd.print("HotWheelsTimerV2"); 55 lcd.setCursor(0,1); 56 lcd.print("By: Mike Freda"); 57 delay(2000); 58 lcd.setCursor(0,1); 59 lcd.print("Ready to race..."); 60} 61 62void loop() 63{ 64 StartState = digitalRead(StartSwitch); //Check state of start gate. 0 = closed & 1 = open. 65 if(StartState == 0) 66 { 67 StartTime = 0; 68 ET1 = 0; 69 ET2 = 0; 70 } 71 72 StartState = digitalRead(StartSwitch); //if start gate is trigger, race started. 1 = open. 73 if(StartState == 1 && StartTime == 0) 74 { 75 StartTime = micros(); //use micro seconds since the races can be that close! 76 } 77 78 //read the analog in value of IR's: 79 sensorValueFinish1 = analogRead(analogOutPin1); 80 sensorValueFinish2 = analogRead(analogOutPin2); 81 82 // remove "//" from below for Debugging and checking actual sensor values. 83 // You may have to adjust sensorThresh value for better accuracy. 84 // The sensors should read around 900-1000 then go "low" (less than 400) when a car passes through the beam. 85 //Serial.println(StartTime); 86 // Serial.println(StartState); 87 // Serial.print("Sensor Finish1 = " ); 88 // Serial.println(sensorValueFinish1); 89 // Serial.print("Sensor Finish2 = " ); 90 // Serial.println(sensorValueFinish2); 91 // delay(50); 92 93 94// wait/check for the Finish Line sensors to be triggered 95 96 if(sensorValueFinish1 < sensorThresh && ET1 == 0) 97 { 98 timeLane1 = micros(); 99 ET1 = timeLane1 - StartTime; 100 ET1 = ET1 / 1000000; 101 } 102 103 if(sensorValueFinish2 < sensorThresh && ET2 == 0) 104 { 105 timeLane2 = micros(); 106 ET2 = timeLane2 - StartTime; 107 ET2 = ET2 / 1000000; 108 } 109 110 111if (ET1 < ET2 && ET1 != 0 && ET2 != 0)// Set winner Lane 1, turn on winner LED 112 { 113 digitalWrite(ledPin1, HIGH); 114 } 115 116 if(ET1 > ET2 && ET2 != 0 && ET1 != 0) // Set winner Lane 2, turn on winner LED 117 { 118 digitalWrite(ledPin2, HIGH); 119 } 120 121 if(ET1 > 0 && ET2 > 0) // Race is over, display times for both lanes. // both cars have to finish to display times. 122 { 123 lcd.clear(); 124 lcd.setCursor(0,0); 125 lcd.print("L1" ); 126 lcd.setCursor(4,0); 127 lcd.print("ET:"); 128 lcd.setCursor(6,0); 129 lcd.print(ET1, 4); 130 if (digitalRead(ledPin1) == HIGH) 131 { 132 lcd.setCursor(12,0); 133 lcd.print("*WIN*"); 134 } 135 lcd.setCursor(0,1); 136 lcd.print("L2" ); 137 lcd.setCursor(4,1); 138 lcd.print("ET:"); 139 lcd.setCursor(6,1); 140 lcd.print(ET2, 4); 141 if (digitalRead(ledPin2) == HIGH) 142 { 143 lcd.setCursor(12,1); 144 lcd.print("*WIN*"); 145 } 146 delay(8000); 147 digitalWrite(ledPin1, LOW); //turn off lane winner LED 148 digitalWrite(ledPin2, LOW); //turn off lane winner LED 149 timeLane1= 0; 150 timeLane2= 0; 151 StartTime = 0; 152 ET1 = 0; 153 ET2 = 0; 154 } 155 156}
Hot Wheels Race Timer
arduino
1//By Mike Freda - April 2020 2//Diecast electronic finish line 3//Time when start gate is open. 4//First car to break IR beam is the lane winner 5//Displays Elapsed time and winner on a 16x2 LCD. 6//times resets when start gate is closed. 7//Calculated time is in microseconds and gets converted to Seconds when displayed. Races can be that close. 8//Uses Gikfun 5mm 940nm IR LED's emitters and receivers: EK8443 9 10#include <I2CIO.h> 11#include <FastIO.h> 12#include <LCD.h> 13#include <LiquidCrystal.h> 14#include <Wire.h> 15#include <LiquidCrystal_I2C.h> 16 17LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE); // double check your LCD address first using: i2C_scanner 18 19int analogOutPin1 = A1; // finish line beam lane 1 on A1 PIN 20int analogOutPin2 = A2; // finish line beam lane 2 on A2 PIN 21 22const int ledPin1 = 11; //lane 1 winning LED on D11 PIN 23const int ledPin2 = 12; //Lane 2 winning LED in D12 PIN 24int StartSwitch = 2; 25 26int sensorValueFinish1 = 0; 27int sensorValueFinish2 = 0; 28int StartState = 0; 29 30int sensorThresh = 500; //Sets the trigger sensing threshold of the IR receivers. ~1000 = high 31 32unsigned long timeLane1; //finish line lane 1 33unsigned long timeLane2; //finish line lane 2 34float StartTime = 0; 35float ET1 = 0; 36float ET2 = 0; 37 38void setup() 39{ 40 41 Serial.begin(9600); 42 pinMode(StartSwitch, INPUT); 43 pinMode(ledPin1, OUTPUT); //lane 1 44 pinMode(ledPin2, OUTPUT); //lane 2 45 digitalWrite(ledPin1, HIGH); 46 digitalWrite(ledPin2, HIGH); 47 delay(1000); 48 digitalWrite(ledPin1, LOW); 49 digitalWrite(ledPin2, LOW); 50 StartTime = 0; 51 52 lcd.begin(16,2); 53 lcd.setCursor(0,0); 54 lcd.print("HotWheelsTimerV2"); 55 lcd.setCursor(0,1); 56 lcd.print("By: Mike Freda"); 57 delay(2000); 58 lcd.setCursor(0,1); 59 lcd.print("Ready to race..."); 60} 61 62void loop() 63{ 64 StartState = digitalRead(StartSwitch); //Check state of start gate. 0 = closed & 1 = open. 65 if(StartState == 0) 66 { 67 StartTime = 0; 68 ET1 = 0; 69 ET2 = 0; 70 } 71 72 StartState = digitalRead(StartSwitch); //if start gate is trigger, race started. 1 = open. 73 if(StartState == 1 && StartTime == 0) 74 { 75 StartTime = micros(); //use micro seconds since the races can be that close! 76 } 77 78 //read the analog in value of IR's: 79 sensorValueFinish1 = analogRead(analogOutPin1); 80 sensorValueFinish2 = analogRead(analogOutPin2); 81 82 // remove "//" from below for Debugging and checking actual sensor values. 83 // You may have to adjust sensorThresh value for better accuracy. 84 // The sensors should read around 900-1000 then go "low" (less than 400) when a car passes through the beam. 85 //Serial.println(StartTime); 86 // Serial.println(StartState); 87 // Serial.print("Sensor Finish1 = " ); 88 // Serial.println(sensorValueFinish1); 89 // Serial.print("Sensor Finish2 = " ); 90 // Serial.println(sensorValueFinish2); 91 // delay(50); 92 93 94// wait/check for the Finish Line sensors to be triggered 95 96 if(sensorValueFinish1 < sensorThresh && ET1 == 0) 97 { 98 timeLane1 = micros(); 99 ET1 = timeLane1 - StartTime; 100 ET1 = ET1 / 1000000; 101 } 102 103 if(sensorValueFinish2 < sensorThresh && ET2 == 0) 104 { 105 timeLane2 = micros(); 106 ET2 = timeLane2 - StartTime; 107 ET2 = ET2 / 1000000; 108 } 109 110 111if (ET1 < ET2 && ET1 != 0 && ET2 != 0)// Set winner Lane 1, turn on winner LED 112 { 113 digitalWrite(ledPin1, HIGH); 114 } 115 116 if(ET1 > ET2 && ET2 != 0 && ET1 != 0) // Set winner Lane 2, turn on winner LED 117 { 118 digitalWrite(ledPin2, HIGH); 119 } 120 121 if(ET1 > 0 && ET2 > 0) // Race is over, display times for both lanes. // both cars have to finish to display times. 122 { 123 lcd.clear(); 124 lcd.setCursor(0,0); 125 lcd.print("L1" ); 126 lcd.setCursor(4,0); 127 lcd.print("ET:"); 128 lcd.setCursor(6,0); 129 lcd.print(ET1, 4); 130 if (digitalRead(ledPin1) == HIGH) 131 { 132 lcd.setCursor(12,0); 133 lcd.print("*WIN*"); 134 } 135 lcd.setCursor(0,1); 136 lcd.print("L2" ); 137 lcd.setCursor(4,1); 138 lcd.print("ET:"); 139 lcd.setCursor(6,1); 140 lcd.print(ET2, 4); 141 if (digitalRead(ledPin2) == HIGH) 142 { 143 lcd.setCursor(12,1); 144 lcd.print("*WIN*"); 145 } 146 delay(8000); 147 digitalWrite(ledPin1, LOW); //turn off lane winner LED 148 digitalWrite(ledPin2, LOW); //turn off lane winner LED 149 timeLane1= 0; 150 timeLane2= 0; 151 StartTime = 0; 152 ET1 = 0; 153 ET2 = 0; 154 } 155 156}
Downloadable files
Layout Drawing PDF
PDF File
Layout Drawing PDF
Layout Drawing PDF
PDF File
Layout Drawing PDF
Layout
Layout
Comments
Only logged in users can leave comments
Hot Wheels Finish Line and Race Timer | Arduino Project Hub
scpcharlie
4 years ago
What library would need to be included on this? Looking forward to seeing it work!