My 4 x 4 timer wont jump to another function to make my sensor PIR enable

I want my keypad when the timer is counting until 0 second, it will jump to another function but it wont happen

#include <Keypad.h>
//#include <LiquidCrystal.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  //0x27 is the i2c address, while 16 = columns, and 2 = rows. 
const uint32_t alarm = 300000;
#include<stdio.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

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


int relay = 13;
int buzzer = 12;
int PIR = 10;

const int motionpin = A0;
int motionsensvalue=0;
int counter = 0; 
int attempts = 0; 
int max_attempts = 3; 

String mymints;
int minutes = 0; 

String mysecs; 
int seconds = 0; 
long int total_seconds = 0; 
int secflag = 0; 
int timer_started_flag = 0; 


// Tracks the time since last event fired
unsigned long previousMillis=0;
unsigned long int previoussecs = 0; 
unsigned long int currentsecs = 0; 
 unsigned long currentMillis = 0;
  int interval= 1 ; // updated every 1 second
int tsecs = 0; 
 
void setup(){
  Serial.begin(9600);
  lcd.begin();                 //Init the LCD
  lcd.backlight();            //Activate backlight 
  

  pinMode(relay, OUTPUT);
  pinMode(PIR, INPUT);
  digitalWrite(relay, LOW);
  digitalWrite(buzzer, LOW);
  Serial.println("enter password");
    lcd.print("Countdown Timer");

    delay(2000); 
    lcd.clear();
     lcd.print("Enter Minutes:");
}
  
void loop()
{
  
 keypadfunction();
 
}

void keypadfunction()
{ 
 char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);
    lcd.print(key);
  }
  
  if (key == '1')
  {

    mymints = mymints + 1;   
  }
  
    if (key == '2')
  {

    mymints = mymints + 2;  
  }
  
  if (key == '3')
  {
 
    mymints = mymints + 3; 
  }
  
   if (key == '4')
  {
  
    mymints = mymints + 4;  
  }
  
  if (key == '5')
  {
  
    mymints = mymints + 5;
  }
  
   if (key == '6')
  {
   
    mymints = mymints + 6; 
  }
  
   if (key == '7')
  {

    mymints = mymints + 7; 
  }

   if (key == '8')
  {

    mymints = mymints + 8; 
  }
  
  if (key == '9')
  {

    mymints = mymints + 9;
  }
             
                 if (key == '0')
  {

    mymints = mymints + 0; 
  }

                    if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  

    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }
  
  
        if (key == '*')
  {
lcd.clear();     
minutes = mymints.toInt();
Serial.println(minutes);
lcd.clear(); 
lcd.print("Minutes: "); 
lcd.setCursor(0,1); 
lcd.print(minutes); 
mymints = ""; // empty the string
delay(2000); 
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Seconds:");
counter = 0; 
secflag = 1; 

while(secflag == 1)
{
forSeconds(); 
}    
  }  
   
}

void forSeconds()
{ 
 char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);
    lcd.print(key);
  }
  
  if (key == '1')
  {

   mysecs = mysecs + 1;   
  }
  
    if (key == '2')
  {

   mysecs = mysecs + 2;  
  }
  
  if (key == '3')
  {
 
    mysecs = mysecs + 3; 
  }
  
   if (key == '4')
  {
  
    mysecs = mysecs + 4;  
  }
  
  if (key == '5')
  {
  
    mysecs = mysecs + 5;
  }
  
   if (key == '6')
  {
   
    mysecs = mysecs + 6; 
  }
  
   if (key == '7')
  {

    mysecs = mysecs + 7; 
  }

   if (key == '8')
  {

    mysecs = mysecs + 8; 
  }
  
  if (key == '9')
  {

    mysecs = mysecs + 9;
  }
             
                 if (key == '0')
  {

    mysecs = mysecs + 0; 
  }

                   if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  

    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }
  
  
  
        if (key == '*')
  {

lcd.clear();     
seconds = mysecs.toInt();
Serial.println(seconds);
lcd.clear();
lcd.setCursor(0,0); 
lcd.print("Seconds: "); 
lcd.setCursor(0,1); 
lcd.print(seconds); 
mysecs = ""; // empty the string
delay(2000); 
lcd.clear();
lcd.setCursor(0,0);
 
lcd.print("Mins      Secs"); 
lcd.setCursor(1,1); 
lcd.print(minutes); 
lcd.setCursor(10,1); 
lcd.print(seconds); 
total_seconds = (minutes * 60) + seconds ;
counter = 0;
secflag = 0; 
timer_started_flag = 1;

lcd.clear();
lcd.print("T Seconds:");
lcd.setCursor(11,0);
lcd.print( total_seconds );
delay(3000); 
while( timer_started_flag == 1)
{
   char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);

  }

   if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  
    total_seconds = 0; 
     timer_started_flag = 0;
    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }

         //  lcd.clear(); 
  lcd.setCursor(0,0); 
  lcd.print("T Seconds:");
  lcd.setCursor(11,0); 
  lcd.print( total_seconds );
  lcd.setCursor(0,1);
  if( total_seconds > 0)
  {
    digitalWrite(relay, LOW); 
    digitalWrite(buzzer, LOW);
  lcd.print("load ON "); 
  }

    if( total_seconds <= 0)
  {
    total_seconds = 0;
    digitalWrite(relay, HIGH); 
    tone(buzzer,100,1000);
    delay(10000);
    pilihan();
    lcd.print("load OFF"); 
  }

     currentMillis = millis();
   currentsecs = currentMillis / 1000; 
    if ((unsigned long)(currentsecs - previoussecs) >= interval) {
      total_seconds = total_seconds - 1;
      lcd.clear(); 
      previoussecs = currentsecs;
    }
}
 
  }  
  
}


void pilihan()
{
  char choice = keypad.getKey();
  switch (choice){
    case 'B' :
    lcd.clear();
    lcd.print("Not Set Timer"); 
    not_set_timer();
    break; 
  }
}


void not_set_timer(){
  Serial.println("Not Set Timer");
  while(motionsensvalue=analogRead(motionpin))// reads analog data from motion sensor
  {
    if (motionsensvalue>=200){
      char choice = keypad.getKey();
      if (choice == 'C'){
      lcd.clear();
      lcd.setCursor(0,1); 
      lcd.print("B. Not Set Timer");
      break;}
      else{
      lcd.clear();
      lcd.print("Not Set Timer");
      digitalWrite(relay,LOW);
      noTone(buzzer); 
      delay(5000);
            
      }
    }
    else {
      lcd.clear();
      lcd.print("Press C to Stop");
      digitalWrite(relay,HIGH); //turns on alarm buzzer
      tone(buzzer,100,5);
      delay(200);
      noTone(buzzer);
      keypadfunction();
    }
    char choice = keypad.getKey();
    if (choice == 'C'){
      lcd.clear(); 
      lcd.setCursor(0,1); 
      lcd.print("B. Not Set Timer");
      break;
    } 
  }
}

When i click my pad to setting time for timer using 4 x 4 pad, it wont happen. I dont know why, please help

#include <Keypad.h>
//#include <LiquidCrystal.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  //0x27 is the i2c address, while 16 = columns, and 2 = rows. 

#include<stdio.h>

//Variabel Keypad
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

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

//Variabel PIR
const int motionpin=A0;
int relay = 11;
const int ledpin=13;
const int buzzpin=12; // ledpin,motionpin and buzpin are not changed throughout the process
int motionsensvalue=0;

//variabel timer
int counter = 0; 
int attempts = 0; 
int max_attempts = 3; 

String mymints;
int minutes = 0; 

String mychoice;
int choice = 0;

String mysecs; 
int seconds = 0; 
long int total_seconds = 0; 
int secflag = 0; 
int timer_started_flag = 0; 

// Tracks the time since last event filedpin
unsigned long previousMillis=0;
unsigned long int previoussecs = 0; 
unsigned long int currentsecs = 0; 
unsigned long currentMillis = 0;
int interval= 1 ; // updated every 1 second
int tsecs = 0; 

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(motionpin,INPUT);
pinMode(buzzpin,OUTPUT);
lcd.begin();                 //Init the LCD
lcd.backlight();            //Activate backlight
Serial.println("enter password");
lcd.print("Countdown Timer");
delay(2000); 
lcd.clear();
Serial.println("idle_state");
  lcd.print("A. Set Timer");
  lcd.setCursor(0,1); 
  lcd.print("B. Not Timer Set");
}

//Main Code
void loop() {
// put your main code here, to run repeatedly:
  char choice = keypad.getKey();
  switch (choice){
    case 'A' : 
    keypadfunction();
    break;

    case 'B' :
    lcd.clear();
    lcd.print("Not Set Timer"); 
    not_set_timer();
    break; 

    case 'C' :
    lcd.clear();
    lcd.print("Stop"); 
    digitalWrite(ledpin,LOW);

    break; 
    default:
    break;
  }
}

void set_timer(){
  choice = 0;
  lcd.clear();
  lcd.print("Set Timer");
  keypadfunction();
}

void not_set_timer(){
  Serial.println("Not Set Timer");
  while(motionsensvalue=analogRead(motionpin))// reads analog data from motion sensor
  {
    if (motionsensvalue>=200){
      choice = 0;
      char choice = keypad.getKey();
      if (choice == 'C'){
        
      lcd.clear();
      lcd.print("A. Set Timer");
      lcd.setCursor(0,1); 
      lcd.print("B. Not Set Timer");
      break;}
      else{
      lcd.clear();
      lcd.print("Not Set Timer");
      tone(ledpin,LOW);
      noTone(buzzpin); 
      delay(5000);
            
      }
    }
    else {
      choice = 0;
      lcd.clear();
      lcd.print("Press C to Stop");
   //turns on alarm buzzer
      tone(buzzpin,100,5);
      delay(200);
      noTone(buzzpin);
      digitalWrite(ledpin,LOW);
    }
    char choice = keypad.getKey();
    if (choice == 'C'){
      choice = 0;
      lcd.clear(); 
      lcd.print("A. Set Timer");
      lcd.setCursor(0,1); 
      lcd.print("B. Not Set Timer");
      digitalWrite(ledpin,LOW);
      break;
    } 
  }
}







void keypadfunction()
{ 
  lcd.clear();
  lcd.print("Enter Minute");
 char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);
    lcd.print(key);
  }
  
  if (key == '1')
  {

    mymints = mymints + 1;   
  }
  
    if (key == '2')
  {

    mymints = mymints + 2;  
  }
  
  if (key == '3')
  {
 
    mymints = mymints + 3; 
  }
  
   if (key == '4')
  {
  
    mymints = mymints + 4;  
  }
  
  if (key == '5')
  {
  
    mymints = mymints + 5;
  }
  
   if (key == '6')
  {
   
    mymints = mymints + 6; 
  }
  
   if (key == '7')
  {

    mymints = mymints + 7; 
  }

   if (key == '8')
  {

    mymints = mymints + 8; 
  }
  
  if (key == '9')
  {

    mymints = mymints + 9;
  }
             
                 if (key == '0')
  {

    mymints = mymints + 0; 
  }

                    if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  

    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }
  
  
        if (key == '*')
  {
lcd.clear();     
minutes = mymints.toInt();
Serial.println(minutes);
lcd.clear(); 
lcd.print("Minutes: "); 
lcd.setCursor(0,1); 
lcd.print(minutes); 
mymints = ""; // empty the string
delay(2000); 
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Seconds:");
counter = 0; 
secflag = 1; 

while(secflag == 1)
{
forSeconds(); 
}    
  }  
   
}

void forSeconds()
{ 
 char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);
    lcd.print(key);
  }
  
  if (key == '1')
  {

   mysecs = mysecs + 1;   
  }
  
    if (key == '2')
  {

   mysecs = mysecs + 2;  
  }
  
  if (key == '3')
  {
 
    mysecs = mysecs + 3; 
  }
  
   if (key == '4')
  {
  
    mysecs = mysecs + 4;  
  }
  
  if (key == '5')
  {
  
    mysecs = mysecs + 5;
  }
  
   if (key == '6')
  {
   
    mysecs = mysecs + 6; 
  }
  
   if (key == '7')
  {

    mysecs = mysecs + 7; 
  }

   if (key == '8')
  {

    mysecs = mysecs + 8; 
  }
  
  if (key == '9')
  {

    mysecs = mysecs + 9;
  }
             
                 if (key == '0')
  {

    mysecs = mysecs + 0; 
  }

                   if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  

    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }
  
  
  
        if (key == '*')
  {

lcd.clear();     
seconds = mysecs.toInt();
Serial.println(seconds);
lcd.clear();
lcd.setCursor(0,0); 
lcd.print("Seconds: "); 
lcd.setCursor(0,1); 
lcd.print(seconds); 
mysecs = ""; // empty the string
delay(2000); 
lcd.clear();
lcd.setCursor(0,0);
 
lcd.print("Mins      Secs"); 
lcd.setCursor(1,1); 
lcd.print(minutes); 
lcd.setCursor(10,1); 
lcd.print(seconds); 
total_seconds = (minutes * 60) + seconds ;
counter = 0;
secflag = 0; 
timer_started_flag = 1;

lcd.clear();
lcd.print("T Seconds:");
lcd.setCursor(11,0);
lcd.print( total_seconds );
delay(3000); 
while( timer_started_flag == 1)
{
   char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);

  }

   if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  
    total_seconds = 0; 
     timer_started_flag = 0;
    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }

         //  lcd.clear(); 
  lcd.setCursor(0,0); 
  lcd.print("T Seconds:");
  lcd.setCursor(11,0); 
  lcd.print( total_seconds );
  lcd.setCursor(0,1);
  if( total_seconds > 0)
  {
    digitalWrite(relay, HIGH); 
    digitalWrite(ledpin, LOW);
  lcd.print("load ON "); 
  }

    if( total_seconds <= 0)
  {
    total_seconds = 0; 
    digitalWrite(relay, LOW); 
    digitalWrite(ledpin, HIGH);
  lcd.print("load OFF"); 
  }

     currentMillis = millis();
   currentsecs = currentMillis / 1000; 
    if ((unsigned long)(currentsecs - previoussecs) >= interval) {
      total_seconds = total_seconds - 1;
      lcd.clear(); 
      previoussecs = currentsecs;
    }
}
 
  }  
  
  
}

Cross posted >> My 4 x 4 timer wont jump to another function to make my sensor PIR enable

I have merged your posts due to them having too much overlap on the same subject matter @rdaffa59.

In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.

The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Thanks in advance for your cooperation.

is this a 3rd posting?

https://forum.arduino.cc/t/keypad-4-x-4-wont-work/1067509/2

I'm trying to use an Arduino UNO to read which button I push on a 4x4 matrix keypad, then output it on an LCD screen. However, I can't get the Arduino to read 4 x 4 pad when i pressed "B", it should go to another function and the keypad is work, but it doesn't.

Please help :frowning:

#include <Keypad.h>
//#include <LiquidCrystal.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  //0x27 is the i2c address, while 16 = columns, and 2 = rows. 

#include<stdio.h>

//Variabel Keypad
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

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

//Variabel PIR
const int motionpin=A0;
int relay = 11;
const int ledpin=13;
const int buzzpin=12; // ledpin,motionpin and buzpin are not changed throughout the process
int motionsensvalue=0;

//variabel timer
int counter = 0; 
int attempts = 0; 
int max_attempts = 3; 

String mymints;
int minutes = 0; 

String mychoice;
int choice = 0;

String mysecs; 
int seconds = 0; 
long int total_seconds = 0; 
int secflag = 0; 
int timer_started_flag = 0; 

// Tracks the time since last event filedpin
unsigned long previousMillis=0;
unsigned long int previoussecs = 0; 
unsigned long int currentsecs = 0; 
unsigned long currentMillis = 0;
int interval= 1 ; // updated every 1 second
int tsecs = 0; 

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(motionpin,INPUT);
pinMode(buzzpin,OUTPUT);
lcd.begin();                 //Init the LCD
lcd.backlight();            //Activate backlight
Serial.println("enter password");
lcd.print("Countdown Timer");
delay(2000); 
lcd.clear();
Serial.println("idle_state");
  lcd.print("A. Set Timer");
  lcd.setCursor(0,1); 
  lcd.print("B. Not Timer Set");
}

//Main Code
void loop() {
// put your main code here, to run repeatedly:
  char choice = keypad.getKey();
  switch (choice){
    case 'A' : 
    keypadfunction();
    break;

    case 'B' :
    lcd.clear();
    lcd.print("Not Set Timer"); 
    not_set_timer();
    break; 

    case 'C' :
    lcd.clear();
    lcd.print("Stop"); 
    digitalWrite(ledpin,LOW);

    break; 
    default:
    break;
  }
}

void set_timer(){
  choice = 0;
  lcd.clear();
  lcd.print("Set Timer");
}

void not_set_timer(){
  Serial.println("Not Set Timer");
  while(motionsensvalue=analogRead(motionpin))// reads analog data from motion sensor
  {
    if (motionsensvalue>=200){
      choice = 0;
      char choice = keypad.getKey();
      if (choice == 'C'){
        
      lcd.clear();
      lcd.print("A. Set Timer");
      lcd.setCursor(0,1); 
      lcd.print("B. Not Set Timer");
      break;}
      else{
      lcd.clear();
      lcd.print("Not Set Timer");
      tone(ledpin,LOW);
      noTone(buzzpin); 
      delay(5000);
            
      }
    }
    else {
      choice = 0;
      lcd.clear();
      lcd.print("Press C to Stop");
   //turns on alarm buzzer
      tone(buzzpin,100,5);
      delay(200);
      noTone(buzzpin);
      digitalWrite(ledpin,LOW);
    }
    char choice = keypad.getKey();
    if (choice == 'C'){
      choice = 0;
      lcd.clear(); 
      lcd.print("A. Set Timer");
      lcd.setCursor(0,1); 
      lcd.print("B. Not Set Timer");
      digitalWrite(ledpin,LOW);
      break;
    } 
  }
}







void keypadfunction()
{ 
  lcd.clear();
  lcd.print("Enter Minute");
 char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);
    lcd.print(key);
  }
  
  if (key == '1')
  {

    mymints = mymints + 1;   
  }
  
    if (key == '2')
  {

    mymints = mymints + 2;  
  }
  
  if (key == '3')
  {
 
    mymints = mymints + 3; 
  }
  
   if (key == '4')
  {
  
    mymints = mymints + 4;  
  }
  
  if (key == '5')
  {
  
    mymints = mymints + 5;
  }
  
   if (key == '6')
  {
   
    mymints = mymints + 6; 
  }
  
   if (key == '7')
  {

    mymints = mymints + 7; 
  }

   if (key == '8')
  {

    mymints = mymints + 8; 
  }
  
  if (key == '9')
  {

    mymints = mymints + 9;
  }
             
                 if (key == '0')
  {

    mymints = mymints + 0; 
  }

                    if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  

    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }
  
  
        if (key == '*')
  {
lcd.clear();     
minutes = mymints.toInt();
Serial.println(minutes);
lcd.clear(); 
lcd.print("Minutes: "); 
lcd.setCursor(0,1); 
lcd.print(minutes); 
mymints = ""; // empty the string
delay(2000); 
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Seconds:");
counter = 0; 
secflag = 1; 

while(secflag == 1)
{
forSeconds(); 
}    
  }  
   
}

void forSeconds()
{ 
 char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);
    lcd.print(key);
  }
  
  if (key == '1')
  {

   mysecs = mysecs + 1;   
  }
  
    if (key == '2')
  {

   mysecs = mysecs + 2;  
  }
  
  if (key == '3')
  {
 
    mysecs = mysecs + 3; 
  }
  
   if (key == '4')
  {
  
    mysecs = mysecs + 4;  
  }
  
  if (key == '5')
  {
  
    mysecs = mysecs + 5;
  }
  
   if (key == '6')
  {
   
    mysecs = mysecs + 6; 
  }
  
   if (key == '7')
  {

    mysecs = mysecs + 7; 
  }

   if (key == '8')
  {

    mysecs = mysecs + 8; 
  }
  
  if (key == '9')
  {

    mysecs = mysecs + 9;
  }
             
                 if (key == '0')
  {

    mysecs = mysecs + 0; 
  }

                   if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  

    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }
  
  
  
        if (key == '*')
  {

lcd.clear();     
seconds = mysecs.toInt();
Serial.println(seconds);
lcd.clear();
lcd.setCursor(0,0); 
lcd.print("Seconds: "); 
lcd.setCursor(0,1); 
lcd.print(seconds); 
mysecs = ""; // empty the string
delay(2000); 
lcd.clear();
lcd.setCursor(0,0);
 
lcd.print("Mins      Secs"); 
lcd.setCursor(1,1); 
lcd.print(minutes); 
lcd.setCursor(10,1); 
lcd.print(seconds); 
total_seconds = (minutes * 60) + seconds ;
counter = 0;
secflag = 0; 
timer_started_flag = 1;

lcd.clear();
lcd.print("T Seconds:");
lcd.setCursor(11,0);
lcd.print( total_seconds );
delay(3000); 
while( timer_started_flag == 1)
{
   char key = keypad.getKey();
  
  if (key){
    Serial.println(key);
    counter = counter + 1; 
    lcd.setCursor(counter, 1);

  }

   if (key == '#')
  {

    counter = 0;
    mymints = ""; 
    minutes = 0;  
    mysecs = ""; 
    seconds = 0; 
    secflag = 0;  
    total_seconds = 0; 
     timer_started_flag = 0;
    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Minutes:"); 
  }

         //  lcd.clear(); 
  lcd.setCursor(0,0); 
  lcd.print("T Seconds:");
  lcd.setCursor(11,0); 
  lcd.print( total_seconds );
  lcd.setCursor(0,1);
  if( total_seconds > 0)
  {
    digitalWrite(relay, HIGH); 
    digitalWrite(ledpin, LOW);
  lcd.print("load ON "); 
  }

    if( total_seconds <= 0)
  {
    total_seconds = 0; 
    digitalWrite(relay, LOW); 
    digitalWrite(ledpin, HIGH);
    lcd.print("load OFF"); 
  }

     currentMillis = millis();
   currentsecs = currentMillis / 1000; 
    if ((unsigned long)(currentsecs - previoussecs) >= interval) {
      total_seconds = total_seconds - 1;
      lcd.clear(); 
      previoussecs = currentsecs;
    }
}
 
  }  
  
  
}

i would test that the keypad code works without doing anything else.

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
  }

Once again, I have merged your posts due to them having too much overlap on the same subject matter @rdaffa59.

In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.

The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Thanks in advance for your cooperation.

the keypad is still function because when i split the code, the timer work.

if you're so convinced, then you don't have a problem

i would test again

So far you have only given a very short information which is unprecise.

Your keypad does not jump into another function. It is your code.
which function is "another function" ????

with such few informations you force your potential helpers to collect almost every information themselves instead that you - the one who is asking for help serves this information.

I don't enjoy collecting information that could be easily given by the TO.

You

can

describe in much more detail what you are observing.
Or do the other users here have to transplant new eyes into your head?

A very important thing for successfully finishing coding is:
making visible what is really going on.

On microcontrollers the most convenient way to make visible what is really going on is to print to the serial monitor.

Now in a fast running function

void loop() 

you don't want to print hundreds of messages to the serial monitor each second.

There are several coding-techniques to slow down the printing.

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