Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
CarCodyAdvertise
Service recordThe Garage

DIY Self-Driving Car for Beginners: Build an Arduino LiDAR Obstacle-Avoiding Rover

Build a small Arduino rover that senses obstacles, stops, reverses, and turns. This beginner guide covers the UNO, VL53L0X and TF Mini sensors, motor-driver wiring, power safety, test sketches, and fail-safe control logic.
Entry636 Date Time19 min MechanicCarCody Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes—you can build a small car-like rover that senses an obstacle, stops, reverses, turns, and continues using an Arduino and a distance sensor. The practical beginner version is an autonomous obstacle-avoiding robot, not a road-going self-driving car. A two-wheel differential-drive chassis, dual H-bridge motor driver, Arduino UNO R3, and forward-facing VL53L0X time-of-flight sensor are the simplest starting combination.

Important scope: This project demonstrates distance measurement, motor control, feedback, and decision logic. It does not provide lane detection, localization, mapping, redundant braking, reliable human detection, public-road safety, or regulatory compliance. Test it on a raised chassis and then on a controlled indoor surface—not on a road.

The build becomes much easier when you treat it as a sequence of small tests: program the board, verify one motor, verify both motors, read one sensor, add a fail-safe stop, and only then combine everything into an avoidance routine.

What this Arduino “self-driving car” actually does

At beginner level, autonomy means a feedback loop:

  1. The distance sensor measures the space ahead.
  2. The Arduino compares that measurement with a threshold.
  3. The motor driver changes the left and right motor commands.
  4. The rover stops, backs up, turns, and checks the path again.

That is reactive obstacle avoidance. It is a useful foundation for robotics because it combines sensing, control, software states, and electromechanical hardware. It is not machine-learning autonomy, simultaneous localization and mapping, or self-driving in the automotive sense.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
This project can demonstrate It cannot safely demonstrate
DC motor control and PWM speed control Public-road driving
I2C or UART sensor communication Reliable navigation in arbitrary environments
Reactive obstacle avoidance Lane perception or traffic awareness
Basic autonomous decision-making Production-grade braking redundancy
Future upgrades such as encoders, an IMU, or wireless telemetry Guaranteed human detection, collision prevention, or regulatory compliance

The recommended beginner build

For the first working version, use a compact two-wheel differential-drive chassis. One geared DC motor drives the left wheel and another drives the right wheel; a caster supports the opposite end. The rover steers by changing the relative speed and direction of those two motors.

The simplest architecture is:

Battery → dual H-bridge motor driver → two DC motors
Arduino → motor-driver direction and PWM inputs
Arduino → I2C VL53L0X sensor

#1 Best Overall
ELEGOO UNO R3 Smart Robot Car Kit V4 with Camera, Compatible with Arduino
  • BUILD, CODE & DRIVE YOUR OWN ROBOT CAR: Turn coding, electronics and engineering into a working programmable robot car you can assemble, program and drive; ideal for weekend family projects, STEM classrooms, coding clubs, robotics lessons and maker challenges
  • EXPLORE FPV, LINE TRACKING & OBSTACLE AVOIDANCE: Control the robot with the ELEGOO app or IR remote, view live FPV video through the onboard camera, follow black lines, avoid obstacles with the ultrasonic sensor and explore multiple interactive driving modes
  • BEGINNER-FRIENDLY BUILD WITH GUIDED WIRING: Keyed XH2.54 connectors help reduce wiring mistakes, while the illustrated tutorial and example programs guide beginners step by step from chassis assembly and module connection to programming and the first successful run
  • GO BEYOND ASSEMBLY WITH CREATIVE CODING: Program with Arduino IDE to explore movement, sensors and control logic, then modify example code to create custom routes, reactions and robotics experiments that develop coding, problem-solving and engineering skills
  • COMPLETE RECHARGEABLE STEM ROBOTICS KIT: Includes an ELEGOO UNO R3 controller board, ESP32-WROVER-based camera and Wi-Fi module, line-tracking and ultrasonic sensors, motors, IR remote and a 2000 mAh rechargeable lithium-ion battery; recommended for ages 8+ with adult guidance for first-time builders

The Arduino should never power a motor directly from an I/O pin. Microcontroller pins provide control signals, not the startup and stall current a motor can require. The driver handles the higher-current motor path while the Arduino supplies direction and speed commands.

Parts list

Part Beginner recommendation What to check
Controller Arduino UNO R3 Use a genuine board or a compatible board with a documented USB interface. Confirm that your USB cable carries data.
Chassis Two-wheel robot chassis with two geared DC motors, wheels, and a caster Motor voltage, wheel clearance, mounting holes, and room for the battery and sensor.
Motor driver dual H-bridge motor driver Motor-voltage range, continuous current, startup or stall-current capability, PWM inputs, enable controls, and thermal limits.
Starter sensor VL53L0X time-of-flight sensor I2C compatibility, breakout-board voltage handling, mounting angle, and realistic range in your environment.
Power Battery holder or protected battery pack appropriate for the motors and driver Battery chemistry, voltage, current capability, connector rating, switch, charger, and protection arrangement.
Prototype hardware Arduino jumper wire kit, a solderless breadboard for Arduino, terminal blocks, and standoffs Do not route motor current through fragile breadboard rails if a direct terminal connection is available.
Programming USB data cable compatible with the board A charge-only cable will prevent uploading even when the board powers up.
Optional upgrades 470–1000 μF electrolytic capacitor, wheel encoders, second distance sensor, servo bracket, buzzer, LED, IMU, or scanning LiDAR Install upgrades after the basic robot is stable and the power budget is understood.

A bundled Arduino 2WD robot car kit can be a convenient way to obtain the chassis, motors, wheels, and basic driver together. Read the listing carefully: inexpensive kits vary, and many include an Arduino-compatible controller rather than a genuine Arduino-branded board. The kit may also omit the specific LiDAR or time-of-flight sensor, battery, charger, USB data cable, or mounting hardware needed for this design.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Buying disclosure: Product references in this guide are included only where the component solves a real build requirement. Availability, kit contents, pricing, regional shipping, and any retailer terms can change. Match every part to its own datasheet before connecting power.

Choose the Arduino board

Arduino UNO R3: the clearest first choice

The UNO R3 is the most straightforward baseline for a first build. Arduino specifies an ATmega328P, 14 digital I/O pins, six PWM-capable outputs, six analog inputs, and a 16 MHz clock. Its conventional 5 V ecosystem works conveniently with many beginner motor-driver and breakout-board examples.

The trade-off is limited memory and limited serial capability. That is rarely a problem for one VL53L0X and two motors, but it matters when you add several sensors, complex libraries, wireless control, or a scanning LiDAR.

Arduino Nano Every: compact classic-Nano alternative

The Nano Every keeps the classic Nano footprint and pin arrangement while using the ATmega4809. It has more flash and a 20 MHz clock than the classic Nano, making it a reasonable compact option when the chassis is small. Check the board’s pin labels and voltage expectations rather than assuming every Nano tutorial maps perfectly to every Nano-family board.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Arduino Nano ESP32: better for expansion

The Nano ESP32 is a stronger choice when you expect to add Wi-Fi, Bluetooth LE, telemetry, a web interface, Arduino Cloud connectivity, or more demanding computation. Arduino documents an ESP32-S3-based NORA-W106 module, USB-C, 16 MB flash, Arduino Cloud compatibility, and MicroPython support.

It is not automatically the easiest controller for a first motor-and-sensor build. The Nano ESP32 uses a 3.3 V logic environment, and board-specific pin behavior must be checked against every motor driver and sensor. A peripheral that is comfortable with UNO-level 5 V signals may need a level shifter or a different wiring arrangement on the ESP32.

Practical choice: start with an UNO R3 for the least complicated documented path; use a Nano Every when space is the main concern; choose a Nano ESP32 when wireless expansion or additional computing is part of the plan from the beginning.

Choose the distance sensor

VL53L0X: easiest first obstacle sensor

The VL53L0X is a short-range time-of-flight sensor commonly sold on an Arduino-compatible breakout. The breakout documentation describes approximately 50–1200 mm of range, I2C communication, and 3–5 V power and logic compatibility through onboard regulation and level shifting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
ELEGOO Mega 2560 R3 Project The Most Complete Starter Kit with Tutorial
  • 35+ Guided Electronics Projects: Progress from LEDs and buttons to RFID access, real-time clocks, motion and distance sensing, environmental monitoring, motor control and interactive displays for STEM learning, coding clubs and maker projects
  • More I/O and Memory for Larger Builds: The MEGA 2560 R3 provides 54 digital I/O pins, including 15 PWM outputs, 16 analog inputs, 4 hardware serial ports and 256 KB flash for projects that combine more sensors, controls and displays
  • 200+ Components for Prototyping: Includes LCD1602, RC522 RFID, RTC, DHT11, HC-SR501 PIR, ultrasonic and water-level sensors, GY-521, MAX7219, keypad, joystick, rotary encoder, relay, SG90 servo, stepper motor, DC motor, breadboard and more
  • Learn, Modify and Create: Follow 35+ guided lessons with example code, then adjust sensor thresholds, timing, display text, motor behavior and control logic to turn structured exercises into access systems, monitors, alarms and interactive projects
  • Organized for Repeatable Learning: Pre-soldered modules, a solderless breadboard, storage case and small-parts box reduce setup time and keep sensors, LEDs, ICs, wires and other components easy to find between projects

On an UNO, connect:

VL53L0X breakout Arduino UNO R3
VIN or appropriate power input 5V, only if the specific breakout supports it
GND GND
SDA A4
SCL A5

The default I2C address is typically 0x29. The sensing cone is relatively narrow, which is useful for a simple front-stop experiment but means one sensor cannot see everything beside or behind the rover. Range also depends on target reflectivity, lighting, mounting, and the exact breakout board.

Multiple VL53L0X units do not simply share the bus at their default address. Identical sensors start with the same I2C address, so you must use their shutdown pins to bring them up one at a time, assign different software addresses, and repeat that sequence after every power cycle.

Grove TF Mini LiDAR: longer forward sensing

The Grove TF Mini LiDAR is a single-point UART sensor for builders who want more forward distance than a short-range ToF breakout. Seeed lists a 5 m maximum operating range at 10% reflectivity, 100 Hz measurement frequency, 1 cm resolution, and an applicable voltage of 4.5–6 V for the Grove module. The serial interface uses 3.3 V TTL levels, and the Grove documentation shows a 115200 default for the module.

This is a useful upgrade, but it introduces more integration decisions: UART wiring, baud rate, serial-port availability, voltage levels, and packet parsing. On an UNO, USB programming and the sensor can compete for the board’s limited hardware serial resources. Use a compatible serial arrangement, a suitable software-serial approach after checking its timing limits, or a board with more convenient serial capability.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not connect a 5 V Arduino transmit signal to a 3.3 V UART input without confirming compatibility or using the appropriate level conversion. The sensor’s applicable supply voltage and its signal voltage are separate questions.

RPLIDAR A1M8: advanced scanning sensor

The RPLIDAR A1M8 is a different class of component. Rather than returning one forward distance, a scanning LiDAR produces angular range data that can support richer obstacle maps. It also adds mechanical mounting, power, protocol, rotating hardware, and software complexity. SLAMTEC provides datasheet, development-kit, and SDK material for the product.

Use a scanning LiDAR after the basic rover is reliable and you have a suitable controller or companion computer. It is not the sensible first sensor for a small UNO-based obstacle-avoidance experiment.

Sensor Best use Main limitation
VL53L0X First forward-facing stop-and-turn project Shorter range and narrow field of view
Grove TF Mini LiDAR Longer-range single-point forward sensing UART, baud-rate, and logic-level complexity
RPLIDAR A1M8 Angular scans and richer mapping experiments Much greater hardware and software complexity

Wire the rover safely

Use the following UNO pin assignment as a reference for a driver with two PWM enable inputs and four direction inputs. The driver’s labels may be different, so follow the selected driver’s documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
UNO pin Connects to Purpose
D5 Left-driver enable or PWM input Left motor speed
D7 and D8 Left-driver direction inputs Left motor direction
D6 Right-driver enable or PWM input Right motor speed
D9 and D10 Right-driver direction inputs Right motor direction
A4 VL53L0X SDA I2C data
A5 VL53L0X SCL I2C clock
GND Driver ground and sensor ground Common signal reference

Connect the motors to the driver’s motor outputs, not to Arduino pins. Connect the battery to the driver’s motor-power input according to the driver and motor ratings. Power the sensor and Arduino through the appropriate regulated path for the selected hardware. Connect the controller and driver grounds together, but keep high-current motor wiring physically separate from sensitive sensor wiring where practical.

Rank #3
ELEGOO UNO R3 Project Super Starter Kit with PDF Tutorial for Beginners
  • TURN CODE INTO REAL-WORLD RESULTS — Follow 22+ guided lessons to make LEDs blink, read temperature and distance, move servo and stepper motors, control an LCD and respond to joystick or IR input; ideal for a family weekend build, homeschool unit, coding club or STEM classroom
  • MORE PROJECT VARIETY IN ONE ORGANIZED KIT — Includes the UNO R3 controller, LCD1602 with pre-soldered header, breadboard power module, ultrasonic and DHT11 sensors, joystick, IR receiver and remote, SG90 servo, stepper motor, relay, DC motor, fan blade, displays, LEDs, buttons, resistors and jumper wires
  • START WITHOUT SOLDERING — Plug-in modules, a solderless breadboard and the pre-soldered LCD help beginners focus on wiring, code and testing; the illustrated component list makes it easier to find each part and move from one lesson to the next
  • LEARN THE LOGIC, THEN CREATE YOUR OWN — Use Arduino IDE and the included example code to understand digital input and output, analog sensing, timing, motor control and display functions, then change thresholds, speeds and sequences for alarms, environmental monitors, reaction games and motion projects
  • CLEAR SETUP SUPPORT FOR FIRST-TIME BUILDERS — Download the latest tutorial and code, select the UNO board and correct computer port, check component polarity and breadboard rows, and keep power-module input at 9V or below; younger learners should work with an experienced adult

Some common H-bridge modules have enable jumpers. If the enable pin is permanently tied high by a jumper, the PWM speed-control pin in the example cannot control speed until that jumper is configured appropriately. Check the module’s labeling before applying power.

Motor startup and stall currents can cause supply droop, electrical noise, Arduino resets, or corrupted sensor readings. Shorten high-current wiring, use a supply with adequate current capability, and consider a 470–1000 μF electrolytic capacitor across the motor supply near the driver. Confirm the capacitor’s voltage rating and polarity before installation.

A physical power switch is strongly recommended. Begin testing with the wheels lifted off the floor. For lithium batteries, use a charger and protection arrangement intended for that exact battery chemistry and never leave a lithium battery charging unattended.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build in five controlled tests

1. Prepare Arduino IDE 2

  1. Install Arduino IDE 2.
  2. Connect the board with a known-good USB data cable.
  3. Open Tools > Board > Boards Manager if the board package is not installed. Search for the board family and install the appropriate package.
  4. Select the board under Tools > Board.
  5. Select the detected USB port under Tools > Port.
  6. Upload a Blink example before connecting motors or batteries.
  7. Open the Serial Monitor from the IDE and select the baud rate used by the sketch when you begin sensor testing.

If the board powers up but does not appear, first try another USB data cable, USB port, and board selection. Verify the board vendor’s or USB-to-serial chip manufacturer’s driver guidance before considering third-party software.

2. Test one motor channel

Lift the wheels clear of the floor. Disconnect the motors from the autonomous logic and test one driver channel at a time. Confirm that positive PWM produces the expected forward direction, negative logic produces reverse, and zero produces stop.

const int ENA = 5;
const int IN1 = 7;
const int IN2 = 8;

void setup() {
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
}

void loop() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 150);
delay(1000);

analogWrite(ENA, 0);
delay(500);

digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(ENA, 150);
delay(1000);

analogWrite(ENA, 0);
delay(1000);
}

If the motor runs backward, swap its motor wires or reverse the software’s logical polarity. Do not diagnose the complete autonomous program until this basic test works.

3. Test both motors

Add the second channel and test forward, reverse, left, right, and stop. A basic open-loop rover will often drift because the motors, gears, tires, and floor are not identical. That is normal. Reduce speed and calibrate the two sides before attempting obstacle avoidance.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Read the VL53L0X alone

Install the appropriate VL53L0X library through Sketch > Include Library > Manage Libraries in Arduino IDE 2. Start with the vendor example before writing your own parser. A minimal test using the commonly documented Adafruit library is:

#include <Wire.h>
#include <Adafruit_VL53L0X.h>

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {
Serial.begin(115200);
while (!Serial) { delay(1); }

if (!lox.begin()) {
Serial.println(&quot;VL53L0X not found&quot;);
while (1) { delay(10); }
}
}

void loop() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&quot;&amp;measure&quot;, false);

if (measure.RangeStatus != 4) {
Serial.print(&quot;Distance: &quot;);
Serial.print(measure.RangeMilliMeter);
Serial.println(&quot; mm&quot;);
} else {
Serial.println(&quot;Out of range or invalid&quot;);
}

delay(100);
}

Point the sensor at a nearby, non-moving target and verify that the Serial Monitor changes as you move it. On an UNO, the I2C bus uses A4 for SDA and A5 for SCL. I2C uses 7-bit addresses, and the Wire library has a limited buffer, so avoid assuming that a sketch designed for another board or sensor family will transfer unchanged.

Rank #4
ELEGOO UNO R3 Project Most Complete Starter Kit, Compatible with Arduino
  • 30+ Guided Electronics Projects: Start with LEDs and build toward LCD1602 displays, RFID access, motion detection, distance sensing, motor control and environmental monitoring for STEM learning, coding clubs, classrooms and hobby projects
  • 200+ Components Across 63 Types: Includes an ELEGOO UNO R3 controller, LCD1602, RC522 RFID, RTC, HC-SR501 PIR sensor, ultrasonic sensor, DHT11, GY-521, MAX7219, keypad, joystick, relay, SG90 servo, stepper motor, breadboard and more
  • Begin Without Soldering: Pre-soldered modules, a solderless breadboard, organized storage case and small-parts box reduce setup time and help beginners move from lesson to lesson while keeping LEDs, ICs, wires and sensors easy to find
  • Learn, Modify and Create: Program the ELEGOO UNO R3 board with Arduino IDE using the included PDF tutorial and example code, then adjust sensor thresholds, timing, display text and motor behavior to turn guided lessons into original projects
  • Flexible Power and Project Setup: Includes a 9 V, 1 A power supply, breadboard power module, 9 V battery and USB cable to support controller, breadboard and module experiments without sourcing basic setup accessories separately

5. Combine the systems only after both pass

Integration should begin with an emergency stop: if the distance is below a conservative threshold, immediately command both motors to zero. Then add reversing and turning. Treat invalid, stale, or timed-out sensor data as unsafe—not as a clear path.

Use a state machine instead of one giant loop

A state machine makes the rover’s behavior easier to inspect and safer to modify:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • STOPPED: motors disabled while startup checks complete.
  • CRUISE: move forward while the path is clear.
  • BRAKE: set both motor commands to zero immediately.
  • REVERSE: back away for a short calibrated period.
  • TURN_LEFT or TURN_RIGHT: rotate or arc until the sensor sees a clearer path.
  • FAULT: stop when readings are invalid, communication times out, the battery is low, or a wiring fault is detected.

The example below uses a 250 mm stop threshold and a 320 mm clear threshold. Those are starting values, not universal safety distances. The gap between them is hysteresis: it prevents the rover from rapidly alternating between driving and stopping at the boundary. Tune the values for speed, sensor behavior, stopping distance, and the environment.

#include <Wire.h>
#include <Adafruit_VL53L0X.h>

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

const byte LEFT_PWM = 5;
const byte LEFT_A = 7;
const byte LEFT_B = 8;
const byte RIGHT_PWM = 6;
const byte RIGHT_A = 9;
const byte RIGHT_B = 10;

const unsigned long SENSOR_PERIOD = 60;
const unsigned long BRAKE_TIME = 120;
const unsigned long REVERSE_TIME = 350;
const unsigned long MIN_TURN_TIME = 300;
const unsigned long TURN_TIMEOUT = 2500;
const int STOP_DISTANCE = 250;
const int CLEAR_DISTANCE = 320;

enum State { STOPPED, CRUISE, BRAKE, REVERSE, TURN_LEFT, TURN_RIGHT, FAULT };
State state = STOPPED;
unsigned long stateSince = 0;
unsigned long lastSensorRead = 0;
int distanceMm = 0;
bool distanceValid = false;
byte invalidReads = 0;
bool chooseRight = false;

void enterState(State next) {
state = next;
stateSince = millis();
}

void setOneMotor(byte pwmPin, byte pinA, byte pinB, int speed) {
speed = constrain(speed, -255, 255);

if (speed > 0) {
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
} else if (speed < 0) {
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
} else {
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
}

analogWrite(pwmPin, abs(speed));
}

void setMotors(int leftSpeed, int rightSpeed) {
setOneMotor(LEFT_PWM, LEFT_A, LEFT_B, leftSpeed);
setOneMotor(RIGHT_PWM, RIGHT_A, RIGHT_B, rightSpeed);
}

void stopMotors() {
setMotors(0, 0);
}

void updateDistance() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&quot;&amp;measure&quot;, false);

if (measure.RangeStatus == 4) {
distanceValid = false;
invalidReads++;
if (invalidReads >= 3) {
enterState(FAULT);
}
return;
}

invalidReads = 0;
distanceMm = measure.RangeMilliMeter;
distanceValid = true;
}

void setup() {
pinMode(LEFT_PWM, OUTPUT);
pinMode(LEFT_A, OUTPUT);
pinMode(LEFT_B, OUTPUT);
pinMode(RIGHT_PWM, OUTPUT);
pinMode(RIGHT_A, OUTPUT);
pinMode(RIGHT_B, OUTPUT);
stopMotors();

Serial.begin(115200);
if (!lox.begin()) {
Serial.println(&quot;VL53L0X initialization failed&quot;);
enterState(FAULT);
return;
}

enterState(STOPPED);
}

void loop() {
unsigned long now = millis();

if (now - lastSensorRead >= SENSOR_PERIOD &amp;&amp; state != FAULT) {
lastSensorRead = now;
updateDistance();
}

if (state == FAULT) {
stopMotors();
return;
}

switch (state) {
case STOPPED:
stopMotors();
if (distanceValid &amp;&amp; now - stateSince > 1500) {
enterState(CRUISE);
}
break;

case CRUISE:
if (!distanceValid) {
enterState(FAULT);
} else if (distanceMm <= STOP_DISTANCE) {
enterState(BRAKE);
} else {
setMotors(165, 165);
}
break;

case BRAKE:
stopMotors();
if (now - stateSince >= BRAKE_TIME) {
enterState(REVERSE);
}
break;

case REVERSE:
setMotors(-140, -140);
if (now - stateSince >= REVERSE_TIME) {
chooseRight = !chooseRight;
enterState(chooseRight ? TURN_RIGHT : TURN_LEFT);
}
break;

case TURN_LEFT:
setMotors(-145, 165);
if (!distanceValid) {
enterState(FAULT);
} else if (now - stateSince >= MIN_TURN_TIME &amp;&amp; distanceMm >= CLEAR_DISTANCE) {
enterState(CRUISE);
} else if (now - stateSince >= TURN_TIMEOUT) {
enterState(FAULT);
}
break;

case TURN_RIGHT:
setMotors(165, -145);
if (!distanceValid) {
enterState(FAULT);
} else if (now - stateSince >= MIN_TURN_TIME &amp;&amp; distanceMm >= CLEAR_DISTANCE) {
enterState(CRUISE);
} else if (now - stateSince >= TURN_TIMEOUT) {
enterState(FAULT);
}
break;

case FAULT:
stopMotors();
break;
}
}

If the motor directions are reversed, change the motor wiring or invert that motor’s speed in software. If the rover drives forward when one motor is reversed, correct the polarity before adjusting the avoidance thresholds.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why this code is deliberately conservative

  • Startup is stopped: the rover waits for a valid reading before entering cruise.
  • Invalid readings are not clear readings: three consecutive invalid readings trigger FAULT.
  • Brake is a separate state: both motor commands are set to zero before reversing.
  • Hysteresis reduces chatter: the rover stops at one distance and resumes only after the path is clearer.
  • Turn timeout prevents an endless blind maneuver: a failed sensor or blocked situation ends in a stopped fault state.
  • Timing uses millis() for the control states: the controller can continue checking its sensor instead of being trapped in a long chain of blocking delays.

This remains a simple open-loop design. A front-facing sensor cannot tell whether the rover is about to hit something on its side or whether reversing is safe behind it. Keep the speed low and the test area clear.

Power and wiring failures to expect

Motors do not move

  • Measure battery voltage, including while the motors are commanded to start.
  • Check that the driver’s motor-power input is connected and that the enable or standby control is active.
  • Confirm the Arduino and driver share a common ground.
  • Test one motor and one direction before testing the autonomous loop.
  • Check motor polarity and loose screw terminals.
  • Verify that the driver’s voltage and current ratings match the motor’s normal and startup requirements.

The Arduino resets when motors start

Suspect supply droop, motor noise, inadequate current capability, poor ground routing, or a loose connector. Power motors through an appropriate independent motor supply or regulated path where the hardware permits, shorten high-current wires, improve the ground arrangement, and add local bulk capacitance after confirming its rating and polarity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The VL53L0X reports zero, maximum, or invalid values

  • Verify power, ground, SDA, and SCL.
  • Confirm that the installed library and the selected example match the sensor.
  • Check that the I2C address is the expected 0x29.
  • Remove protective film from the optical sensor if present.
  • Try a large, nearby, non-moving target.
  • If using multiple units, verify the shutdown-pin startup sequence and unique software addresses after every power cycle.

The UART LiDAR conflicts with USB serial

The UNO has limited hardware serial resources. Confirm the TF Mini baud rate, use a compatible serial arrangement, or move to a controller with additional serial capability. A software-serial solution may work only within its timing and baud-rate limits; it is not a universal substitute for a hardware UART.

The robot turns unpredictably

First identify the left and right motors correctly. Reverse one motor’s logical polarity if necessary, align the wheels, lower the speed, and calibrate unequal motor behavior. Better repeatability requires wheel encoders and closed-loop speed control. An encoder can tell the controller how far each wheel actually moved; it cannot replace obstacle sensing.

Windows cannot detect the Arduino

How to improve the rover after the first successful run

Add side sensing

A second or third distance sensor can help the rover choose between left and right rather than alternating turns blindly. With multiple VL53L0X modules, use shutdown-pin sequencing and assign unique I2C addresses at startup. Mount sensors so their fields of view overlap the areas the front sensor cannot see.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
ELEGOO Conqueror Robot Tank Kit with UNO R3, Compatible with Arduino
  • BUILD A METAL TRACKED ROBOT: Assemble the stainless-steel chassis, suspension, tracks, sensors and UNO R3 control system into a working robot; ideal for home STEM projects, homeschool lessons, coding clubs and classroom builds
  • EXPLORE FIVE INTERACTIVE MODES: Switch between FPV driving, IR remote control, obstacle avoidance, line tracking and auto follow; create patrol routes, black-line courses, maze challenges and navigation experiments
  • DRIVE FROM THE ROBOT’S VIEW: The camera and ESP32-WROVER Wi-Fi module stream live FPV video to a compatible phone, while the adjustable servo-mounted camera lets you change the viewing angle during driving and inspection
  • START WITH BLOCK CODING, ADVANCE TO ARDUINO IDE: Use the ElegooKit app for visual programming, then modify motor speed, sensor thresholds, servo movement and navigation logic in Arduino IDE as coding skills grow
  • COMPLETE NO-SOLDER PROJECT KIT: Includes the UNO R3 controller, metal chassis, tracks, camera, ultrasonic and line-tracking modules, motors, servos, IR remote, 7.4 V battery, tools and illustrated instructions; recommended for ages 10+

Put one sensor on a servo

A servo-mounted forward sensor can scan left and right before choosing a turn. This is simpler than a full scanning LiDAR, but the scan takes time and the rover is still making decisions from a small number of points rather than a complete map.

Add wheel encoders

Encoders provide wheel-motion feedback. They help compensate for unequal motors, measure approximate travel, and make timed turns more repeatable. They are the natural next step when the rover veers or turns inconsistently.

Add an IMU

An inertial measurement unit can provide orientation and motion information, although it requires calibration and sensor fusion. It does not by itself provide position or prevent collisions.

Use a scanning LiDAR and a more capable computer

An RPLIDAR A1M8 can supply angular range data for richer obstacle maps. At that point, plan for a suitable power system, stable mechanical mount, protocol handling, and a controller or companion computer capable of processing the scan. This is an advanced robotics project rather than a minor sensor swap.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add wireless telemetry

A Nano ESP32 is a reasonable expansion path for Wi-Fi, Bluetooth LE, web controls, or telemetry. Keep motor safety local: a temporary wireless disconnect should result in stopped motors rather than an uncontrolled rover. The 3.3 V logic environment still requires careful peripheral compatibility checks.

What not to buy or add yet

Do not begin with a scanning LiDAR, several identical I2C sensors, wireless control, encoders, and mapping software all at once. Each addition creates another possible failure point. The useful progression is:

  1. Bench-test the controller with Blink and Serial Monitor.
  2. Test one motor channel with the wheels raised.
  3. Test both motors and correct polarity.
  4. Read one forward-facing VL53L0X.
  5. Implement an emergency stop for close or invalid readings.
  6. Add reverse and a simple turn decision.
  7. Only then add side sensors, a servo, encoders, an IMU, wireless telemetry, or scanning LiDAR.

Likewise, a streaming service is not part of this build. StreamNeo is intended for continuously streaming owned or cleared prerecorded video to YouTube Live; it does not solve the material hardware, programming, sensing, or power problems involved in an Arduino rover, so it is not recommended here.

Final pre-power checklist

  • Wheels are raised for the first motor test.
  • A physical switch is installed or the battery can be disconnected quickly.
  • Motor voltage is within the driver and motor specifications.
  • Motor current, including startup or stall current, is within the driver and battery capability.
  • Arduino I/O pins connect only to driver control inputs—not directly to motors.
  • Arduino, driver, and sensor grounds share a common reference.
  • High-current motor wiring is not being forced through a weak breadboard rail.
  • The sensor’s power and logic voltage are appropriate for the selected Arduino.
  • The USB cable supports data.
  • Invalid or stale sensor data causes a stop.
  • The first tests happen at low speed in a clear, controlled area.
  • Lithium batteries are charged only with the correct charger and protection arrangement, and never unattended.

Frequently Asked Questions

Is an Arduino LiDAR car really self-driving?

It is autonomous in the narrow robotics sense that it senses its surroundings and chooses motor commands without a human steering input. The beginner version is reactive obstacle avoidance, not a road-safe self-driving automobile. It lacks lane perception, localization, mapping, redundant braking, traffic awareness, and regulatory compliance.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use a VL53L0X and a TF Mini LiDAR together?

Yes, in principle, but they use different interfaces: the VL53L0X uses I2C while the TF Mini uses UART. Plan the pin assignments, power rails, logic levels, serial resources, and software timing before combining them. Start with one sensor and add the second only after each works independently.

Why should the rover stop when the LiDAR reading is invalid?

An invalid or stale measurement does not prove that the path is clear. Treating it as clear can make the rover drive blind. A fail-safe state that disables both motors is safer for a beginner project, especially when a sensor cable or communication bus can fail.

Do Arduino 2WD kits include the LiDAR sensor and battery?

Contents vary by listing. Many kits include a chassis, geared motors, wheels, and a basic motor driver, but may omit a genuine Arduino board, the VL53L0X or TF Mini sensor, battery, charger, USB data cable, or mounting hardware. Verify the exact parts list before ordering.

The Bottom Line

The most dependable beginner path is an Arduino UNO R3, two-wheel differential-drive chassis, properly rated dual H-bridge driver, and one forward-facing VL53L0X breakout. Prove each subsystem separately, stop on close or invalid readings, and keep the rover slow and off public roads. Once that foundation works, encoders, side sensors, a Nano ESP32, or a scanning LiDAR can add capability without hiding basic wiring and control problems.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

More from the Garage

  1. Entry001Date09 OCT 26Time3 minWhich Brake Pad Should You Buy From RockAuto or Elsewhere?Section: Blog
  2. Entry002Date09 OCT 26Time5 minThe Pros and Cons of Touchless Car Wash SystemsSection: Blog
  3. Entry003Date09 OCT 26Time3 minCan a Trickle Charger or Battery Tender Properly Charge a Car Battery?Section: Blog

Thanks for visiting Carcody

Carcody.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.co

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.