What do if arduino reset itself?

Stop doing whatever is making it reset.

Could bd the sketch - writing off thed end of an array usually causes it to reset.

The board resets when you open serial monitor (or most other serial consoles) - if this is a problem, put a 10uF cap between reset and ground after uploading sketch; you must remove it to upload new code.

Excessive load on power can cause resets.