Arduino program won't stay on when connected to a 12v battery

This sounds like a grounding and possibly EMI (ElectroMotive Interference) problem.

If you disconnect the motor relay does the rest of it work?

If you ground the Arduino/System to a local ground does it work?

See some about EMI etc. on the ArduinoInfo.Info WIKI HERE: