Bypass Key Switch

Hello, i have a Problem with the source code of Sundial.

I want to use a key switch as bypass to open my gps based box. My idea was, to give 5V via a key Switch to the digital pin 0 on the arduino and by pushing the main button to start the box, the servo opens. I tried many ways but don't find any solution.

I hope you can help me. I am sure it is simple by it seems that it is not my Cup of tea^^

Here is the source code:

#include <PWMServo.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>

//Hier nichts verändern!
// -------------------------------------------------------------------
static const int   SERVO_CLOSED_ANGLE = 95;    // degrees (0-180)
static const int   SERVO_OPEN_ANGLE = 135;     // degrees (0-180)

//Hier kannst du Deine Koordinaten und den Radius eingeben
// -------------------------------------------------------------------
static const float DEST_LATITUDE = 47.642154;  // degrees (-90 to 90)
static const float DEST_LONGITUDE = 9.762664; // degrees (-180 to 180)
static const int   RADIUS = 100;              // meters
static const int   LCD_CONTRAST = 50;          // (0-255)

//Hier nichts verändern!
// -------------------------------------------------------------------

static const int DEF_ATTEMPT_MAX = 50;
static const int EEPROM_OFFSET = 100;

static const int GPS_RX_PIN = 4, GPS_TX_PIN = 3; 
static const int LCD_ENABLE_PIN = 7, LCD_RS_PIN = 5, LCD_RW_PIN = 8;
static const int LCD_DB4_PIN = 14, LCD_DB5_PIN = 15, LCD_DB6_PIN = 16, LCD_DB7_PIN = 17;
static const int LCD_CONTRAST_PIN = 6; 
static const int POLOLU_SWITCH_PIN = 12;
static const int SERVO_CONTROL_PIN = 9; 
static const int LED_PIN = 2; 
static const int PIEZO_PIN = 11; 

static SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN);
static LiquidCrystal lcd(LCD_RS_PIN, LCD_RW_PIN, LCD_ENABLE_PIN, LCD_DB4_PIN, LCD_DB5_PIN, LCD_DB6_PIN, LCD_DB7_PIN);
static TinyGPS tinyGps; 
static int attemptCounter;
static PWMServo servo;

void setup()
{

  pinMode(POLOLU_SWITCH_PIN, OUTPUT);
  digitalWrite(POLOLU_SWITCH_PIN, LOW);

  servo.attach(SERVO_CONTROL_PIN);

  Serial.begin(115200);

  ss.begin(4800);

  pinMode(LCD_CONTRAST_PIN, OUTPUT);
  analogWrite(LCD_CONTRAST_PIN, LCD_CONTRAST);

  lcd.begin(16, 2);
  
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);

  servo.write(SERVO_CLOSED_ANGLE); 
  
  attemptCounter = EEPROM.read(EEPROM_OFFSET);
  if (attemptCounter == 0xFF) 
    attemptCounter = 0;

  ++attemptCounter;

  Msg(lcd, "    Kevin &     ", "    Nadja's     ", 1500);

  Msg(lcd, "   Adventure    ", "      Box!      ", 2000);

  if (attemptCounter >= DEF_ATTEMPT_MAX)
  {
    Msg(lcd, "  Sorry, keine  ", "    weiteren    ", 2000);
    Msg(lcd, "    Versuche    ", "    erlaubt!    ", 2000);
    Msg(lcd, " Bitte Besitzer ", " kontaktieren!  ", 2000);
    Msg(lcd, "    Telefon:    ", " 0152-52564613  ", 5000);
    Msg(lcd, "kevinmeister89@ ", " googlemail.com ", 5000);
    Msg(lcd, "  Vielen Dank!  ", "", 2000);
    PowerOff();
  }

  Msg(lcd, "Das ist Versuch ", "", 2000);
  lcd.clear();
  lcd.setCursor(3, 0);
  lcd.print(attemptCounter);
  lcd.print(" von "); 
  lcd.print(DEF_ATTEMPT_MAX);
  delay(2000);

  EEPROM.write(EEPROM_OFFSET, attemptCounter);

  Msg(lcd, "  (((Suche)))  ", "  (((GPS..)))  ", 0);
}

void loop()
{
  if (ss.available() && tinyGps.encode(ss.read()))
  {
    float lat, lon;
    unsigned long fixAge;

    tinyGps.f_get_position(&lat, &lon, &fixAge);
    if (fixAge != TinyGPS::GPS_INVALID_AGE)
    {
      Chirp(true);
      
      float distance_meters = TinyGPS::distance_between(lat, lon, DEST_LATITUDE, DEST_LONGITUDE);

      if (distance_meters <= RADIUS)
      {
        Msg(lcd, "    Zugriff    ", "    erlaubt!    ", 2000);
        EEPROM.write(EEPROM_OFFSET, 0);
        servo.write(SERVO_OPEN_ANGLE);
      }
      else
      {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("   Entfernung   ");
        lcd.setCursor(6, 1);
        if (distance_meters < 5000)
        {
          lcd.print((int)distance_meters);
          lcd.print("m");
        }

        else
        {
          lcd.print((int)(distance_meters / 1000));
          lcd.print("km");
        }
        delay(4000);
        Msg(lcd, "      Kein      ", "    Zugriff!    ", 2000);
      }

      PowerOff();
    }
  }

  if (millis() >= 300000)
      
    PowerOff2();
}

void PowerOff()
{
  Chirp(false);
  Msg(lcd, "  Schalte aus!  ", "", 2000);
  lcd.clear(); 
  
  digitalWrite(POLOLU_SWITCH_PIN, HIGH);

  delay(300000);
  servo.write(SERVO_OPEN_ANGLE); 

  
  EEPROM.write(EEPROM_OFFSET, 0); 
  
 
  delay(10000); 

 
  servo.write(SERVO_CLOSED_ANGLE); 

  
  exit(1);
} 


void PowerOff2()
{
  Chirp(false);
  Msg(lcd, "  Kein Signal!  ", "", 2000);
  Msg(lcd, "  Schalte aus!  ", "", 2000);
  lcd.clear(); 
  
  digitalWrite(POLOLU_SWITCH_PIN, HIGH);

  delay(300000);
  servo.write(SERVO_OPEN_ANGLE); 

  
  EEPROM.write(EEPROM_OFFSET, 0); 
  
 
  delay(10000); 

 
  servo.write(SERVO_CLOSED_ANGLE); 

  
  exit(1);
} 


void Msg(LiquidCrystal &lcd, const char *top, const char *bottom, unsigned long del)
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(top);
  lcd.setCursor(0, 1);
  lcd.print(bottom);
  delay(del);
}

static void Chirp(bool up)
{
  static const int A = 1760;
  static const int E = 2637;
  static const int CS = 2218;
  static const int duration = 100;

  int tone1 = up ? A : E;
  int tone2 = up ? E : A;

  ss.end();
  tone(PIEZO_PIN, tone1, duration);
  delay(duration);
  noTone(PIEZO_PIN);
  tone(PIEZO_PIN, tone2, duration);
  delay(duration);
  noTone(PIEZO_PIN);
  ss.begin(4800);
}

My idea was in "void setup();" add something like this:

void setup() {
   pinMode(53, OUTPUT); 
   pinMode(bypass_input,INPUT);
   servo.attach(servo_Pin);
   servo.write(closePosition);
   gpsSerial.begin (9600); // connect gps sensor
    
   // set up the LCD's number of columns and rows: 
   lcd.begin(16, 2);
   // Print a message to the LCD.
       val = digitalRead(bypass_input);
     if (val == HIGH){
     PrintToLCD("Bypass enabled","(2000)");
     servo.write(openPosition);
     delay(500);
     PowerOff();
    }

Best greetings Kevin

My idea was, to give 5V via a key Switch to the digital pin 0 on the arduino

So, you don;t want to use Serial?

My idea was in "void setup();" add something like this:

So, you only want to be able to open the box when the Arduino resets?

     PrintToLCD("Bypass enabled","(2000)");

What possible reason is there to send "(2000)" as the second argument to this mysterious function?

That was just a samplecode from a other site.

I have one other option from someone:

INPUT_HIGH:
 pinMode(10, INPUT_HIGH);

servo.write(SERVO_CLOSED_ANGLE); 

if (digitalRead(10) == LOW)
 {
   Msg(lcd, "Bypass", "Mode", 2000);
   servo.write(SERVO_OPEN_ANGLE);
   PowerOff();
 }

This could be a solution. Is void setup() only the part to reset the box?

kevinmeister:
This could be a solution. Is void setup() only the part to reset the box?

It's the other way around. Resetting the box will run setup().