After starting the automatic mode, I cant switch it off.

These "if"s should not be nested:

 if(val == val2) {                     // make sure we got 2 consistant readings!
    if (val != modeButtonState) {        // the button state has changed!
      if (val == LOW) {                  // check if the button is pressed
        if (Mode == 0) {
          Mode = 1;
        } else {
          if (Mode == 1) {
            Mode = 0;
          }