Bluetooth not connecting error
What i have learnt working with HC-05 modules is that communicates through its RX/TX lines at 9600 baud. But, if you need to send/receive AT commands, then the baud rate needs to be 38400 and needs to have the EN pin driven high on startup. I haven't checked the rest of your code, but since you are not programming using AT commands, then the baud rate needs to be set to 9600 with only VCC,GND,RX,TX lines connected to the microcontroller.
HC-05 works best with Arduino's native serial port. My personal experience is that HC-05 struggles to maintain stable connection with SoftwareSerial library. Although HC-06 works with SoftwareSerial with no problems.