Very strange power supply problem
[Turning my comment and other peoples replies into an answer to make it easier to read]

You are using two different power supplies? (PC + 12V or USB Charger + 12V) Have you connected the grounds from the two power supplies?  

I have a limited understanding of why, but I know that unless the two power supplies have a common ground level the values for 0V and 5V may not be the same across the two feeds and you get odd and unpredictable behaviour.

Gerban explained that the reason it works on your PC is that most PC Power supplies reference Gnd from the Earth.  If you 12V supply is an ex-PC PSU, or similar, that will be doing the same which is why that setup works, they share a common ground via the mains earth.  The 5V phone charge probably has a plastic earth pin, which means it doesn't do this and therefore the Gnds are not tied to each other.

Majenko's blog will provide a more detailed, less hand wavey explanation:
https://hackingmajenkoblog.wordpress.com/2016/12/06/the-importance-of-sharing-grounds/