Projects / Slot car or toy car lap timer

Slot car or toy car lap timer

Beginner1 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Test the sensors

    Each module's LED lights when a car passes. Tune the trimmer.

  2. NANO

    Mount them

    One per lane at the start-finish line, pointing across the lane.

  3. NANO

    Wire the interrupts

    Outputs to D2 and D3, which are the Nano's two interrupt pins.

  4. NANOHelloPCF8574

    Wire the LCD, buzzer and reset

    LCD on A4 and A5, buzzer on D8, reset on D4.

  5. NANO

    Upload and run

    Start a car. The first pass starts timing, and each later pass shows the lap time.

  6. NANO

    Watch the best lap

    A beep sounds when a lane sets a new best.

  7. NANO

    Reset

    Press the reset button to clear the lap times.

In short

How do you build a slot car or toy car lap timer?

A beam across the track times each lap and shows the best lap for two lanes. You need Arduino Nano, IR obstacle avoidance sensor module × 2, 16x2 LCD with I2C backpack (PCF8574), Passive buzzer, Tactile push button 6 mm, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data). It takes 7 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
8

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Lane 1 sensor OUTNano D2Interrupt, low when a car passes
Lane 2 sensor OUTNano D3Interrupt, low when a car passes
Both sensors VCC and GNDNano 5V and GNDSupply
LCD SDA and SCLNano A4 and A5Display
Passive buzzer +Nano D8New record beep
Passive buzzer -Nano GNDReturn
Reset buttonNano D4 and GNDClear the best laps

Code

Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "LiquidCrystal I2C". Timing uses micros() inside interrupts for accuracy of a few milliseconds. Mount each sensor beside its lane, pointing at the lane's side wall or at the car's body, and tune its trimmer so a passing car triggers it. Laps shorter than 0.3 seconds are ignored as bounces.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte SENSOR[2] = {2, 3}, BUZZ = 8, RESET = 4;
volatile unsigned long passAt[2] = {0, 0};
volatile bool passed[2] = {false, false};
unsigned long lastPass[2] = {0, 0}, lap[2] = {0, 0}, best[2] = {0, 0};

void isr0() { if (micros() - passAt[0] > 300000UL) { passAt[0] = micros(); passed[0] = true; } }   // ignore bounces for 0.3 s
void isr1() { if (micros() - passAt[1] > 300000UL) { passAt[1] = micros(); passed[1] = true; } }

void show() {
  for (byte i = 0; i < 2; i++) {
    lcd.setCursor(0, i);
    lcd.print("L"); lcd.print(i + 1); lcd.print(" ");
    lcd.print(lap[i] / 1000000.0, 2); lcd.print(" B ");
    lcd.print(best[i] / 1000000.0, 2); lcd.print("  ");
  }
}

void setup() {
  pinMode(RESET, INPUT_PULLUP);
  pinMode(SENSOR[0], INPUT); pinMode(SENSOR[1], INPUT);
  attachInterrupt(digitalPinToInterrupt(SENSOR[0]), isr0, FALLING);
  attachInterrupt(digitalPinToInterrupt(SENSOR[1]), isr1, FALLING);
  lcd.init(); lcd.backlight();
  show();
}

void loop() {
  for (byte i = 0; i < 2; i++) {
    if (passed[i]) {
      noInterrupts(); unsigned long t = passAt[i]; passed[i] = false; interrupts();
      if (lastPass[i] != 0) {
        lap[i] = t - lastPass[i];
        if (best[i] == 0 || lap[i] < best[i]) { best[i] = lap[i]; tone(BUZZ, 2000, 300); }   // new record
      }
      lastPass[i] = t;
      show();
    }
  }
  if (digitalRead(RESET) == LOW) {
    for (byte i = 0; i < 2; i++) { lap[i] = 0; best[i] = 0; lastPass[i] = 0; }
    show(); delay(300);
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
First passStarts timing
Second passShows the lap time to a hundredth of a second
Faster lapBeep and the best time updates
Reset buttonClears all times

If it does not work

Counts several times per pass

The car is long and triggers it more than once. The 0.3 s lockout hides this, so raise it for a longer car.

Never counts

Sensor range too short or it is pointing the wrong way. Adjust the trimmer.

Times are wrong

Check the lap is measured from the same line. Both sensors must be at the finish line.

LCD blank

Check the I2C address and contrast.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the slot car or toy car lap timer?

Arduino Nano, IR obstacle avoidance sensor module × 2, 16x2 LCD with I2C backpack (PCF8574), Passive buzzer, Tactile push button 6 mm, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data).

How long does the slot car or toy car lap timer take to build?

About 60 minutes for a beginner maker, in 7 steps.

How do I know the slot car or toy car lap timer works?

First pass: Starts timing. Second pass: Shows the lap time to a hundredth of a second. Faster lap: Beep and the best time updates.

Counts several times per pass: what should I check?

The car is long and triggers it more than once. The 0.3 s lockout hides this, so raise it for a longer car.

Never counts: what should I check?

Sensor range too short or it is pointing the wrong way. Adjust the trimmer.

Times are wrong: what should I check?

Check the lap is measured from the same line. Both sensors must be at the finish line.

LCD blank: what should I check?

Check the I2C address and contrast.