Switching and sense circuit
How can the circuit be modified with very fewer components so that, the voltage from the MOSFET side does not go to OPTO and only goes to the IN/OUT connector? And Whenever Voltage comes from the IN/OUT Connector, the Opto should sense that, doesn't matter if it goes to MOSFET drain or not.


My deciphering of this requirement is:


I want to detect if LEDs are being powered from the MOSFET or from the manual switch.
How can I signal this via opto-isolator to the MCU?








simulate this circuit &ndash; Schematic created using CircuitLab

Figure 1. (a) Original circuit. (b) By reconfiguring the opto isolator we can sense current direction.

How Figure 1b works:


If MOSFET is on current flows to LEDs through D3. You will lose 0.7 V on the LED supply. 12 mA will flow through R2. Opto-LED will be reverse biased and will be off. 
If MOSFET is off and MANUAL switch is on then D2, the opto-LED is forward biased and Q2 will turn on.
If MOSFET is on AND the manual switch is on then D2 will be off.


If the MOSFET is on and you want to detect whether the manual switch has been closed or not you will have to periodically switch the MOSFET off for long enough to detect the opto-isolator turn on. A short blink every 100 ms or so shouldn't be noticable.