External power source not working

I am uploading simple obstacle avoiding code using ultrasonic sensor. The robot is working fine when connected to laptop through usb but as soon as it is connected to ac adapter using 9v battery it stops working. Everything is fine. All the leds are working when connected to battery. Just the robot is not moving or sometimes only one wheel moves for few seconds and after that even that stops.

As per your thread in Feb of this year, an 9V 'smoke alarm' type battery isn't powerful enough to run much. You'd be better off using a pack of 6xAA batteries to get 9V.

... and many adapters have insufficient power for motors, which should have a separate power supply with a common ground anyway.