Robot Car with LiDAR is a project to build a robot car with a LiDAR sensor to navigate the environment and avoid obstacles. The car uses a tank track with 4 DC motors. It can be controlled by a remote control or can be driven autonomously.
There are 3 operational modes: Manual, Autonomous, and Semi-Auto.
Manualmode is controlled by a remote control (LiDAR disabled).Autonomousmode is controlled by the LiDAR sensor with smart navigation.Semi-Automode is a combination of theManualandAutonomousmodes, it can avoid obstacles even when it is controlled by the RC.
The autonomous mode uses a Vector Field Histogram (VFH) inspired algorithm for intelligent obstacle avoidance. Instead of simple reactive turns, the robot builds a spatial model of its surroundings and selects the probabilistically best path.
-
Sector-Based Mapping - The 180° front field-of-view is divided into 12 sectors (15° each). Each LiDAR point is accumulated into its corresponding sector, building an obstacle density histogram per full scan.
-
Weighted Density Scoring - Closer obstacles contribute exponentially more to a sector's density using inverse-square weighting (
1/d²). This makes the robot more sensitive to nearby threats while still accounting for distant objects. -
Multi-Factor Path Selection - Each sector is scored by combining:
- Openness (primary) - sectors with less obstacle density score higher.
- Distance - prefers paths where the nearest obstacle is further away.
- Gap Width - favors wider openings by checking adjacent sectors.
- Center Preference - slight bonus for going straight to avoid unnecessary deviation.
- Heading Continuity - prefers directions close to the current heading for smoother motion.
-
Proportional Steering - Instead of binary hard-left/hard-right turns, steering is proportional to how far the best path is from the current heading, producing smooth, natural turns.
-
Temporal Smoothing - An exponential moving average blends current and previous scans (
alpha = 0.3) to filter out noise and prevent erratic oscillation. -
Graduated Speed Control - The robot slows down proportionally as it approaches obstacles:
- Full speed when clear (> 35cm).
- Linear deceleration from 35cm down to 16cm.
- Emergency stop and smart reverse at 16cm or closer.
| Parameter | Default | Description |
|---|---|---|
NUM_SECTORS |
12 | Number of angular sectors (higher = finer resolution) |
SMOOTHING_ALPHA |
0.3 | Temporal smoothing factor (lower = smoother, slower reaction) |
MAX_LIDAR_DISTANCE_CM |
50 | Maximum detection range in cm |
SLOW_DOWN_DISTANCE_CM |
35 | Distance at which the robot begins to decelerate |
MIN_SAFE_DISTANCE_CM |
16 | Emergency stop distance threshold |
- Arduino Mega 2560 REV3 (https://amzn.to/3wObNdW)
- Slamtec RPLIDAR A1M8 (https://amzn.to/3VaSoy3)
- 7.4V 1200mAh Lipo Battery (https://amzn.to/3Pdja4Z)
- L298N Motor Driver Controller Board (https://amzn.to/3TxBqc0)
- FLYSKY FS-i6X 10CH 2.4GHz RC Transmitter (https://amzn.to/3wP557x)
Motors (via L298N)
| Pin | Function |
|---|---|
| 2 | Left Motor Direction 1 |
| 3 | Left Motor Direction 2 |
| 4 | Right Motor Direction 1 |
| 5 | Right Motor Direction 2 |
| 6 | Left Motor Speed (PWM) |
| 7 | Right Motor Speed (PWM) |
RP LiDAR Motor
| Wire | Function |
|---|---|
Purple |
PWM control (Pin 8) |
Yellow |
Motor GND |
Red |
Motor +5V |
The LiDAR motor runs at 9V. The PWM wire is connected to Arduino Mega Pin 8 to control motor speed.
RP LiDAR Sensor (Serial1)
| Wire | Function |
|---|---|
White |
Ground |
Black |
5V |
Orange |
RX |
Green |
TX |
RC Receiver (IBus protocol on Serial2)
| Channel | Function |
|---|---|
| CH1 | Left / Right steering |
| CH2 | Forward / Reverse |
| CH3 | Throttle |
| CH4 | Rudder (unused) |
| CH5 (AUX1) | Mode selector (< 10 = Manual, > 10 = Autonomous) |