Powering issues with mega

A 7805 could work, but it will waste a lot of power. 7805 is a linear voltage regulator so it will drop the voltage and to do so dump off the excess as heat. That makes it less efficient. For 12V to 5V you will need a heat sink. A buck (switching) regulator does not drop the excess as heat and can be over 90% efficient.

I have used these 12V to 5V converters with good result. Like shown in the ad, cut that one trace and solder jumper the 5V pads for 5V regulation. Or don't cut the trace and adjust the tiny pot for 5V.