Problem of water pump with code is working

Hi everyone, I've got a problem on water pump. I am using a fingerprint sensor (AS608) to control a water pump. When the fingerprint match, the water pump start pumping liquid for 5 seconds and then stop. I have try the code and it works. However, once i have unplug the connection with the PC and connect again, the water pump keep pumping without stop. I have upload the code again and cannot stop. May I know what is the problem? Thank you!

#include <Adafruit_Fingerprint.h>



SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);



#define RELAY_PIN       10

#define ACCESS_DELAY    5000 // Keep lock unlocked for 3 seconds 





void setup()

{

  // set the data rate for the sensor serial port

  finger.begin(57600);

  delay(5);

  if (finger.verifyPassword()) 

  {

  } 

  else 

  {

    while (1) { delay(1); }

  }

  

  pinMode(RELAY_PIN, OUTPUT);

  digitalWrite(RELAY_PIN, HIGH);   //Switch off relay initially. Relay is LOW level triggered relay so we need to write HIGH.

}



void loop()

{

  if ( getFingerPrint() != -1)

  {

    digitalWrite(RELAY_PIN, HIGH);

    delay(ACCESS_DELAY);

    digitalWrite(RELAY_PIN, LOW);   

  }  

  delay(50);            //Add some delay before next scan.

}



// returns -1 if failed, otherwise returns ID #

int getFingerPrint() 

{

  int p = finger.getImage();

  if (p != FINGERPRINT_OK)  return -1;



  p = finger.image2Tz();

  if (p != FINGERPRINT_OK)  return -1;



  p = finger.fingerFastSearch();

  if (p != FINGERPRINT_OK)  return -1;



  // found a match!

  return finger.fingerID;

}

Please remove all empty lines and please post schematics. Pictures of wiring is not useful.
Some more help: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum

Did you try pushing the reset button in the uno?

You turn the relay on in setup()... and the fingerprint is failing to while(1)

I see, I just made a silly mistake, it works now, thanks!

But may I know why the water pump sometimes will operate once I connect to my PC, but sometimes not? Actually before I upload the code, the water pump did not operate even though it has 5v voltage to the pump :thinking:

Your pump is bad.