In a few projects i have, where i use the arduino to drive higher loads (stepper motors, high power LED etc) i can only upload the sketch if i disconnect the high power circuit completely.
E.g. using arduino nano to switch a MOSfet, a 24V 40W load goes through drain/source and only the gate and common gnd is connected to the arduino. With the LED power supply powered up i can only some times upload the sketch. Need to switch off the power entirely to upload. Makes prototyping and testing a bit annoying.
I am guessing there is some noise involved. Anyone know the reason and any good tips on how to fix it? Should i be filtering/smoothing some voltage lines or something something?
These type of problems are very difficult to resolve. I will take a SWAG, It sounds like ground noise possibly via the USB connection. Post a complete schematic showing all connections and links to technical info on all hardware parts. I would place R2 on the other side of R1, you have a voltage divider in the gate circuit. You picked a good MOSFET, I would suggest checking the max Vgs rating, I could not find it and 18V Zener appears a bit high to me, consider a 12 volt one.
Good point, not much of a divider 68/10000 but still...
The Vgs is +/-20 so 18V zener is fine. I wanted to minimize the current though the 68R resistor when running on a 24V supply while not making the 68R larger then necessary as it slows switching and this is PWM control. The PWM frequency is not that high so could probably make the 68R larger, but moved on to other things that did not work (like the software)
You need to keep power ground current flowing in separate conductors to signal ground current then join the 2 at a single point. To be helpful we need to see both the schematic and how you have physically constructed the circuit, which means take clear photos of it.
Also, and this is speculation, if you have your the power supply for the high power stuff connected while uploading then maybe there is a ground loop: Mains earth to PC > PC to board via USB > board ground to power ground > power ground back to mains earth via its mains lead.
Update on this circuit. There have been a lot of opto-isolator failures in the field. So I would not recommend using TLP5771. I am in the process of building a new circuit using a different component.