Measuring the speed of a moving object is a fun way to explore how sensors and Arduino work together. I built this speed detector using an Arduino Nano, two IR sensor modules, a 128×64 OLED display and a buzzer.
Two IR sensors sit a fixed distance apart along a track. When a model car passes the first sensor and then the second, the Nano measures the time between them, calculates the speed and shows it on the OLED in km/h. If the car goes faster than 40 km/h, the buzzer sounds an overspeed alert.
This page covers how it works and the wiring. The complete interrupt-based Arduino code, a code walkthrough, troubleshooting tips and FAQs are in the full tutorial on my website: Arduino Car Speed Detector – full tutorial and code on Electronixity.
Note: this is a DIY demonstration for model cars on a controlled track, not a certified road-speed measurement device.
Demo video
How it works

The detector measures how long the car takes to travel between two known points:
- First detection: the car passes IR sensor 1 and the Nano records the time.
- Second detection: the car passes IR sensor 2 and the Nano records the next time.
- Elapsed time: the Nano takes the difference between the two.
- Speed: sensor spacing ÷ elapsed time, converted to km/h.
- Display and alert: the OLED shows the speed, and the buzzer sounds above 40 km/h.

Formula: Speed (km/h) = [Distance (m) ÷ Time (s)] × 3.6
Example: with the sensors 10 cm (0.10 m) apart and a travel time of 0.020 s, the speed is (0.10 ÷ 0.020) × 3.6 = 18 km/h.
Both sensors are read with hardware interrupts on D2 and D3, so even very short travel times are captured accurately.
Circuit diagram and wiring

Disconnect the Nano from USB before wiring.
IR sensors → Arduino Nano
- Sensor 1 OUT → D2
- Sensor 2 OUT → D3
- Both VCC → 5V, both GND → GND

OLED → Arduino Nano
- VCC → 5V (if your module supports it), GND → GND
- SDA → A4, SCL → A5

Buzzer → Arduino Nano
- Signal / driver input → D8, GND → GND
- Use a transistor driver if the buzzer draws more current than a Nano pin can supply.
Mount both IR sensors at the same height facing the track and measure the distance between their actual detection points carefully. Your speed reading is only as accurate as that number. Reflective IR modules react to the car's colour, surface and ambient light, so test with the real car and adjust each sensor's potentiometer if needed.
Libraries
Install Adafruit SSD1306 and Adafruit GFX Library from the Arduino IDE Library Manager (Sketch → Include Library → Manage Libraries). The sensors, interrupts and buzzer use built-in Arduino functions.
Code
The complete sketch uses interrupts on D2 and D3 to timestamp each sensor, includes a timeout for incomplete readings and shows the last measured speed. Get it, with a section-by-section explanation, here:
👉 Get the complete Arduino Car Speed Detector code on Electronixity
Before uploading, set SENSOR_DISTANCE_M to your measured spacing in metres (10 cm = 0.10) and SPEED_LIMIT_KMH to your overspeed threshold (default 40).
Testing

- Open the Serial Monitor at 9600 baud and check that the OLED shows the waiting message.
- Roll a model car past both sensors at a controlled speed.
- Check the speed on the OLED and the elapsed time in the Serial Monitor.
- Push the car faster and confirm the buzzer turns on above 40 km/h.
At 10 cm spacing, a travel time of 20 ms means 18 km/h, while 8 ms means 45 km/h (overspeed).
Not working? If the OLED is blank, the speed stays at zero, readings look wrong, the buzzer stays silent or the Nano resets, see the troubleshooting section and FAQs of the full tutorial on Electronixity.