Read Integer From Text File Stored in SD Card

I made this code just for testing purpose, I wanted to read an integer from txt file stored in SD card and use that value to control led on off delay !

the integer is extracted fine, but the LED is not turning On or OFF, ive tried putting a constant instead of the value in the txt file but it is still not working. the code in the void setup seems to run fine, i used serial communication to read various values to check correct working.

#include <SD.h>
#include <stdlib.h>

File duty;
int input =0;

void setup()
{
  pinMode (13, OUTPUT);
  Serial.begin(9600);
  Serial.print ("Initializing Card....");
  pinMode(10, OUTPUT);
 
  if (!SD.begin(10))
  {
    Serial.println ("Card Initialization Failed !");
    return;
  }
  
  Serial.println ("Initialization Complete");
  char buffer[10];
  int index = 0;
   for(int i = 0; i < 10; i++)
   {
          buffer[i] = NULL;
   }
        
  duty = SD.open ("duty.txt");
  if (duty)
  {
    Serial.println("duty.txt:");
    while (duty.available())
    {
      int num = duty.read();
      if(num != 10)
      {
        //write in next location in buffer
        buffer[index++] = num;
         //Serial.println(buffer);
         Serial.write(num);
    }
    input = atoi(buffer);
  }
    duty.close();
  }
  else
  {
    Serial.println("Error Opening Text");
  }
 Serial.end(); 
}
void loop()
{
  digitalWrite (13, HIGH);
  delay(input);
  digitalWrite (13, LOW);
  delay(input);
}

The SD is a SPI device. If this is an Uno, then you can't use digital pin 13. That is the SPI clock (SCK).

Which pin can i use?

Can i use another pin to control the inbuilt LED on Uno ?

Which pin can i use?

I think 10,11,12,13 is used by SPI (SD), (and 0, 1 is used by Serial)
So there should be a few left for your LED

Can i use another pin to control the inbuilt LED on Uno ?

No, you'll have to use an external LED, with a series resistor.

      int num = duty.read();
      if(num != 10)
      {
        //write in next location in buffer
        buffer[index++] = num;
         //Serial.println(buffer);
         Serial.write(num);
    }
    input = atoi(buffer);

So, if the file contains "Twelve", it's OK to store the letters in the array?

The input to atoi() is expected to be a NULL terminated array of chars. Your array of chars is not NULL terminated. Danger lies this way.

Once you find a value in the file, you should break out of reading the file. Otherwise a files containing "12

" is going to cause issues.

Why do we need to NULL Terminate it? I check with LED on pin 8 & the code is working fine !

Why do we need to NULL Terminate it?

Because the atoi() function expects the input to be a NULL terminated array of characters. Since you are not providing a NULL terminated array of characters, the atoi() function will walk past the end of your array looking for a NULL or a non-integer character.

If you are lucky, you will always get away with not NULL terminating the array. I wouldn't count on that, though.