interfacing arduino uno + lcd + BLE + SD card + ps2keyboard + sensors(pulse etc)

1)Hello, i am trying to make a patient health detecting kit which includes sensors like pulse and lm35 (for body temp). But i want to store the data taken in a SD card which contains a file that will store name, pulse and body temp. Also i want to see live data on a android app with BLE. I am using ps2 keyboard for taking names of patients. i have made a program combining all of these but it seems that the code is not proper. Problem lies with the keyboard and pulse part. The pulse part needs to be in a loop as i am calculating the time between 2 pulses to calculate BPM thus using for loop for some time. Please tell whether in what other way can i make my program work.
2) interfacing of so much devices also have made me change and set different pins for different things, plz check whether the assigned pins in the code are also right
thank you in advance for help

#define pulsePin A0

#include <SoftwareSerial.h>
SoftwareSerial BTserial(0, 1); // RX | TX

int tempPin = 1;

int relay = 16;

#include <PS2Keyboard.h>
const int DataPin = 2;
const int IRQpin =  3;
PS2Keyboard keyboard;

#include<LiquidCrystal.h>
const int rs = 9, en = 10, d4 = 5, d5 = 6, d6 = 7, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#include <SPI.h>
#include <SD.h>
File myFile;


//  VARIABLES
int rate[10];
unsigned long sampleCounter = 0;
unsigned long lastBeatTime = 0;
unsigned long lastTime = 0, N;
int BPM = 0;
int IBI = 0;
int P = 512;
int T = 512;
int thresh = 512;
int amp = 100;
int Signal;
boolean Pulse = false;
boolean firstBeat = true;
boolean secondBeat = true;
boolean QS = false;
int val;


void setup() {

  lcd.setCursor(0, 1);

  pinMode(relay, OUTPUT);

  BTserial.begin(9600);
  Serial.begin(9600);
  delay(1000);

  keyboard.begin(DataPin, IRQpin);

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  lcd.print("Initializing SD card...");
  if (!SD.begin(4)) {
    lcd.println("initialization failed!");
    while (1);
  }
  lcd.println("initialization done.");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
}

void loop() {

  lcd.print("Enter Patient's Name");
  //keyboard on

  if (keyboard.available()) {
    // read the next key
    char c;

    while (c == PS2_END) {
      c = keyboard.read();
      // check for some of the special keys
      if (c == PS2_ENTER) {
        lcd.println();
        myFile.println();
      } else if (c == PS2_TAB) {
        lcd.print("[Tab]");
        myFile.print("[Tab]");
      } else if (c == PS2_DELETE) {
        lcd.print("[Del]");
        myFile.print("[Del]");
      } else if (c == PS2_LEFTARROW) {
        lcd.print("[Left]");
        myFile.print("[Left]");
      }
      else {
        // otherwise, just print all normal characters
        lcd.print(c);
        myFile.print(c);
      }
    }
    myFile.print("[Tab]");


    //RELAY
    digitalWrite(relay, HIGH);


    //temp
    val = analogRead(tempPin);
    float mv = ( val / 1024.0) * 5000;
    float cel = mv / 10;
    float farh = (cel * 9) / 5 + 32;
    BTserial.print("TEMPRATURE = ");
    BTserial.print(cel);
    myFile.print(cel);
    BTserial.print(",");
    BTserial.print("TEMPRATURE(farh) = ");
    BTserial.print(farh);
    BTserial.print(",");
    delay(1000);
    myFile.print("[Tab]");

    //pulse
    for (int y = 0; y <= 25; y++) {
      if (QS == true) {
        BTserial.println("BPM: " + String(BPM));
        BTserial.print(";");
        QS = false;
      } else if (millis() >= (lastTime + 2)) {
        readPulse();
        lastTime = millis();
      }
    }
    myFile.print(String(BPM));
    myFile.println();
    lcd.print("Done");
    c = keyboard.read();

    // check for some of the special keys
    while (c == PS2_ENTER) {
    }
  }
}



void readPulse() {

  Signal = analogRead(pulsePin);
  sampleCounter += 2;
  int N = sampleCounter - lastBeatTime;

  detectSetHighLow();

  if (N > 250) {
    if ( (Signal > thresh) && (Pulse == false) && (N > (IBI / 5) * 3) )
      pulseDetected();
  }

  if (Signal < thresh && Pulse == true) {
    Pulse = false;
    amp = P - T;
    thresh = amp / 2 + T;
    P = thresh;
    T = thresh;
  }

  if (N > 2500) {
    thresh = 512;
    P = 512;
    T = 512;
    lastBeatTime = sampleCounter;
    firstBeat = true;
    secondBeat = true;
  }

}

void detectSetHighLow() {

  if (Signal < thresh && N > (IBI / 5) * 3) {
    if (Signal < T) {
      T = Signal;
    }
  }

  if (Signal > thresh && Signal > P) {
    P = Signal;
  }

}

void pulseDetected() {
  Pulse = true;
  IBI = sampleCounter - lastBeatTime;
  lastBeatTime = sampleCounter;

  if (firstBeat) {
    firstBeat = false;
    return;
  }
  if (secondBeat) {
    secondBeat = false;
    for (int i = 0; i <= 9; i++) {
      rate[i] = IBI;
    }
  }

  word runningTotal = 0;

  for (int i = 0; i <= 8; i++) {
    rate[i] = rate[i + 1];
    runningTotal += rate[i];
  }

  rate[9] = IBI;
  runningTotal += rate[9];
  runningTotal /= 10;
  BPM = 60000 / runningTotal;
  QS = true;
}

It doesn’t make sense to output “Enter Patient’s Name” with every iteration of loop(). Also reading and processing keys deserves some more fixes and extensions, like an array where the input is stored.

Try to put the kbd input into a subroutine, that can be called from loop(). That subroutine should return almost immediately, if no key is pressed or after a pressed key was processed.