Arduino Mega freezes after sometime

Post your latest version of the code. Use code tags as described in How to get the best out of this forum.

It would be very useful if you just posted those errors (again using code tags).