This guide walks you through wiring the IR sensor to an Arduino Nano and uploading the lap timer sketch.
- Arduino Nano (or compatible clone with USB-C or Mini-USB)
- IR obstacle sensor module (FC-51 / MH-B or similar)
- 3 jumper wires (female-to-female or female-to-male)
- USB cable (matching your Arduino)
- A computer with the Arduino IDE installed
The sensor module has three pins on one end:
| Pin | Description |
|---|---|
| VCC | Power — connect to 5V on the Arduino |
| GND | Ground — connect to GND on the Arduino |
| OUT | Digital output — connect to D2 on the Arduino |
The small blue trimpot on the module adjusts detection sensitivity/distance. Turn it clockwise to increase range, counter-clockwise to reduce it.
Connect the three sensor pins to the Arduino Nano as follows:
| Sensor Pin | Arduino Nano Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| OUT | D2 |
The wiring diagram above uses a breadboard for clarity, but you can connect the jumper wires directly from the sensor to the Arduino header pins.
- Go to https://www.arduino.cc/en/software
- Download the Arduino IDE 2 for your operating system (Windows, macOS, or Linux)
- Run the installer and follow the on-screen steps
- Launch the Arduino IDE
If you are using a clone Arduino Nano with the CH340 USB chip (common on budget boards):
- Open Arduino IDE → Preferences
- In "Additional boards manager URLs" add:
https://raw.githubusercontent.com/nanochip/arduino-boards/master/package_index.json - Go to Tools → Board → Boards Manager, search for Arduino AVR Boards, and install it
- Go to Tools → Board and select Arduino Nano
- Go to Tools → Processor and select ATmega328P (Old Bootloader) if the standard option fails to upload
- In the Arduino IDE, open File → Open
- Navigate to the
arduino/lap_sensor/folder in this project - Open
lap_sensor.ino
The sketch sends a TRIGGER line over serial (9600 baud) each time the IR beam is broken, with a 500 ms debounce to avoid duplicate triggers.
- Connect the Arduino to your computer via USB
- Go to Tools → Port and select the port that appeared when you plugged in the Arduino
- On macOS/Linux it looks like
/dev/tty.usbserial-XXXXor/dev/ttyUSB0 - On Windows it looks like
COM3,COM4, etc.
- On macOS/Linux it looks like
- Click the Upload button (→ arrow icon) or press
Ctrl+U/Cmd+U - Wait for "Done uploading" to appear in the status bar
The built-in LED on pin 13 will flash briefly each time a trigger is detected — a quick way to confirm the sensor is working without opening the serial monitor.
Position the sensor across the track so the IR beam is broken by the car as it passes. Keep the emitter and receiver facing each other at the same height as the car body.
Adjust the trimpot until the sensor LED lights up reliably when the car passes and turns off between passes.
Once the sketch is uploaded and the sensor is mounted, follow the User Guide to start the Go server and begin timing laps.




