Help on race track timer

Hi guys,

I'm to some degree a technical guy. However, I don't have much experience with Arduino yet. I have been trying to build a drag race track-timer for our (very long) HotWheels race track and got all the parts needed (hopefully), but I'm not sure how to set up the system and I don't have much idea about the codes needed. Please find attached a sketch of the system and here below the sequence of of the race process:

  1. Start Gate is closed and Micro Switch is held in.
  2. Race starts when Start Gate opens. Micro Switch simultaneously releases and sends signal (HIGH or LOW?) to Main Control Box to start the stopwatch. The Start Gate and Micro Switch remain in open position. During the race the stopwatch count is not displayed on the Display Boxes.
  3. Each Sensor at finish line sends HIGH signal to Main Control Box when each respective race car crosses the finish line. This is the signal for the stopwatch to stop for each lane.
  4. The Main Control Box display the elapsed times (ET’s) on the Display Boxes. Also, the Winner Light for the lane that has the lowest ET turns ON via a 5V relay which gets activated when it gets a LOW signal.
  5. The ET’s and the Winner Light stay ON until the Start Gate is closed. When the Start Gate is closed, ET’s are cleared, the Winner Light is turned OFF and the Main Control Box is ready for next race.
  6. Very unlikely scenario, but nice to have programmed: in case ET’s are equal to each other, both ET’s are displayed and both Winner Lights flicker until Start Gate is closed and timer resets.

Some confusion/concerns:

A. The distance from start to finish (23m) and the distance from finish to display boxes (18m). Is this too long for sending signals?
B. Do we need 1 Arduino in the Main Control Box and 1 RedBoard in each Display Box? What would you recommended?

Any help/guidance on this is highly appreciated.

Kind regards,

Although I can't really advise on (A), user @dlloyd has posted numerous schematics that might work for switches wired over long connections, e.g. :
Dirty Ac power activating uno button
How far can I send a pulse on a wire?

You can also consider MAX232 drivers (as used for RS232 serial communication).

There might be other considerations first for your project. Have you considered how to drive the displays? If these are the ones, you can not connect them directly to the Redboard as they are 12V.

You also need multiplexing as the Redboard does not have sufficient pins (4x7 plus 1 for a single display unit).

How do you 'visualize' the communication between the master and the display units? If serial, you can use RS232 or RS422 drivers which will not have a problem with long distances (RS232 can go about 100 meters, RS422 can go further).

You can consider to use one display micro (regardless if you use one or two) to also read the finish contacts and communicate that to the master. That might (?) keep the wiring between switches and controllers short.

For a permanent setup, I think that Uno or Redboard in your setup are a bit expensive and I would consider a Nano as a cheaper alternative (but if you want to use what you have available that is a moot point).

From a software perspective, this sounds like a reasonably easy project.

Thank you for the fast reply @sterretje.

The 4 digit 7-segements displays in each display box are going to be connected in series, each digit with its driver, an jumped from one to the other, just like it's done at this link:
https://learn.sparkfun.com/tutorials/large-digit-driver-hookup-guide

I have already solder these and test a sample code, powering all 4 digits straight from the Redboard. Only the first digit needs the inputs.

I'm not sure how to communicate the master to the display boards. The inputs of the (first) digits in each of the two display boxes are:

GND
LAT
CLK
SER
5V
12V

Which one of these should get its input for the master (control box)? I suppose I can connect an 12V external power to GND and 12V for each display box (unlike what I did when testing sample code), and let only the other 4 inputs coming from the control box?

Is there a more effective way to do this?

Considering the delivery time of parts (track located on Aruba) and the fact that I already have 1 Arduino and two Redboards available, I would like to carry on with these for now, we could consider more cost effective replacements in the future.

OK, I forgot about shift registers (the driver boards that you use at the back of the displays).

Those you wanted to connect to the Redboards; I'll call those the display controller. Did you change that idea because it sounds like you want to connect the driver boards to the main controller?

I don't know how you managed to power everything in your test setup from the Arduino. Did you connect the 12V and the 5V on the driver boards together? Or did you feed 12V into the driver board and to the Redboard? I guess the latter is the intention (looking at the guide).

I would definitely use a reasonably beefy power supply for the display boxes (1A@12V). Each segment takes 20mA, there are 7 plus 1 in a display and you have 4 displays to display the time. That is 640mA worst case. Add 150mA for the Redboard and a little for the driver boards and 1A should be sufficient.

Looking at your earlier picture, what is the distance between the two display boards?

Note: you will always need to connect the ground of the display drivers to both the GND of the 12V power supply and the GND of the Redboard !

If there is a way I could connect the driver of the first digit of each display box directly to the main control box (Arduino), I would prefer that. However, if I understand it correctly, then I would have to connect the GND of each of the 2 drivers to the GND of the main control box (Arduino) as well? Or shall I use the Redboard in each display box? I prefer by all means the Arduino close to the finish line (i.e. close to the sensors).

I have connected it just as in the picture attached (tutorial Sparkfun):

5V driver - 5V Redboard
12V driver - Vin Redboard

I have new 5A adapters, one for each box. (I also have to power LED winner lights, I wasn't sure about the Amps needed back then).

The distance between the two display boxes is approximately 3 meters.

I have booked some progress on the diagrams for the Main Control and Display boxes (please see attachment page 2 and 3).

My concerns: Is there anything fundamentally wrong in the diagram? Anyone an idea how to proceed further in linking the Arduino in the Main Control Box to the Redboards in the Display boxes? How do I go about the codes for the three boards?

Any help is very much appreciated!

Hotwheels Minidrag sketch and diagram.pdf (592 KB)

Little background, a switch is just a thing that makes or breaks contact between 2 wires.

You can read a pin to see if it has HIGH or LOW voltage on it. The pin can be made HIGH from a 5V source through the switch when it's closed (needs another wire and resistor to ground to drain the pin back to LOW when the switch opens) -or- the pin can be powered HIGH by the chip (through an on-chip resistor) and when the switch closes to a ground it will read LOW with no other wires or resistors.

Answer I don't know is if the second way has enough current to work at 23 meters. You're not trying to do high speed serial comms, just catch single changes in pin states which is way simpler/easier.

I have read switches through long wires by powering them with 12V and using opto-isolators (bit of overkill but easy to hook up, very reliable) to bridge to the PC port I used back then.

If there is a way I could connect the driver of the first digit of each display box directly to the main control box (Arduino),

In which case I do not see how the Redboards come into play :wink:

In theory you can do everything with one Arduino or Redboard. I honestly don't know which distance you can do with 5V for your clock/data/latch signals. If you place the Arduino between the two tracks, the distance to the finish switches and display boxes is 1.5 meters; you might get away with that and you can easily test it yourself but be prepared that it might work on your desk and not in the field.

                                           switches at
                                              finish
                                            |    |
                            +-----------+   |    |                                  +-----------+
                            |  Arduino  |<--+    |                                  |   596     |
switch at start gate ------>|           |<-------+                                  |           |
                            |           |                                           |           |
                            |           |-----------> Clk display unit 1 ---------->|           |
                            |           |-----------> Data display unit 1 --------->|           |
                            |           |-----------> Latch display unit 1 -------->|           |
                            |           |                                           +-----------+
                            |           |-----------> Clk display unit 2               ^     ^
                            |           |-----------> Data display unit 2              |     |
                            |           |-----------> Latch display unit 2             |    12V
                            |           |                                              |
                            |           |-----------> led winner1                      +--> 12V GND
                            |           |-----------> led winner2                      |
                            +-----------+                                              |
                               ^     ^                                                 |
                               |     |                                                 |
                               |     +--------------> gnd display unit 1 and display unit 2
                               |     |
                              5V   5V GND

I haven't drawn the second display unit nor the optocoupler or resistor network for the start switch.

I'm one that likes to play it safe and would use 12V communication (MAX232 comes to mind) between Arduino and display unit. A MAX232 can drive two lines, so you need 2x2 at the Arduino side and 2 in each display unit.

|             CONTROLLER               ||           DISPLAY UNIT                |
         
+-----------+       +---------------+       +---------------+       +-----------+
|  Arduino  |       |    MAX232     |       |    MAX232     |       |           |
|           |---C-->|T1 in    T1 out|--//-->|R1 in    R1 out|---C-->| 596 clk   |
|           |---D-->|T2 in    T2 out|--//-->|R2 in    R2 out|---D-->| 596 data  |
|           |       +---------------+       +---------------+       |           |
|           |                                                       |           |
|           |       +---------------+       +---------------+       |           |
|           |       |    MAX232     |       |    MAX232     |       |           |
|           |---L-->|T1 in    T1 out|--//-->|R1 in    R1 out|---L-->| 596 latch |
|           |---X-->|T2 in    T2 out|--//-->|R2 in    R2 out|---X-->| led       |
+-----------+       +---------------+       +---------------+       +-----------+

This is how I would 'play' it to be safe.

Can you provide that data sheets for the finish line sensors?

You can connect a wire to a pin and see how long it takes to fill using INPUT_PULLUP. That is how the simplest capacitive sensors work. A short wire fills so fast that a finger near it changes the count you can get, there's an example in the playground.

A long straight wire... Start the pin OUTPUT LOW to drain the wire to ground. Then using direct port manipulation (not the slow Arduino functions) change the pin to INPUT then to HIGH and start counting reads until the pin reads HIGH. That is how long THAT pin took to fill the wire with enough current to reach the 2.5 or so volts to raise it HIGH. The INPUT_PULLUP resistor on each pin may be 20K to 50K ohms so some will take longer than others but they will ALL take time filling up through the impedance of the pullup resistor.
Have someone stand near the wire or touch the far end and see how much longer it takes to fill, just for education. The total time will still be short, too short for human senses, not "a little while" or even a second.

When you ground that wire directly, not impeded, it will go LOW very quickly regardless of how long (in microseconds) it took to fill.

If you have a switch to ground that stays open longer than the fill time through the pullup then fine, you can detect the switch closing very fast and there will be a delay between when it opens and the pin goes HIGH that frankly you don't care if it takes a whole millisecond do you?
That kind of lag ruins fast communications or even slow ones on really long wires but detecting your switch is a single bit read not subject to the time of refilling the wire.

Alternate to long wires... the gate lights/flashes a led when tripped and a photodetector at the controller reads that. Light travels 300 meters per microsecond which is instant in terms of your project and can be used to communicate serial data you don't need.

Thank you for your input guys, I really appreciate it.

@GoForSmoke, I'm going to test the switch (with CAT6, at 23 meters distance) based on the way it's wired in the sketch I have until now (which is the same as in your first comment: LOW with resistor to ground when switch is open, HIGH when closed). I think a small delay does not matter much for this project, considering the time it takes a car to run the track (approximately 6 to 7 seconds, meassured with a stopwatch). However, consistency is more important for the project..

Indeed, for curiosity I will also test how long the change from LOW to HIGH takes at the distance of 23 meters.

@sterretje, I have upload a 'side view' sketch and some photo's of the track, to give a better insight on the location of the components. Microswitch at start, Main control box at finish (mounted underneath the track), Display boxes will be mounted above in the ceiling, so it can be seen from a good distance. Running the wires from Main control box to the first Display box would cover a distance of 18 meters, and then another 3 meters to the second Display box. These are measured very conservatively and could be less.

Intuitively, I considered mounting the Main control box as close as possible to the finish line sensors to cut of the stopwatch as quickly as possible. However, considering the distance for the clock/latch/data signals as you pointed out, do you think it's a better idea to have the Main control box mounted closer to the Display boxes and farther away from the microswitch at start gate (23+18 meters), and farther away from the finish line sensors (18meters)? Can I use CAT6 cables between the Main control box and the Display boxes? Does the clock, latch or data wire need to be assigned to a specific pin number on the Arduino?

Considering that we already have the Large Digit Drivers soldered already on the all display digits, I would like to try them out first. However, in case we need to go with this alternative way: what would the use of MAX232 mean for the Large Digit Drivers we currently have mounted on the display units? Would we need to replace these?

@cattledog, I have uploaded the data sheet for the finish line sensors.

I'm going to carry out some tests in coming days based on your inputs, hopefully I can get to the coding soon :sweat_smile:

Sideview.pdf (173 KB)

Datasheet Current Sensors.pdf (314 KB)

Klampe:
Thank you for your input guys, I really appreciate it.

@GoForSmoke, I'm going to test the switch (with CAT6, at 23 meters distance) based on the way it's wired in the sketch I have until now (which is the same as in your first comment: LOW with resistor to ground when switch is open, HIGH when closed). I think a small delay does not matter much for this project, considering the time it takes a car to run the track (approximately 6 to 7 seconds, meassured with a stopwatch). However, consistency is more important for the project..

Indeed, for curiosity I will also test how long the change from LOW to HIGH takes at the distance of 23 meters.

If you just connect the Arduino ends to the pin you want to read and ground and the other end wires to the switch, put in no resistor since when you test with pinMode(pin,INPUT_PULLUP) the Arduino chip will use an internal resistor to feed the pin. Any resistor you add will slow how fast the wire and pin go to ground when the switch is closed, the last thing you want!
The on-chip pullup resistor is ground-safe. Not enough current will flow from the pin to damage it, unlike the same pin moded OUTPUT then written HIGH which needs a resistor to keep from sourcing too much.

Hey, that saves you a resistor and a wire to 5V. CAT6... very thin wires but they are shielded if you ground the shield. I'd be tempted to use plain old 2-strand speaker wire if the course doesn't go through an area with running industrial strength electric motors or like.

Hey, that saves you a resistor and a wire to 5V. CAT6... very thin wires but they are shielded if you ground the shield. I'd be tempted to use plain old 2-strand speaker wire if the course doesn't go through an area with running industrial strength electric motors or like.

There is plenty of 18-2 or 20-2 twisted/shielded wire available.

It is very often used for long runs of thermostat or bell switch wire with 12v. It's got a very good chance of working a long distance with 5v, but if you have to use higher voltage and an optocoupler it's not a big impact.

What are the chances that you can't fill 23M of unterminated (switch open) wire with enough current from a 5V source through a 50K pullup to bring that wire up to 5V?

What happens when the switch closes to 23M of wire back to ground? Do you think that the pullup pin won't go LOW?

The slowness of filling the unterminated wire kills serial comms (maybe not for 300 baud) but this isn't about serial comms.

Getting fill time, only need one straight wire, not even a switch. It's just the simple cap sense with a much longer wire.
http://playground.arduino.cc/Code/CapacitiveSensor
I worried a bit about static running that sketch so I took a ceramic disk cap and bent the legs to the sides and stuck that in the pin hole instead of the wire shown. It works. It works better with a bit of foil for surface area on top.

Just a thought, the thicker the wire, the more capacitance, the longer to fill. Longer here is relative though. At 9600 baud there's a bit every 104 microseconds which does take more voltage and current to achieve over wires just 6M long. I am comparing "longer" to that expecting a few milliseconds at most.

The MAX232 is just a level converter to get the signals to RS232 levels (-12V and +12V) that are less prone to disturbances from the outside world. It's also an inverter but that is not relevant.

As there are now others in this thread that will have more experience with long distances (my knowledge of the subject is about zero :wink: ), I will leave it to them to guide you to a final solution.

Hi guys,

Hope all is well. I have been running several tests in the past days and fortunately everything seems to work perfectly despite the long distances I was initially concerned about. Thank you very much for all your help so far!

@GoForSmoke, the INPUT_PULLUP works perfectly at the long distance.

@sterretje, your wiring diagram worked perfectly as well with the common ground in the tests.

It looks like all of the hardware part is figured out. However, I have no idea on how to program the Arduino to work as the desired procedure of the race. The race procedure is revised/updated a bit (in comparison to my first post):

1. Start Gate is closed and Micro Switch is held in.
2. Race starts when Start Gate opens. Micro Switch simultaneously releases and sends LOW signal to Main Control Box to start the stopwatch. The Start Gate and Micro Switch remain in open position. During the race the stopwatch count is not displayed on the Display Boxes.
3. Each Sensor at finish line sends LOW signal to Main Control Box when each respective race car crosses the finish line. This is the signal for the stopwatch to stop for each lane.
4. The Main Control Box then shows the elapsed times (ET's) on the Display Boxes. Also, the Winner Light for the lane that has the lowest ET turns ON via a 12V relay which gets activated when it gets a LOW signal.
5. The ET's and the Winner Light stay ON until the Start Gate is closed. When the Start Gate is closed, ET's are cleared, the Winner Light is turned OFF and the Main Control Box is ready for next race.
6. Very unlikely scenario, but nice to have programmed: in case ET's are equal to each other, both ET's are displayed and both Winner Lights flicker until Start Gate is closed and the system is reset in the same fashion as a normal race.

I have uploaded a picture with the connections listed.

Does anyone have suggestions or could provide me with guidelines on how to write the codes?

Any help is again very much appreciated.

Best regards,

Do the micro switches have contact bounce or not?
If so, a capacitor across the switch will greatly simplify the needed code and accuracy of the gates.

Making light-interrupt gates (IR led + detector each) can also achieve that.

Using INPUT_PULLUP will work until the switching frequency gets too fast, inhumanly fast. Your use can't begin to get that fast. Want to see how long it takes to refill the wire from LOW to HIGH?

The best way to code this, if you want to code this (it's not a school or work project, we can help way more) is to first learn the 'many things at once' method. That way the sketch is always watching the inputs and reacting in a millisecond or less.

You might want to declare a tie if both cars are within a millisecond or even 10 millis of each other, but use micros() for timing since millis() jumps 1 every 40-some counts.

@Klampe
Use a variable to record the start time (value must be set to 0 when program starts).
Use digitalRead to read the switch at the start if start time equals 0; if low, record start time.
Use digitalRead to read the switches at the finish if start time is not 0, when they go low, record end time (one variable for each).
Calculate duration and take action.
If endtimes are set (not 0), read start switch and when it goes high, reset times to 0.