External power supply problem

The servo works fine when powered off the Vin when Arduino is on USB power. But when extn. 9V is connected it goes its own way. Other sketches which involved the sensor and LEDs work fine with extn. supply