Advise Needed: CO2 Racer Timing Gates

Hi All,

Firstly any advise on this topic would be appreciated once I get this up and running the entire project will be available on Thingiverse with DXFs. Hoping in the next 4 weeks

I’m currently creating race gates for CO2 Racers at work (Teacher), I have managed to get parts done but have run into an issue getting the timer to run with trigger wires how i intend.

im stuck at displaying time to 4 LED displays then on 2 separate button presses each timer records the time taken to press the button (more below).

The idea is to recreate http://www.envizage.com.au/race-control-timing-system/ less the solenoid launchers but these will be used in the program

Stages of the event are as follows

  1. Start button pressed

  2. 4 leds light up 1 second delay between each

  3. after random time interval between 1-4 seconds lights all go out and buzzer sounds for 1 second then stops

  4. on event 3 timer starts all 4 displays time

  5. screens 1 and 2 record time between race start and the launch (student reaction times) on solenoid switch

  6. Laser/Photo-transistor 20m away tripped by racer (Tethered by cable)

  7. LED Displays 3 and 4 stop and record time

  8. LED finish lights display winner Lane 1 / Lane 2

The process is quite simple in my head thus far

I’ll be updating this over the coming weeks as i work more out. Ive got to change the timer to have 3dp instead of the current 1.

I’ll be using 4 bit 7 segment displays once they arrive in the mail this is to allow the ability to program this on a single ATMEGA 2560

Starter.ino (2.95 KB)

Update

Ive made quite a bit of progress since last time

I will admit I was moments away from doing this in software with a Raspberry Pi but committed I’ve come back to arduino

I’ve got my timer working and have all serial outs working correctly with this.

I’ve got to now change all the serial outputs for times to be displayed on a 4-Bit Digital Tube module if anyone has suggestions on how to output 4 digits to a 4-digit display that would be great to see

any suggestions would also be taken if you see anything I’ve done terribly that could be done better

#include <Chrono.h>
#include <LightChrono.h>
#include <Chrono.h>
#include <LightChrono.h>


/* Start Tower
  turn on a LEDS when the button is pressed and let it on when the button is released
*/

int pinButton = 2; //the pin where we connect the button
int LED1 = 3; //the pin we connect the LED1
int LED2 = 4; //the pin we connect the LED2
int LED3 = 5; //the pin we connect the LED3
int LED4 = 6; //the pin we connect the LED4
int BUZZ = 7; //the pin we connect the Buzzer
int randNumber; //random number variable for start gate
int stateButton = 0; //variable for starting button status

int Trigger1 = 10; // pin that trigger 1 is connected
int Trigger2 = 11; // pin that trigger 2 is connected
int Trig1State = 0;
int Trig2State = 0;


int LASER1 = 8; //pin LASER LANE 1 is connected to
int LASER2 = 9; //pin LASER LANE 2 is connected to
int photoTran1 = A0; //pin PhotoTransistor Lane 1 is connected to
int photoTran2 = A1; //pin PhotoTransistor Lane 2 is connected to
int F1LED = 12; //pin FINISH Gate LED Winner (Lane1) is connected to
int F2LED = 13; //pin FINISH Gate LED Winner (Lane2) is connected to

int Amb1 = 0;
int Amb2 = 0;
int TrigAmb1 = 0;
int TrigAmb2 = 0;

int START = 0; //start variable
unsigned long STARTTIME = 0; //declare start time variable
unsigned long TrigTime1 = 0; //declearetrigger
unsigned long TrigTime2 = 0; //declare trigger pull


unsigned long rxncurmillis1 = 0;
unsigned long rxncurmillis2 = 0;
unsigned long fincurmillis1 = 0;
unsigned long fincurmillis2 = 0;

int Light1 = 0;
int Light2 = 0;

int trip1 = 0; //Variable to change to 1 if tripped first
int trip2 = 0; // variable to change to 1 if tripped first
int FIN1 = 0; //declate finish time lane 1
int FIN2 = 0; //declare finish time lane 2

void setup() {
  Serial.begin(9600);  // initialize serial communication at 9600 bits per second used for check data

  pinMode(pinButton, INPUT); //set the button pin as INPUT
  pinMode(LED1, OUTPUT); //set the LED1 pin as OUTPUT
  pinMode(LED2, OUTPUT); //set the LED2 pin as OUTPUT
  pinMode(LED3, OUTPUT); //set the LED3 pin as OUTPUT
  pinMode(LED4, OUTPUT); //set the LED4 pin as OUTPUT
  pinMode(BUZZ, OUTPUT); //set the BUZZ pin as OUTPUT

  pinMode(Trigger1, INPUT); //trigger 1 as input
  pinMode(Trigger2, INPUT); // Trigger 2 as input


  pinMode(photoTran1, INPUT); //set Lane 1 photo transistor to input
  pinMode(photoTran2, INPUT); //set Lane 2 photo transistor to input
  pinMode(LASER1, OUTPUT); //set Lane 1 laser to output
  pinMode(LASER2, OUTPUT); //set Lane 2 laser to output
  pinMode(F1LED, OUTPUT); //set Lane 1 LED Win to output
  pinMode(F2LED, OUTPUT); //set Lane 2 LED win to output
  digitalWrite(LASER1, HIGH); //activeate lane 1 laser
  digitalWrite(LASER2, HIGH); // activeate lane 2 laser
  delay(100);
  Amb1 = analogRead(photoTran1); // measure ambiant light of phototransistor 1
  Amb2 = analogRead(photoTran2); // measure ambiant light of phototransistor 1
  Serial.print("Lane 1 Ambient Light is: ");
  Serial.println(Amb1);
  Serial.print("Lane 2 Ambient Light is: ");
  Serial.println(Amb2);
  TrigAmb1 = 2 * Amb1; // Trigger value for finish gate 1
  TrigAmb2 = 2 * Amb2; //Trigger Value for Finish gate 2


}

void loop() {

  stateButton = digitalRead(pinButton); //read the state of the button
  //Serial.println(stateButton);  // print out the state of the button:
  // delay(50);
  if (stateButton == HIGH) { //if is pressed
    // Serial.println(stateButton);  // print out the state of the button:

    delay(2000); // 2 second pause for clearing
    digitalWrite(LED1, HIGH); //write 1 or HIGH to led1 pin
    delay(1000);
    digitalWrite(LED2, HIGH); //write 2 or HIGH to led2 pin
    delay(1000);
    digitalWrite(LED3, HIGH); //write 3 or HIGH to led3 pin
    delay(1000);
    digitalWrite(LED4, HIGH); //write 4 or HIGH to led4 pin
    delay(random(1, 4000)); //wait random 1-4 seocnds before all off and buzzer sounds
    digitalWrite(BUZZ, HIGH); //write 5 or HIGH to BUZZ pin
    digitalWrite(LED1, LOW); //write 4 or LOW to led4 pin
    digitalWrite(LED2, LOW); //write 4 or LOW to led4 pin
    digitalWrite(LED3, LOW); //write 4 or LOW to led4 pin
    digitalWrite(LED4, LOW); //write 4 or LOW to led4 pin
     START = 1; //START GLOBAL TIMER from Millis of Arduino
     STARTTIME = millis();
    Serial.print("The START TIME is: ");
    Serial.println(STARTTIME);

   
    
  }

//  do {

    Trig1State = digitalRead(Trigger1);
    Trig2State = digitalRead(Trigger2);
    /*    Serial.println("State of Trigger  1 is:");
        Serial.println(Trig1State);
      Serial.println("State of Trigger  2 is:") ;
        Serial.println(Trig2State);
        delay(1000);
    */
    if (Trig1State == HIGH) { //if Trigger 1 pressed
      rxncurmillis1 = millis();
      TrigTime1 = (rxncurmillis1 - STARTTIME);
      Serial.print("Lane 1 Reaction Time was: ");
      Serial.println(TrigTime1);
      Serial.println("Trigger 1 Works");
    }

    if (Trig2State == HIGH) { //if Trigger 1 pressed
      rxncurmillis2 = millis();
      TrigTime2 = (rxncurmillis2 - STARTTIME);
      Serial.print("Lane 2 Reaction Time was: ");
      Serial.println(TrigTime2);
      Serial.println("Trigger 2 Works");
    }

    digitalWrite(BUZZ, LOW); //write 5 or LOW to BUZZ pin buzer off after 1 second

    /*
      Serial.println("Analog Button1 is at:");
      int READ1 = analogRead(photoTran1);
      Serial.println(READ1);
      Serial.println("Analog Button2 is at:");
      int READ2 = analogRead(photoTran2);
      Serial.println(READ2);
      delay(1000);
    */


     Light1 = analogRead(photoTran1);
     Light2 = analogRead(photoTran2);

    if (Light1 > TrigAmb1) {
      fincurmillis1 = millis();
      FIN1 = (fincurmillis1 - STARTTIME);
      Serial.print("START TIME WAS: ");
      Serial.println(STARTTIME);
      Serial.print("Lane 1 Finish Time is: ");
      Serial.println(FIN1);
    }

    if (Light2 > TrigAmb2) {
        fincurmillis2 = millis();
      FIN2 = (fincurmillis2 - STARTTIME);
      Serial.print("START TIME WAS: ");
      Serial.println(STARTTIME);
      Serial.print("Lane 2 Finish Time is: ");
      Serial.println(FIN2);
    }


    if (FIN1 && FIN2 > 100) {
      int START = 2;
      //     Serial.print("The Start Variable is now: ");
      //   Serial.println(START);
    }

 // }
 // while (START == 1);

 // do {

    if (START == 2) {

      if (FIN1 < FIN2) {
        digitalWrite(F1LED, HIGH);
      }
      if (FIN2 < FIN1) {
        digitalWrite(F2LED, HIGH);
      }

      Serial.print("Lane 1 Reaction Time is: ");
      Serial.println(TrigTime1);
      Serial.print("Lane 2 Reaction Time is: ");
      Serial.println(TrigTime2);
      Serial.print("Lane 1 Race Time is: ");
      Serial.println(FIN1);
      Serial.print("Lane 2 Race Time is: ");
      Serial.println(FIN2);
      delay(5000);
    }
 // }
 // while (START == 2);

  //if race timer1 < Race timer 2
  // show LANE 1 WINNER
  //ELSE timer 2< timer 1
  //show LANE 2 WINNER

}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

It sounds like a job much more suited for an Arduino than a Raspberry Pi.
The triggers are probably the hardest part to get right.

Edited code above,

Will draw up a circuit diagram this evening, currently just went though and wired up using breadboards

The triggers were one of the simpler things to get working.

Just need to get the 4 digit time to display to the 4 digit LED display rather then through serial.

Love the code, been playing around with it - one suggestion i have is to only display the fist high state of the push button, notice if you hold the button down the reaction time keeps displaying in the serial output, i think this is the case with the finish time as well.