problem with the nano arduino. Help!

It pains me to have to repeat this so often but ...

The "Vin" pin or in fact the "barrel jack" which is the same with a diode, was provided to demonstrate the Arduino. Once you start connecting things that draw current, and that includes connecting things to draw current from the "5V" pin, you are playing with fire - or not! This is even worse for the Mega as it has more pins to connect things to! :astonished:

The on-board regulator - unless you use a variant such as the "RoboRed" (it has a proper switchmode regulator) - has no heatsink of significance. It may theoretically have a rating of 1 A, but only when bonded to a substantial heatsink. You can barely see it on the Arduino board. You will not get 1 A at 5 V from the board with any "Vin" voltage for more than a second or two before the regulator overheats - and hopefully shuts down peacefully. You may be lucky to get 150 mA. :roll_eyes:

It is thus extremely bad design to use "Vin" in a serious project. Even if it works at a start, any modification may later cause trouble.

The microprocessor and its peripherals operate from 5 V. If you have 5 V then you provide it to the "5V" terminal. You can fudge it by connecting something such as a USB charger to the USB connector but there is a 500 mA polyfuse on the UNO/ Mega and a diode on the Nano interposed. If you do not have 5 V, then you provide a switchmode regulator to produce regulated 5 V.