Arduino BYOR troubleshooting

Hi everyone, I am working on the Arduino BYOR kit, and I have built the car. When I use it without the sonar, the wheels turn with no problems. But, when I include the sonar, the wheels move jerkily, depending on some conditions I can't understand. I wrote the code as reported on the book, the wires are all at the right place. I can't understand, could someone help me?