Arduino Mega code on Arduino Nano

Welcome to the forum

The hardware sounds compatible but the code might not be

Please post the sketch here, using code tags when you do

In my experience this is the easiest way to tidy up the code and add the code tags

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.