Hi,
Not a softwavre more likely circuit problem.
In the current circuit setup, the relay operates flawlessly without any load, successfully switching the 5V voltage on and off. However, upon connecting the Waveshare TOF laser, the relay fails to activate. This behavior suggests a potential issue within the circuit. Here is the shematics:
Can't you wire another power source, like 5-6AA batteries or 9V PSU to the battery contacts?
Arduino, laser, relay through buck converter can draw way more than 300mA and 9V battery is not reliable power source.
Did you move the 5V supply from arduino VIN to 5V pin?
I have only one power supply for powering everything. When I made the first prototype and just wired the parts together it worked flawlessly. Now with the pcb I have this problem.
Not a surprise, correctly powered to 5V with sufficient current.
Which doesn't happen if you give 5V to VIN and especially if your battery can't provide sufficient current...