Arduino program problem with DC input

The only thing I noticed in your code is an unindented closing brace right after counter increment. But I don't think this has something to do with the behaviour you described.

The diagram looks good to me. Maybe someone here with hw-fu can give you a hint about where to look for potential problems. I would start by checking the 9V line both before and after the regulator with a multimeter when Arduino is running without the usb cable.