new-user
Posts: 4
Joined: Wed Jan 09, 2019 11:48 am

Controlling several electromagnets

Wed Jan 09, 2019 12:23 pm

I started a project in which I need to control 3 electromagnets using programming. I am building the magnets myself and I want them to be as powerful as possible, so the higher the voltage the better. What would be the best way to get the highest voltage for those magnets?
I was thinking about having the magnets attached to a 9V battery and having a switch in the Pi which disrupts the connection. So when the switch is closed the magnet would turn on. So...
Is this a valid way of controlling the magnets?
Would using a breadboard be sufficient?
What would that type of switch be called?

Thanks for reading.

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: Controlling several electromagnets

Wed Jan 09, 2019 1:09 pm

First of all. How big are those magnets. Because this will tell you sort of what voltage they can work on. And how much power they will be using.
And I think a 9v battery had not enough power for the magnets. But it will depend on the magnets.

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Controlling several electromagnets

Wed Jan 09, 2019 3:21 pm

new-user wrote:
Wed Jan 09, 2019 12:23 pm
I was thinking about having the magnets attached to a 9V battery and having a switch in the Pi which disrupts the connection. So when the switch is closed the magnet would turn on.
.......
What would that type of switch be called?
The type of switch you are probably looking for is called a relay. They are electro-magnetic switches. There are a few Pi HATs out there that have a few relays on them and there are some larger "non-HAT" boards compatible with the PI that have more relays on them.

Relays have a current/voltage rating i.e 20V @ 1 Amp. Check the rating to pick a relay that will work with your electromagnets. You'll need to test them and measure what current they draw.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
Burngate
Posts: 6313
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling several electromagnets

Wed Jan 09, 2019 6:57 pm

You're building the magnets yourself? As in winding some wire round a soft-iron core? I think we may need more details.

The strength of a magnetic field depends on the number of turns of wire and the current. Voltage is only needed to drive the current through the resistance of the wire - thinner wire has higher resistance so more voltage required, but you can get more turns in the same space so less current therefore less voltage ... swings versus roundabouts.

Also, when you switch on the current, it'll gradually build up, but switching it off again tries to cut the current instantaneously. That produces a large voltage that can cause sparks and destroy things, so put a diode across the coil to allow the current to die gradually.

new-user
Posts: 4
Joined: Wed Jan 09, 2019 11:48 am

Re: Controlling several electromagnets

Mon Jan 21, 2019 10:34 am

Thank you for the responses and sorry I didn't answer sooner, I was trying to workout if I could make the magnet or if I needed to build one. I ended up making one.
Brandon92 wrote: First of all. How big are those magnets. Because this will tell you sort of what voltage they can work on. And how much power they will be using.
And I think a 9v battery had not enough power for the magnets. But it will depend on the magnets.
Yes 9V should be enough I only need to attract a small mass (10-30 grams) a small distance (max 1 cm)
scotty101 wrote:
new-user wrote:
Wed Jan 09, 2019 12:23 pm
I was thinking about having the magnets attached to a 9V battery and having a switch in the Pi which disrupts the connection. So when the switch is closed the magnet would turn on.
.......
What would that type of switch be called?
The type of switch you are probably looking for is called a relay. They are electro-magnetic switches. There are a few Pi HATs out there that have a few relays on them and there are some larger "non-HAT" boards compatible with the PI that have more relays on them.

Relays have a current/voltage rating i.e 20V @ 1 Amp. Check the rating to pick a relay that will work with your electromagnets. You'll need to test them and measure what current they draw.
Does the "non-HAT" mean it doesn't need to be attached to the GPIO directly?
Burngate wrote: You're building the magnets yourself? As in winding some wire round a soft-iron core? I think we may need more details.

The strength of a magnetic field depends on the number of turns of wire and the current. Voltage is only needed to drive the current through the resistance of the wire - thinner wire has higher resistance so more voltage required, but you can get more turns in the same space so less current therefore less voltage ... swings versus roundabouts.

Also, when you switch on the current, it'll gradually build up, but switching it off again tries to cut the current instantaneously. That produces a large voltage that can cause sparks and destroy things, so put a diode across the coil to allow the current to die gradually.
As I mentioned above I already built my own magnet, by winding wire around a soft-iron core. Thanks for the information about the diode, do you know the average time increase in cutting the current?
Also what do you mean exactly by connecting it across the coil, can that just be at one of the ends coming out of the magnet?

User avatar
Burngate
Posts: 6313
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling several electromagnets

Mon Jan 21, 2019 12:31 pm

More info regarding your electromagnet needed - probably info you don't have!

"Soft-iron" isn't very informative - there's been a whole industry built around iron going back centuries, including how much carbon it contains (making steel) as well as other impurities. Calling it "soft" just means it doesn't retain much of an internal magnetic field when an external field is removed - "much" being somewhat vague.

Also, not only the size (how long, how wide) but also its shape can affect how it behaves.

Then, how many turns of wire? What thickness? The thickness, the number of turns and how long each turn is will determine the resistance. Probably best to measure the resistance with your meter, so you know how much current any particular voltage will drive through it.

Now to your question about time.
Here, we're going to step up into calculus - I vaguely remember it was GCE maths in my day, but it might now be sixth form or beyond, unless it's taught in primary school now.

A coil has a property called inductance, L
Put a voltage V across it, and a current I starts to build up according to the equation
V = L dI/dt
where dI/dt is the rate of change of current with time

The same equation tells you how much voltage is generated if the current changes at a certain rate.

If you try to cut the current instantaneously - dI/dt is infinite - the voltage is also going to be infinite, for an instant.
Naturally, infinity isn't realistic, and what happens is sparks happen - the voltage rises enough to make air conductive, and the current flows through that, for a short time.

Connecting a diode across the ends of the coil gives the current a path, so that it doesn't die too fast.
Normally, it's reverse-biased, so no current flows through it, but when you disconnect the voltage - switch off your relay, or whatever - the voltage changes direction, the negative end becomes positive, and the diode conducts.

At that point in time, the current is flowing through the coil and the diode, and the resistance of that path together with the inductance of the coil determines how long it takes for the current to die down.

Just as a capacitance and resistance have a time constant - RC seconds, where R is ohms and C is Farads - so does an inductance and resistance - L/R seconds, again R is ohms with L in Henries.

You probably don't know the inductance of your coil, so you won't know the time-scale of the decay.
The inductance will depend on number of turns, etc., but also the size and shape of the core, and what the iron is like.


new-user
Posts: 4
Joined: Wed Jan 09, 2019 11:48 am

Re: Controlling several electromagnets

Mon Jan 28, 2019 11:09 am

Burngate wrote: More info regarding your electromagnet needed - probably info you don't have!

Connecting a diode across the ends of the coil gives the current a path, so that it doesn't die too fast.
Normally, it's reverse-biased, so no current flows through it, but when you disconnect the voltage - switch off your relay, or whatever - the voltage changes direction, the negative end becomes positive, and the diode conducts.
Unfortunately the website I bought it off doesn't provide the relative permeability of the iron. However I have all the other information. What would be the best way to work out the resistance level required from the diode?

User avatar
Burngate
Posts: 6313
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Controlling several electromagnets

Mon Jan 28, 2019 12:18 pm

The diode doesn't of itself provide resistance - it just has a forward voltage drop of 0.6-0.7V. It just (effectively) provide a path for the current to flow.
Al it needs to do is carry the current you've been supplying - look on its datasheet to find out whether it can carry that current.

When the current first built up, when you switched it on, energy got stored in the magnetic field.
That energy has to go somewhere when you switch it off. It's that energy that causes sparks if you don't have the diode, and it gets lost as heat in the resistance of the winding while the current is going through the diode.

The coil winding can handle that with no problem - after all, you made sure it can handle the heat generated by the current flowing through its resistance (I²R) and the current doesn't grow when you switch it off.

Return to “Other projects”