ULN2003 Used for security door magnets
Your optocoupler input is somewhat lacking.

To all intents and purposes an optocoupler is an NPN transistor. It's just controlled by light instead of base current.  Change the input circuit to be more like:







simulate this circuit &ndash; Schematic created using CircuitLab

(I have replaced your box with an actual transistor and LED so you can see better how it works).

When the output is HIGH (i.e., at VDD) the LED is off. That means the NPN is off. The resistor R1 pulls the base of the darlington pair high, which turns on the coil.

When the output is LOW (i.e., near 0V) the LED turns on. With the LED on the NPN is on. That pulls the base of the darlington pair down to ground, turning off the coil.

The way it's wired is a kind of double-inversion. The LED does the opposite to normal (on is LOW, off is HIGH) and the NPN in the optocoupler switches the darlington pair the opposite of how you would normally think to do it. The two together result in normal operation.

Yes, it is possible to use the NPN as a high-side switch, in which case you could invert the LED so it was on when HIGH, and use a pull-down instead of a pull-up, but I apply the same rule to optocouplers that I apply to all transistors when using them as switches: NPN are emitter direct to ground, PNP are emitter direct to power.