1

I am using a fingerprint sensor and GSM module on Arduino MEGA 2560. I want a fingerprint to be scanned every minute, if a minute elapses with no finger scanned, then the next code for the GSM to send an SMS must be executed enter image description here

const unsigned long timeLimit = 60000;
unsigned long prevTime;
unsigned long currTime;
void setup() {
 prevTime = millis();
}
void loop() {
 unsigned long currTime = millis();
 getFingerprintID(); //fingerprint func
 if (currTime - prevTime <= timeLimit) {
 if (finger.fingerSearch() == FINGERPRINT_OK) { //if the fingerprint matches
 prevTime = currTime;
 }
 } else {
 Serial.print("MAXIMUM TIME OF ");
 Serial.print(currTime / 1000);
 Serial.print(" SECONDS HAS LAPSED\n");
 }
}
Juraj
18.3k4 gold badges31 silver badges49 bronze badges
asked Nov 14, 2021 at 12:59
3
  • 2
    Consider looking at this forum.arduino.cc/t/using-millis-for-timing-a-beginners-guide/… What you need to do is create a timer that every 60 seconds executes the code that you want and sets a flag if it was successful and based on that you can do whatever you need with the GSM. Commented Nov 14, 2021 at 13:13
  • do something like this ... modify the millis code in the comment from @Coder_fox to increment a counter every second ... the millis code does nothing else ...... check for fingerprint, if detected then clear the counter to zero, do nothing else ...... check the counter, if 60 then send SMS Commented Nov 14, 2021 at 19:02
  • @Coder_fox the issue i have now is that the timer starts when i run the code and lapses within 60 seconds regardless of how many times the fingerprint was scanned within the time period Commented Nov 14, 2021 at 22:09

1 Answer 1

1

i cleaned up your version. make sure to update the prevTime variable.

const unsigned long timeLimit = 60000;
unsigned long prevTime ;
unsigned long currTime;
unsigned long elapsedTime;
int id;
void setup() {
prevTime=millis();
} 
void loop() {
 if (fingerprint()){
 currTime = millis();
 elapsedTime = currTime- prevTime;
 if (elapsedTime < 60*1000) {
 prevTime = currTime;
 } else {
 sendSms();
 }
 }
}
void sendSms() {
Serial.print("MAXIMUM TIME OF ");
Serial.print(currTime/1000);
Serial.print(" SECONDS HAS LAPSED\n");
}
bool fingerprint(){
 bool fingerPrintAccepted = false;
 if (finger.fingerSearch()==FINGERPRINT_OK){
 fingerPrintAccepted = true;
 }
 return fingerPrintAccepted;
}
answered Nov 16, 2021 at 19:24
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.