How to make my arduino uno act as a switch?

I'm not clear if you just want the electormagnet ON or OFF or whether you want to use a PWM signal to give variable magnetization.

If you want to use PWM (i.e. analogWrite()) you need to choose one of the PWM pins. Otherwise you can use any pin (apart from 0 and 1 which are the serial connection to your PC).

If I want to put a HIGH or low on (say) pin 3 it would be as simple as

pinMode(3, OUTPUT); // within setup()

digitalWrite(3, HIGH); // within the code that makes the electromagnet go on/off

...R