Thanks everyone!
The sensor is this one https://www.alibaba.com/product-detail/GTRIC-photoelectric-sensor-M18-cylindrical-LS18_1601167457846.html
I have tried my best to make schematics here, but I have to admit it's not something I have done before. I tried 4 free programs to make one before giving up and just using Adobe XD. So I have just copied symbols from the internet and used lines and text.
Avoiding crossing wires was really hard for me because of all the components, so I made a gap where they cross but are not connected. Maybe I should give some sort of backstory here as to why I am trying to change my circuit in the first place.
Long story short: My garage door used to close automatically when I drove away, but it stopped working after I replaced a sensor. I'm using an Arduino setup with a MOSFET to trigger the garage door opener. It triggers when current starts flowing between the positive and the negative terminal marked "START". There is a 24V potential here. I have added two switches to show how I have connected a physical switch and a Meross garage door opener. Both work as they should.
The original circuit worked despite possibly being incorrectly designed.
I'm still learning about circuits and may have some misunderstandings. My main goal now is to design a circuit that works in theory before implementing it. The Arduino logic and code are working fine - it's the electrical aspect that's stumping me.
So here's the schematic for the circuit that worked perfectly:
Some notes on this is that I have been using ChatGPT and Claude.ai to learn, in addition to doing research myself and testing stuff. The problem with these chatbots is that they are so confident even though they are wrong, and they lack the reasoning skills to understand a lot of this. I need to catch that they are wrong to be able to get the correct answer, and oftentimes I don't.
This is the sole reason for the 100k ohm resistor between source and Arduino ground. ChatGPT said it should be there. Later on I have learned that there should be as little resistance as possible here, and that I absolutely need a common ground between the source, the Arduino and the negative from the 24V garage door opener.
Nevertheless, the circuit worked absolutely fine until one of the ultrasonic sensors started acting up. I have one for detecting the presence of each car, and one on each side of the door to detect blockage. One of the sensors for the door was detecting blockage all the time, so I swapped both out for a photoelectric sensor with a retroreflector.
While doing that I also found that the MOSFET had about 250 ohm resistance between gate and source, so that was bust. I therefore replaced that too.
After hooking up the new sensor the wiring looked like this:
The only problem was that it didn't work. The control logic worked fine, and PIN 7 got triggered when it was supposed to, but the door just either would do nothing or it would start and immediately stop.
Now here's the weird part. After triggering the door like this with the MOSFET, the physical switch and the Meross opener would not be able to open the door. Nothing would happen. The same was true for pressing "TEST" on the garage door motor itself. I needed to power cycle the motor for the physical button to work again. It would work until triggering the MOSFET, then it would stop working.
I did some measurements and found that before triggering the MOSFET I have about 22 - 24V potential between the source and drain, and also between the positive and negative on the terminals on the garage door motor and on the switch.
After triggering the MOSFET this voltage would go haywire and read 3, 12, 22, 18, 15, 23 etc. just switching back and forth. This would stop after power cycling.
This led me down the rabbit hole of ground loops and stuff like that. I thought maybe that I had an earth ground on the garage door motor connected to the negative terminal internally, and that my grounding scheme for the Arduino and connected sensors perhaps was at a slightly different potential.
That led to the question in my original post, but it's really getting this whole system to work that is my goal. With the first smaller goal being designing a circuit that should work in theory. I am thinking of swapping the MOSFET for a relay module with an optocoupler to isolate the 24V from the 5V of the Arduino.
I have to add: I did try to add another cable between Arduino ground and directly to source/the negative wire from the garage door terminal, but that made no difference.
I also don't get any continuity between the negative terminal and the garage door frame or the earth ground on the outlet, so I guess it's some kind of internal reference there?
I appreciate any feedback on how to improve this post or make the schematics clearer. As a novice in this field, I've found it challenging to locate forums or experts able to guide me through these issues. Learning through hands-on experience is rewarding but often complex. Your insights and questions not only help me but could also benefit others facing similar challenges.
Thank you for your patience and expertise!