nfarrier
Published © GPL3+

Hot Wheels Car Photogate

Measure how fast your Hot Wheels car moves at different points on your track or use it to tell how fast your race was.

IntermediateFull instructions provided4,160
Hot Wheels Car Photogate

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Through Hole Resistor, 200 kohm
Through Hole Resistor, 200 kohm
×1
Through Hole Resistor, 2k ohm
×1
High Brightness LED, White
High Brightness LED, White
×1
Adafruit Photo transistor light sensor
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Photogate Holder

Holder for photogate parts that sits under a standard flexible Hot Wheels track.

Schematics

1 photogate

Single photogate schematic

2 photogates

Two photogates schematic

Code

Single LED Photogate

Arduino
Single photogate code for measuring of the speed of a single Hot Wheels car. The code allows the photogate to work in either direction.
/* PhototransistorVoltage Hot Wheels Timer
 * Power phototransistor with 5v and GND
 * Connect the phototransistors yellow wire into A1 
 * Optional: Use a piezo buzzer connected to pin 4 and GND.
 */

const int buzzerPin = 4;  // other end of buzzer connected to GND
float threshold = 0.25;    // voltage where phototransistor shows car is in the way
const int interval = 5;  // accuracy of timer in milliseconds

void setup()                                 // Built-in initialization block
{
  Serial.begin(9600);                        // Set data rate to 9600 bps
}

float v1, timerCount;
boolean waitFor2ndTrigger;

void loop() {
  tone(buzzerPin, 440*6, 50);                   // Sound "ready"
  timerCount = 0;
  waitFor2ndTrigger = true;
  v1 = volts(A1);                                // measure voltage from phototransister in A1
  tone(buzzerPin, 880, 150);                     // Sound for start of waiting for trigger
  Serial.println("Waiting for trigger...");      // wait for  phototransistor to be dimmed
  while (v1 > threshold) { 
   delay(interval);                   // otherwise it's too fast to notice button press ((when one is used)
   v1 = volts(A1);                    // measure voltage from phototransister in A1
    }
  Serial.print("Started...");                    // Display "Start"
  
  while (waitFor2ndTrigger) {              // count time until phototransistor receives light again
    delay(interval);                       // Delay for defined time
    timerCount = timerCount+interval;      // Add time to counter
    v1 = volts(A1);                        // check A1 phototransistor
    waitFor2ndTrigger = (v1 < threshold);  // is "false" when phototransistor receives light again
    }

  // end timer count and display results
  Serial.println("Stopped");             // Display " sec." & newline
  tone(buzzerPin, 880, 50);              // Sound at finish
  delay(80);
  tone(buzzerPin, 880, 80);
  Serial.print("Final Time = ");          // Display "Final Time = "
  Serial.print(timerCount/1000);          // Display timerCount in #.### format instead of milliseconds
  Serial.println(" seconds");             // Display " sec." & newline
  Serial.print("Speed = ");               // Display "Speed = "
  Serial.print(72/(timerCount/1000));     // Display speed based on 72 mm car
  Serial.println(" mm/sec");              // Display "mm/sec" & newline
  Serial.println("");                     // print blank line
  delay(3000);                            // wait 3 seconds and reset
}
                                           
float volts(int adPin)                       // Measures volts at adPin
{                                            // Returns floating point voltage
 return float(analogRead(adPin)) * 5.0 / 1024.0;
}    

Dual photogate code

Arduino
Using two identical photogates to measure the speed of a Hot Wheels car going either direction. The code allows the photogates to work in either direction.
/* PhototransistorVoltage Hot Wheels Timer
 * Power each phototransistor with 5v and GND
 * Connect the 2 phototransistors yellow wires 
 *       into A1 & A2 to detect start and stop of car.
 * Use a piezo buzzer connected to pin 4 and GND.
 */

const int buzzerPin = 4;  // other end of buzzer connected to GND
float threshold = 0.25;    // voltage where phototransistor shows car is in the way
const int interval = 10;  // accuracy of timer in milliseconds

void setup()                                 // Built-in initialization block
{
  Serial.begin(9600);                        // Set data rate to 9600 bps
}

float v1, v2, timerCount;
boolean v1trigger, waitFor2ndTrigger;
int count=0;

void loop() {
  tone(buzzerPin, 440*6, 50);                   // Sound "ready"
  timerCount = 0;
  count = 0;
  v1 = volts(A1);                      // measure voltage from phototransister in A1
  v2 = volts(A2);                      // measure voltage from phototransister in A2
  Serial.println("Waiting...");       // wait for either phototransistor to be dimmed
  while (v1 > threshold && v2 > threshold) { 
   delay(interval);                   // otherwise it's too fast to notice button press
    v1 = volts(A1);                    // measure voltage from phototransister in A1
    v2 = volts(A2);                    // measure voltage from phototransister in A2
    }
  v1trigger = (v1 < threshold);  // find which was triggered 
  Serial.println("Start");                    // Display "Start"
  tone(buzzerPin, 880, 150);                          // Sound for start of clock
  v1 = volts(A1);
  v2 = volts(A2);
  waitFor2ndTrigger = true;                // check only A1 phototransistor
  
  while (waitFor2ndTrigger) {              // count time until 2nd probe is triggered
    delay(interval);                       // Delay for defined time
    timerCount = timerCount+interval; 
    v1 = volts(A1);
    v2 = volts(A2);
    if (v1trigger) {
      waitFor2ndTrigger = (v2 > threshold); // check A2 phototransistor
    } 
    else {
      waitFor2ndTrigger = (v1 > threshold); // check A1 phototransistor
    }
  }

  // end timer count and display results
  tone(buzzerPin, 880, 50);                   // Sound at finish
  delay(80);
  tone(buzzerPin, 880, 80);
  Serial.print("Final Time = ");       // Display "v  Final Time = "
  Serial.print(timerCount/1000);       // Display timerCount in #.### format
  Serial.println(" sec.");             // Display " sec." & newline
  Serial.println("");                  // print blank line
  delay(3000);                         // wait 3 seconds and reset
}
                                           
float volts(int adPin)                       // Measures volts at adPin
{                                            // Returns floating point voltage
 return float(analogRead(adPin)) * 5.0 / 1024.0;
}    

Credits

nfarrier

nfarrier

0 projects • 4 followers

Comments