It is possible that the combination of running the motors and the ping sensor on the same supply is causing the issue. Typically I try to have a separate power source for the motors because they have a tendency to generate a lot of noise that can interfere with other logic or sensors.
Here is a couple troubleshooting things you can do:
- Double check your power source for your design. Typically hbridge motor drivers allow for a dual source so that you can separate the motor power from the logic power. Maybe you only have the motor power being supplied and the logic power is being supplied when you plug in the USB.
- Comment out the code that turns on the motors. On power up does the ping sensor seem to be working while the motors are no longer running?
- If the ping sensor still doesn't work make sure you delay some on your start up code before you start doing the ping.
- If you still don't have ping on power up then try removing the Motor Shield.
- Paul Newton likes this