Program works only when board is connected to system, not even if the USB is connected to an USB adapter or a 7.5V adapter to pin
So how can that be anything to do with your code.
You have a hardware issue with your external supplies.
Does an LED blink sketch work?
If so then it is an issue of current.
If not then you haven't connected it like you think you have or have a problem with the current capacity of your external supplies.