There are special analog optocouplers exactly for such purposes you are decribing. They that have not only one but two photodiodes that are illuminated by the same LED. The reason for two photodiodes is use one for a feed-back-loop on the transmitter side that takes care that the photocurrent is **proportional** to the input voltage. The second photodiode on the receiver side will have a photocurrent that is proportional to the first one because it is illuminated by the same LED. This way an analog signal can be transfered with high linearity. An example is the IL300. See e.g. following circuit: [![enter image description here][1]][1] [1]: https://i.sstatic.net/mz6dy.png