I hav a trouble with the output voltage, the output was variation between
0-5 voltage not exactly 0v or 5v.
There are many types of optocouplers: transistor, Schmitt-trigger logic, FET. You are probably using one with a transistor output. The transistor is linear so its output voltage depends on the strength of the IR beam that is shining on it.
If you want the transistor to conduct hard then shine a strong IR beam on it. If you want the transistor to be cutoff then turn off the IR beam. Or use an opto-coupler with Schmitt-trigger logic at its output.