Arduino Robot Car with Wheel Encoders to Drive a Set Distance
Level 54 · Exactly One Metre · 30 minutes
Count the pulses from two wheel encoders, so the robot drives straight for exactly one metre and stops.

Preview the project free; a course seat is required to run and submit. No hardware kit needed.
Your project challenge
Press the button, and the robot drives straight for one metre, then stops. Wire it up: - L298N: ENA D5, IN1 D7, IN2 D8, IN3 D9, IN4 D10, ENB D6 - Wheel sensors: left D0 to D2, right D0 to D3 - Button: D4 and GND Count both wheels. The battery changes between drives.
Components you’ll use
- Arduino Uno
- L298N Motor Driver
- Battery
- TT Motor with Speed Sensor (LM393) × 2
- Pushbutton
What you’ll build
A robot that drives exactly one metre when you press its button, then stops. Not about a metre: one metre, every time.
How it works
- Each wheel has a disc with 20 slots. A sensor gives one pulse for every slot that passes.
- The wheel is 66 mm across, so one turn rolls about 207 mm. One metre is 96 pulses.
- D2 and D3 are interrupt pins.
attachInterruptcounts every pulse, even while your loop is busy.
The key idea
Count, don’t time. A fresh battery drives fast and a tired one drives slowly, but a metre is always 96 pulses.
if ((left + right) / 2 >= 96) stop
Count both wheels. No two motors turn at the same speed, so slow down whichever wheel is ahead.
⚠ Watch out
Set both counts back to zero before each drive. A real robot also rolls on a little after you stop the motors. That is fine.
The interactive editor includes the wiring guide, code editor and simulation controls.