Arduino Freezes after working for few hours

I made a Home automation project and am able to control all my lights and everything with no errors at all. But major problem occurs after few hours. port stops responding. When I try to open port with IDE it says port busy and everything stops working. Then i have to remove Arduino USB from laptop and replug it and start everything again. Tried using Processing to provide serial input to Arduino. Also tried Batch files with "Echo "A" > com4: ". Both had the same problem. I think there is some problem with my Arduino code.

web.ino (18.4 KB)

Check Windows USB power savings settings.

already disabled. Issue remains the same :frowning:

My first guess is you have a bug on your code if power supply is not the issue as you said already.

What you can try to do is to start printing some serial outputs on specific points of your program and monitor this trough the serial to see when exactly the problem happens.
That's probably the easiest way to troubleshoot this further.

It takes time, but usually drives you to the root cause.

Thanks,