Obstacle Avoiding Robot build guide
Ultrasonic mounting, servo sweep, and escape maneuvers.
INTERMEDIATE
Mount the HC-SR04 on a servo so it can scan left and right without hitting the chassis.
Keep the ultrasonic clear of motor wiring EMI — twisted power leads help.
Implement a simple state machine: drive forward, stop under threshold, scan, turn toward the clearer side.
Test in an open room before adding rugs or dark floors that confuse distance readings.