You can use an optoisolator circuit. They can be obtained off-the-shelf. But usually such questions bring into play the question of whether the person who is asking knows enough to safely avoid electrocuting themselves or someone else.
You can use an optoisolator circuit. They can be obtained off-the-shelf. But usually such questions bring into play the question of whether the person who is asking knows enough to safely avoid electrocuting themselves or someone else.