Thank you for the suggestion. I encountered an issue with the baud rate, which seemed to be causing the problem. Interestingly, the system only worked when set to the baud rate of 115200. Regardless of whether I tried the initial 9600 baud rate or any other standard baud rates such as 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, or 57600—both in the code and the serial monitor selection—none of them seemed to work except for 115200.
Making adjustments to all baud rates to 115200 resolved the issue.