* SPICE netlist
D2 0 N003 1N4148
D3 N002 OT1 1N4148
D4 N002 0 1N4148
R1 N004 N003 330
D5 N002 N009 1N750
D7 N002 N008 1N750
R2 N009 N010 220
R3 N010 N002 100
XU1 N005 0 N004 N008 PC817 Igain=1m ;pnba A)K)C)E
XU2 N010 N002 P001 RX PC817 Igain=1m ;pnba A)K)C)E
VTX N006 0 PULSE(0 3.3 0 0 0 5m 10m)
R5 N006 N005 330
R6 RX 0 10k
V3 P001 0 3.3
D6 N002 N004 BZX84C15L
D1 OT1 N003 1N4148
V1 N001 N007 24
R4 OT1 N001 100
I1 0 N007 PULSE(6m 17m 0 0 0 5m 10m)
M1 N009 N004 N003 N003 AO3423
.tran 100m

* LTspice schematic (.asc)
Version 4
SHEET 1 1600 688
WIRE -688 -328 -800 -328
WIRE -464 -328 -608 -328
WIRE -256 -328 -464 -328
WIRE -800 -264 -800 -328
WIRE -336 -232 -400 -232
WIRE -256 -232 -256 -328
WIRE -256 -232 -272 -232
WIRE -224 -232 -256 -232
WIRE -112 -232 -160 -232
WIRE -112 -184 -112 -232
WIRE 32 -184 -112 -184
WIRE 80 -184 32 -184
WIRE 192 -184 160 -184
WIRE 352 -184 192 -184
WIRE 592 -184 544 -184
WIRE 800 -184 672 -184
WIRE -800 -152 -800 -184
WIRE -400 -120 -400 -232
WIRE -336 -120 -400 -120
WIRE -256 -120 -272 -120
WIRE -224 -120 -256 -120
WIRE -112 -120 -112 -184
WIRE -112 -120 -160 -120
WIRE 32 -88 32 -184
WIRE 352 -88 272 -88
WIRE 576 -88 544 -88
WIRE 192 -72 192 -184
WIRE 192 -72 80 -72
WIRE 576 -56 576 -88
WIRE 800 -56 800 -104
WIRE -800 -40 -800 -72
WIRE -544 -40 -800 -40
WIRE -464 -40 -544 -40
WIRE -256 -40 -256 -120
WIRE -256 -40 -464 -40
WIRE -544 -8 -544 -40
WIRE 192 8 192 -72
WIRE 32 24 32 8
WIRE 32 24 -48 24
WIRE 32 40 32 24
WIRE -48 88 -48 24
WIRE 32 136 32 120
WIRE 464 136 32 136
WIRE 768 136 736 136
WIRE 32 152 32 136
WIRE 768 168 768 136
WIRE 272 216 272 -88
WIRE 464 232 336 232
WIRE 704 232 656 232
WIRE 800 232 704 232
WIRE -400 280 -400 -120
WIRE -48 280 -48 152
WIRE -48 280 -400 280
WIRE 32 280 32 232
WIRE 32 280 -48 280
WIRE 192 280 192 72
WIRE 192 280 32 280
WIRE 272 280 192 280
WIRE 336 280 336 232
WIRE 336 280 272 280
WIRE 704 344 704 312
FLAG 704 344 0
FLAG 576 -56 0
FLAG 800 -56 0
FLAG 768 168 0
FLAG 800 232 RX
FLAG -464 -328 OT1
FLAG -544 -8 0
FLAG -464 -40 OT2
SYMBOL diode -224 -104 R270
SYMATTR InstName D2
SYMATTR Value 1N4148
SYMBOL diode -336 -216 R270
SYMATTR InstName D3
SYMATTR Value 1N4148
SYMBOL diode -336 -104 R270
SYMATTR InstName D4
SYMATTR Value 1N4148
SYMBOL res 176 -200 R90
SYMATTR InstName R1
SYMATTR Value 330
SYMBOL zener -32 152 R180
SYMATTR InstName D5
SYMATTR Value 1N750
SYMBOL zener 288 280 R180
SYMATTR InstName D7
SYMATTR Value 1N750
SYMBOL res 16 24 R0
SYMATTR InstName R2
SYMATTR Value 220
SYMBOL res 16 136 R0
SYMATTR InstName R3
SYMATTR Value 100
SYMBOL Optos\\PC817A 448 -136 M0
SYMATTR InstName U1
SYMBOL Optos\\PC817A 560 184 R0
SYMATTR InstName U2
SYMBOL voltage 800 -200 R0
SYMATTR InstName TX
SYMATTR Value PULSE(0 3.3 0 0 0 5m 10m)
SYMBOL res 688 -200 R90
SYMATTR InstName R5
SYMATTR Value 330
SYMBOL res 688 216 R0
SYMATTR InstName R6
SYMATTR Value 10k
SYMBOL voltage 640 136 R270
SYMATTR InstName V3
SYMATTR Value 3.3
SYMBOL zener 208 72 R180
SYMATTR InstName D6
SYMATTR Value BZX84C15L
SYMBOL diode -224 -216 R270
SYMATTR InstName D1
SYMATTR Value 1N4148
SYMBOL voltage -800 -280 R0
SYMATTR InstName V1
SYMATTR Value 24
SYMBOL res -592 -344 R90
SYMATTR InstName R4
SYMATTR Value 100
SYMBOL current -800 -72 R180
SYMATTR InstName I1
SYMATTR Value PULSE(6m 17m 0 0 0 5m 10m)
SYMBOL pmos 80 8 R180
SYMATTR InstName M1
SYMATTR Value AO3423