74HC126D buffer IC with Arduino Uno 3

I also want to connect optocoupler moc7811.

Te MOC7811 is not an opto coupler it is an opto slot.
Use it like this (attached)

Can you please tell me how to connect 4 pins of position encoder

What position encoder, there are lots of different types.

Opto slot.png