If the power of each electromagnet is 120V / 2A DC or less, you would probably want two 1017
boards. Each one has eight relays that you can use to switch power to each electromagnet. Go to the user guide on the 1017's page for info on how you'd initially set it up. After that, you just have to choose a programming language and write some code based on how you want the magnets to function.
It goes without saying that depending on the power of the electromagnets, you should keep them away from the rest of the electronics to avoid interference.