How to use an optocoupler with a transistor on both sides?
Check the schematic below:



simulate this circuit &ndash; Schematic created using CircuitLab
When opto transistor is ON, external transistor's base gets grounded and it is turned OFF which turns OFF the load as well.
When opto transistor is OFF, external transistor turns ON due to pull up resistor R1. This turns the load ON.