Hello! I am trying to connect two servos to act as wheels and a distance sensor. For some reason, the servos work perfectly fine and can move when the distance sensor isn't connected, but the second the distance sensor is added the servos no longer move. Not sure why this is happening.
Welcome! Thanks for following the guidelines and posting your code accordingly. Nice picture but I cannot determine how everything is connected. Can you post a schematic showing exactly how you have wired this.
It looks like your 'distance sensor' is a HC-SR04 which requires a
minimum trigger pulse of 10 us for reliable operation. With your pulse of 5us, pulsein might be returning an erratic value over 100.
Ok you found the problem. Double check your connections and
wiring to the sensor and arduino. Hopefully you will find the problem there. If not I would suggest you try a new sensor.