Opto isolators are smaller and cheaper than relays, also you can use exactly the same circuit to work with all the voltage sources that the OP mentioned. See my reply #2.
Opto isolators are smaller and cheaper than relays, also you can use exactly the same circuit to work with all the voltage sources that the OP mentioned. See my reply #2.