Use the first method in a robot. The second is better if you use 230V AC with a ground wire.

Have Fun
STB