I found out that if I press the reset button after power on everything starts to work. Is there a way to automatically reset arduino on startup???
Yes arduino get reset once it get restarted.
1)DO not power on arduino using both USB and Vin connected. Either use external USB to serial monitor to view your output data.
2)Can you send image of your Setup
3)Let me know what will happen when you run only on power supply?? On what basis you are saying that your code is not working when powered externally.
4) What is VIn voltage you are trying to GIVE.
check this part