As a starting point and assuming you have instantiated the LCD object, something like:
void setup() {
char code[5];
int charsRead;
Serial.begin(9600);
lcd.print("Hello World !!");
delay(5000);
lcd.print("Enter Code: ");
if (Serial.available() > 0) {
charsRead = Serial.readBytesUntil('\n', code, sizeof(code) - 1); // Save room for NULL
vode[charsRead] = '\0'; // Now it's a string
Serial.println(code); // Shows you the code entered
}
}
might work. The readBytesUntil() method reads input until the Enter key is sensed, or 4 characters are entered. We then add the null character so it can be used as a C string, and display it. What you do from there is up to you.