This guide contains Amazon affiliate links. If you buy through them, DroneCoreGuide earns a small commission at no extra cost to you.
Obstacle avoidance gives your drone a chance to stop before it hits a tree, wall or pole, even when you or your autonomous code make a mistake. ArduPilot has built-in support for it. You just need the right sensors and settings.
Sensor options
| Sensor | How it works | Strengths | Limits |
|---|---|---|---|
| Single-point lidar or rangefinder | Measures distance in one direction | Cheap, light, reliable | One direction only |
| Multiple rangefinders | Several sensors pointing different ways | Covers key directions | More wiring |
| 360° scanning lidar | Spins to measure all around | Full horizontal coverage | Heavier, pricier |
| Depth camera | Measures distance for every pixel | Rich 3D data | Needs a companion computer, struggles in bright sun or low texture |
Shop lidar rangefinders · Shop 360° lidar · Shop depth cameras
How ArduPilot avoids obstacles
ArduPilot offers two main behaviors in modes like Loiter and AltHold:
- Stop: the drone refuses to move closer than a set distance to an obstacle.
- Slide: the drone slides along the obstacle instead of moving toward it.
In auto missions, ArduPilot’s path-planning options (such as BendyRuler and Dijkstra’s with a fence) can route around obstacles.
Wiring a rangefinder
Most lidar rangefinders connect by serial (UART) or I2C:
- Connect TX/RX (crossed) or SDA/SCL to a free port.
- Power from 5 V. Check the sensor’s current draw.
- Mount the sensor facing the direction you want to protect, with nothing in its field of view.
Configure ArduPilot
- Set the rangefinder parameters (
RNGFND1_TYPE, orientation, min/max range) to match your sensor. - Enable proximity: set
PRX1_TYPEto use the rangefinder or your 360° lidar. - Enable avoidance with
AVOID_ENABLE, and setAVOID_MARGIN(the distance the drone keeps from obstacles) andAVOID_BEHAVE(stop or slide). - Reboot and check the Proximity view in Mission Planner, which shows detected obstacles around the drone.
Parameter names can change between ArduPilot versions; follow the current ArduPilot documentation for your firmware.
Depth cameras and the companion computer
A depth camera usually connects to a companion computer, which processes the depth image and sends obstacle distances to ArduPilot as MAVLink messages. This gives much richer coverage but needs more setup and processing power.
Test safely
- Test indoors on the bench: wave your hand in front of the sensor and watch distance readings.
- Fly in Loiter in an open field and approach a large, soft obstacle like a hanging tarp or foam board at low speed.
- Confirm the drone stops at your margin.
- Increase speed gradually.
Choosing a rangefinder by specs
| Spec | Why it matters |
|---|---|
| Maximum range | How early the drone can react |
| Minimum range | Close obstacles may not register |
| Update rate | Faster rates give quicker reactions |
| Field of view | Narrow beams can miss obstacles off-center |
| Outdoor performance | Sunlight affects some sensors |
| Interface | Serial or I2C support on your flight controller |
Placing multiple sensors
A practical layout for a GPS quad:
- Forward: the most important direction for missions.
- Downward: for precise altitude near the ground and landing.
- Rear and sides: add when the drone often moves in those directions.
Each sensor needs its own orientation setting so ArduPilot knows which way it points.
Speed vs stopping distance
A drone can’t stop instantly. At higher speeds, it needs more distance to brake. If your sensor’s range is short, keep speeds low enough that the drone can stop within the avoidance margin. Test stopping distance at increasing speeds before relying on it.
Precision landing
A related feature: using a downward camera or an infrared beacon, ArduPilot can land precisely on a target. It uses a similar companion-computer or sensor setup and is a great next project after basic obstacle sensing.
Know the limits
- Thin wires, branches and glass are hard for many sensors to detect.
- Bright sunlight can blind some depth cameras.
- Avoidance doesn’t work in every flight mode.
- It’s a safety net, not a replacement for careful flying.
Frequently Asked Questions
Can I add obstacle avoidance to a DIY drone?
Yes. ArduPilot supports rangefinders, 360° lidar and depth cameras for obstacle avoidance in modes such as Loiter and AltHold.
What is the cheapest obstacle avoidance sensor?
A single-point lidar rangefinder is the most affordable option, but it only protects one direction.
Does obstacle avoidance work in acro mode?
No. ArduPilot’s avoidance works in assisted and autonomous modes, not in fully manual modes.
Can obstacle avoidance see power lines?
Often not reliably. Thin wires are very hard to detect, so keep clear of power lines regardless.