Same code working differently on Nano 33 IoT and Mega

Have you taken into account that the Nano 33 runs at 3.3V whilst the Mega runs at 5V ?