electromagnet controller

I need to build a device that will move a nail hanging from a string. I will use an electromagnet like this at a distance 5-10cm from the hanging nail and I want to create a swinging motion to the nail.

I was thinking to use a mosfet like this to turn on and off the electromagnet. I see that electromagnets are connected with a flyback diode in parallel and that mosfet module seems to have a diode on board.
How quickly am I allowed to turn on and off the electromagnet with the mosfet to be protected from voltage spikes? (for example 2-3 times per second is fine?)
Will I be able to use PWM with the mosfet and have a variable intensity field instead of turning it on and off?
Should I use a solid state relay instead?

rojoiko:
I need to build a device that will move a nail hanging from a string. I will use an electromagnet like this at a distance 5-10cm from the hanging nail and I want to create a swinging motion to the nail.

I was thinking to use a mosfet like this to turn on and off the electromagnet. I see that electromagnets are connected with a flyback diode in parallel and that mosfet module seems to have a diode on board.
How quickly am I allowed to turn on and off the electromagnet with the mosfet to be protected from voltage spikes? (for example 2-3 times per second is fine?)
Will I be able to use PWM with the mosfet and have a variable intensity field instead of turning it on and off?
Should I use a solid state relay instead?

Your project is getting WAY ahead of itself.

The first step is to determine if holding your electromagnet 5-10cm from the nail ans then connecting the 12 volts to the electromagnet will move your nail the way you want.

If that work the way you want, then you must measure the current drawn by the magnet when it is connected to the 12 volts. That way you can know how much current a mosfet must handle.

Next select a mosfet that will handle the current and then some and be turned completely on by less than 5 volts.

Now you are ready to connect things to your Arduino and try to control the mosfet with a digital pin. Be sure the grounds are all connected.

The inductance of the electromagnet determines how fast you can turn the magnet on and off.

And yes, you need the diode across the electromagnet.

Paul

That’s completely the wrong geometry of magnet to act at a distance.

You need a long straight cored electromagnet to have a large extent of magnetic field, 3 or 4 inches long will
have a reasonable range of action. And you probably won’t need anything like 8 watts to do the job.

That MOSFET module has nothing to indicate its logic-level, so don’t get it, get one that’s definitely logic level.
Also there’s no schematic so its not clear at all that it has a free-wheel diode.

What if I decrease the distance to 2-3cm? Will it work? I haven't used electromagnets before.
The mosfet is not logic level but it looks like there is an optocoupler on board so it used the optocoupler with logic level signal to turn on and off (that's my guess...) I will also add a diode in parallel on the mosfet module terminals to be sure that there is a flyback diode on the electromagnet.
Is it safe to use PWM on the arduino to drive the electromagnet's MOSFET?

rojoiko:
What if I decrease the distance to 2-3cm? Will it work? I haven't used electromagnets before.
The mosfet is not logic level but it looks like there is an optocoupler on board so it used the optocoupler with logic level signal to turn on and off (that's my guess...) I will also add a diode in parallel on the mosfet module terminals to be sure that there is a flyback diode on the electromagnet.
Is it safe to use PWM on the arduino to drive the electromagnet's MOSFET?

QUITE BEING SO SILLY!!! Just hook the magnet to the power and try it.

Paul

Gets even more interesting if that “nail” was a magnet..

Slumpert:
Gets even more interesting if that “nail” was a magnet..

And it soon will be if the OP ever gets brave enough to try something.

Paul

I wasn't trying anything because I hadn't receive my electromagnet yet.
I tried it with the MOSFET module (from the 1st post) and it seems to work fine. I can control the intensity of the field with PWM and the result is visible. It works only at 1-2cm but that's not a big issue.

When I use PWM to control it I can hear a buzz from the electromagnet. It's not buzzing when it gets full power. Is this normal? Could this cause any problem?

rojoiko:
I wasn't trying anything because I hadn't receive my electromagnet yet.
I tried it with the MOSFET module (from the 1st post) and it seems to work fine. I can control the intensity of the field with PWM and the result is visible. It works only at 1-2cm but that's not a big issue.

When I use PWM to control it I can hear a buzz from the electromagnet. It's not buzzing when it gets full power. Is this normal? Could this cause any problem?

So, up to this point, you were just wasting time, yours and ours.

The electromagnet buzzes because the windings of copper wire inside the magnet are not tightly held in position by epoxy or other potting compound, so they move a bit each time the PWM pulse of current occurs. If the turns move enough and over time, one will wear away the insulation on the wire and will either break or will begin to short wire turns together.

Paul