Ackdetect circuit:
ackdetect

Optocoupler data sheet:PC817.pdf