How do I change a variable password into a fixed one and cutting a wire starts the clock?

Hi there, I'm just a father that wants to help his son so forgive me if I just ask for help here...
I want this bomb prop just to start with cutting a wire but instead I need to fill in the password first. Can I simply do that (adding a wire as pull-up) and input a fixed password? I tried it for hours now but I simply don't see it and it does not work at all
Here is my the code I found on the internet, already fixed the timer (that starts now with 2 hours countdown)

[code]
// Viral Science www.viralsciencecreativity.com www.youtube.com/c/viralscience
// Arduino Airsoft Time Bomb
#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>



LiquidCrystal_I2C lcd(0x27, 16, 2); //Change the HEX address

int Hours = 00;
int Minutes = 00;
int Seconds = 00;
int trycount = 0;
int keycount = 0;
int i = 0;
int a = 10;


const String password_1 = "1234";

int redled = A2;
int yellowled = A1;
int greenled = A3;

int hourstenscode;
int hoursonescode;
int mintenscode;
int minonescode;
int sectenscode;
int seconescode;

long secMillis = 0;
long interval = 1000;

char password[4];
char entered[4];


const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5};  //7,2,3,5 for Black 4x3 keypad
byte colPins[COLS] = {4, 3, 2};     //6,8,4 for Black 4x3 Keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  pinMode(redled, OUTPUT);
  pinMode(yellowled, OUTPUT);
  pinMode(greenled, OUTPUT);
  digitalWrite(redled, HIGH);
  digitalWrite(yellowled, HIGH);
  digitalWrite(greenled, HIGH);

  lcd.begin(16, 2);
  lcd.backlight();
  Serial.begin(9600);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Bom geactiveerd!");                 // Je kan hier de tekst aanpassen tussen de "....."
  lcd.setCursor(0, 1);
  lcd.print("Enter Code:");                     // Je kan hier de tekst aanpassen tussen de "....."
  while (keycount < 4)
  {
    lcd.setCursor(keycount + 12, 1);
    lcd.blink();
    char armcode = keypad.getKey();
    armcode == NO_KEY;
    if (armcode != NO_KEY)
    {
      if ((armcode != '*') && (armcode != '#'))
      {
        lcd.print(armcode);
        tone(9, 5000, 100);
        password[keycount] = armcode;
        keycount++;
      }
    }
  }

  if (keycount == 4)
  {
    delay(500);
    lcd.noBlink();
    lcd.clear();
    lcd.home();
    lcd.print("Disarm Code is: ");
    lcd.setCursor(6, 1);
    lcd.print(password[0]);
    lcd.print(password[1]);
    lcd.print(password[2]);
    lcd.print(password[3]);
    delay(1000);
    lcd.clear();
  }


  if (keycount == 11);
  {
    Hours = 02;
    Minutes = 00;
    Seconds = 00;
    delay(100);
    lcd.noBlink();
    lcd.clear();
    lcd.setCursor(0, 0);


    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Press # to arm");        // Je kan hier de tekst aanpassen tussen de "....."
    delay (50);
    keycount = 12;
  }

  while (keycount == 12)
  {
    char armkey = keypad.getKey();

    if (armkey == '#')
    {
      tone(9, 5000, 100);
      delay(50);
      tone(9, 0, 100);
      delay(50);
      tone(9, 5000, 100);
      delay(50);
      tone(9, 0, 100);
      delay(50);
      tone(9, 5000, 100);
      delay(50);
      tone(9, 0, 100);
      lcd.clear();
      lcd.print ("Bomb Armed!");        // Je kan hier de tekst aanpassen tussen de "....."
      lcd.setCursor(0, 1);
      lcd.print("Countdown start");     // Je kan hier de tekst aanpassen tussen de "....."
      delay(100);
      lcd.clear();
      keycount = 0;
    }
  }
}
void loop()
{
  timer();
  char disarmcode = keypad.getKey();

  if (disarmcode == '*')
  {
    tone(9, 5000, 100);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Code: ");

    while (keycount < 4)
    {
      timer();

      char disarmcode = keypad.getKey();
      if (disarmcode == '#')
      {
        tone(9, 5000, 100);
        keycount = 0;
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Code: ");
      }
      else if (disarmcode != NO_KEY)
      {
        lcd.setCursor(keycount + 7, 0);
        lcd.blink();
        lcd.print(disarmcode);
        entered[keycount] = disarmcode;
        keycount++;
        tone(9, 5000, 100);
        delay(100);
        lcd.noBlink();
        lcd.setCursor(keycount + 6, 0);
        lcd.print("*");
        lcd.setCursor(keycount + 7, 0);
        lcd.blink();
      }
    }

    if (keycount == 4)
    {
      if (entered[0] == password[0] && entered[1] == password[1] && entered[2] == password[2] && entered[3] == password[3])
      {
        lcd.noBlink();
        lcd.clear();
        lcd.home();
        lcd.print("Bomb Defused!");         // Je kan hier de tekst aanpassen tussen de "....."
        lcd.setCursor(0, 1);
        lcd.print("Well Done!");            // Hier ook
        keycount = 0;
        digitalWrite(greenled, LOW);
        delay(15000);
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Reset the Bomb");        // En hier ook
        delay(10000);
      }
      else
      {
        lcd.noBlink();                    //Hier begint de code om alles te regelen voor een onjuiste code
        lcd.clear();
        lcd.home();
        lcd.print("Wrong Password!");     // Je kan hier de tekst aanpassen tussen de "....."
        trycount++;


        if (Hours > 0)
        {
          Hours = Hours / 2;              // Hours / 2  kan ook een ander getal worden, hetzelfde geld voor de minuten
        }


        if (Minutes > 0)
        {
          Minutes = Minutes / 2;
        }
        if (Seconds > 0)
        {
          Seconds = Seconds / 2;
        }
        if (trycount == 2)
        {
          Hours = Hours * 4;
        }
        if (trycount == 3)                // Hier begint de code voor als je voor de 2de keer een onjuiste code invoert.
        {
          interval = interval / 10;       // Interval is de snelheid van de tijd in duizendste, 1000 is dus 1 seconden. Deel je dat door 10 gaat de snelheid van de tijd dus 10 keer zo snel.
        }
        if (trycount == 4)
        {
          interval = interval * a;
        }
        if (trycount == 5)                //voor de 3de keer een foute code is dat de bom af gaat, je kan dit dus herhalen zo vaak als je wilt. Dus ook een if (trycount == 4) met een daarbij behorende opdracht...je kan dus ook + een aantal minuten doen
        {
          Minutes = Minutes - 59;
          Hours = Hours - 59;
          Seconds = Seconds - 59;
        }
        if (trycount == 5)
        {
          Hours = Hours * a;
        }
        delay(1000);
        keycount = 0;


      }
    }
  }
}

void timer()
{
  Serial.print(Seconds);
  Serial.println();

  if (Hours <= 0)
  {
    if ( Minutes < 0 )
    {
      lcd.noBlink();
      lcd.clear();
      lcd.home();
      lcd.print("The Bomb Has ");                 // Je kan hier de tekst aanpassen tussen de "....."
      lcd.setCursor (0, 1);
      lcd.print("Exploded!");                     // Je kan hier de tekst aanpassen tussen de "....."

      while (Minutes < 0)
      {
        digitalWrite(redled, LOW);
        tone(9, 7000, 100);
        delay(100);
        digitalWrite(redled, HIGH);
        tone(9, 7000, 100);
        delay(100);
        digitalWrite(yellowled, LOW);
        tone(9, 7000, 100);
        delay(100);
        digitalWrite(yellowled, HIGH);
        tone(9, 7000, 100);
        delay(100);
        digitalWrite(greenled, LOW);
        tone(9, 7000, 100);
        delay(100);
        digitalWrite(greenled, HIGH);
        tone(9, 7000, 100);
        delay(100);
      }
    }
  }
  lcd.setCursor (0, 1);
  lcd.print ("Timer:");

  if (Hours >= 10)
  {
    lcd.setCursor (7, 1);
    lcd.print (Hours);
  }
  if (Hours < 10)
  {
    lcd.setCursor (7, 1);
    lcd.print ("0");
    lcd.setCursor (8, 1);
    lcd.print (Hours);
  }
  lcd.print (":");

  if (Minutes >= 10)
  {
    lcd.setCursor (10, 1);
    lcd.print (Minutes);
  }
  if (Minutes < 10)
  {
    lcd.setCursor (10, 1);
    lcd.print ("0");
    lcd.setCursor (11, 1);
    lcd.print (Minutes);
  }
  lcd.print (":");

  if (Seconds >= 10)
  {
    lcd.setCursor (13, 1);
    lcd.print (Seconds);
  }

  if (Seconds < 10)
  {
    lcd.setCursor (13, 1);
    lcd.print ("0");
    lcd.setCursor (14, 1);
    lcd.print (Seconds);
  }

  if (Hours < 0)
  {
    Hours = 01;
  }

  if (Minutes < 0)
  {
    Hours --;
    Minutes = 59;
  }

  if (Seconds < 1)
  {
    Minutes --;
    Seconds = 59;
  }

  if (Seconds > 0)
  {
    unsigned long currentMillis = millis();

    if (currentMillis - secMillis > interval)
    {
      tone(9, 7000, 50);
      secMillis = currentMillis;
      Seconds --;
      digitalWrite(yellowled, LOW);
      delay(10);
      digitalWrite(yellowled, HIGH);
      delay(10);
    }
  }
}

[/code]

I don't quite understand what it is you want to do. Can you say, step by step, how the prop works now and then say how you would like it to work?

@johnwasser
Yes I can :slight_smile:

Now it starts like this:
It ask me to enter a new password everytime
then it ask me to press # on the keypad attached to 'arm' the bomb
Then timer starts at 2 hours countdown.

How I want it to work:
cut a wire to start the clock
clock starts the countdown
enter the fixed password to disarm bomb

I think you want to delete from:

  lcd.setCursor(0, 0);
  lcd.print("Bom geactiveerd!");                 // Je kan hier de tekst aanpassen tussen de "....."
  lcd.setCursor(0, 1);
  lcd.print("Enter Code:");                     // Je kan hier de tekst aanpassen tussen de "....."

through

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Press # to arm");        // Je kan hier de tekst aanpassen tussen de "....."
    delay (50);
    keycount = 12;
  }

Then change the:

while (keycount == 12)
  {
    char armkey = keypad.getKey();

    if (armkey == '#')

to

   // Wait for trigger wire to be cut
    while (digitalRead(TriggerWirePin) == LOW) {}

Hi John, thanks for you answer. I got the Triggerwirepin working but the password is still not a static one.
So if I 'cut the wire' the clock starts the countdown but there is now password stored (a static one that I can put somewhere in the code). Can you point me in the right direction with it?

Try changing those to:
char password[] = "1234";

Thanks John, that was it to make it happen! It works but I see another little thing now...can I skip the "Press # to arm" message and button? So that cutting the wire immediately starts the countdown?

Started to remove the

while (keycount == 12)
  {
    char armkey = keypad.getKey();

    if (armkey == '#')
    {
      tone(9, 5000, 100);
      delay(50);
      tone(9, 0, 100);
      delay(50);
      tone(9, 5000, 100);
      delay(50);
      tone(9, 0, 100);
      delay(50);
      tone(9, 5000, 100);
      delay(50);
      tone(9, 0, 100);
      lcd.clear();
      lcd.print ("Bomb Armed!");        // Je kan hier de tekst aanpassen tussen de "....."
      lcd.setCursor(0, 1);
      lcd.print("Countdown start");     // Je kan hier de tekst aanpassen tussen de "....."
      delay(100);
      lcd.clear();
      keycount = 0;
    }

but that doesn't do the trick that I need

Yes. I told you how in Reply 4:

John...you're today's hero...I forgot to adress Triggerwirepin at pin 12... Now everything works perfect! My son says THANK YOU :slight_smile:

Glad that it all worked out.

You guys just put yourselves in the FBI's watchlist...

1 Like

It's harmless....a prop for a suprise gift for a 10 year old...:rofl:. Hope the FBI sees the difference otherwise they are welcome at our home to check it out

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.