If the circuit works correctly without motors (use e.g. leds instead of motors) but stops working as soon as you use real motors, then the problem will be the motors.
What amount of power do these motors take?
- Try to test it with the motors not too close to your digital circuit, with seperate power supplies with the ground of both connected at only one point.
- Add a small capacitor (a couple of nF) in parallel with the motor leads, these will block the noise from the brushes (if it is not a brushless motor...)
- Do you have some 100nF capacitors close to the powerpins of the microcontroller? Also you should have 100nF capacitors in parallel with the power supply lines of the distance sensors, closeby these sensors.
- Add a low-pass filter to the output of the distance sensors, or do some digital filtering inside the microcontroller.
- Put your digital circuit in a metal case.
If still problems, you can try to test if it helps with a series resistor connected to the motors. If it is solved then, you have to further decouple your powersupply of the motor from the digital power supply.