why my led is not going to be turn off after one minute?

led goes off and again ON

char blueToothVal;
int fklc=0,tkl=0,tklc=0,thl=0,thlc=0;
char lastValue;
//int cnt;
void setup(){
Serial.begin(9600);
pinMode(13, OUTPUT);
// pinMode(12, OUTPUT);
// pinMode(11,OUTPUT);
cli();//stop interrupts

//set timer1 interrupt at 1Hz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = 15624;// = (1610^6) / (11024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12 and CS10 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);

sei();//allow interrupts
//cli();
}//end setup

ISR(TIMER1_COMPA_vect){//timer1 interrupt 1Hz toggles pin 13 (LED)
//generates pulse wave of frequency 1Hz/2 = 0.5Hz (takes two cycles for full wave- toggle high then toggle low)

//char blueToothVal;
if(Serial.available())//if there is data being recieved
{
blueToothVal=Serial.read(); //read it
}

if(blueToothVal=='a')//if value from bluetooth serial is n
{
int fk=60;//for one minute to glow led
digitalWrite(13,HIGH); //switch on LED
if (lastValue!='a')
Serial.println(F("Relay3 is on")); //print LED is on
lastValue=blueToothVal;
fklc=fklc+1;
if(fklc>=fk)
{
digitalWrite(13,LOW);
Serial.println(F("Relay3 is OFF"));
fklc=0;
tklc=0;
}
}

void loop(){
//do other things here
// digitalWrite(13,LOW);
}

Serial I/O in an interrupt service routine is a bad idea.

Your comments and your code claim different things are connected to pin 13. Get your act together. Make up your mind what is connected to pin 13.

Useless comments are worse than no comments. There is NOTHING that explains WHY you are doing anything.

If all you want to do is make something go on and off every second why bother with Timers or interrupts? Just use millis()

...R

Robin2:
If all you want to do is make something go on and off every second why bother with Timers or interrupts?

Perhaps to learn about Timers and Interrupts? Maybe?

BulldogLowell:
Perhaps to learn about Timers and Interrupts? Maybe?

Counsel is leading the witness :slight_smile:

I was looking for the OP to explain his needs.

...R