perik
Posts: 28
Joined: Sat May 10, 2014 3:12 pm

12 v for driving electromagnets PCA9685

Sun Aug 18, 2019 12:23 pm

Im thinking of buying PCA9685 to control the magnetis in 16 electromagnets from raspberry pi. I intend to supply the electromagnets with 12v and connect it according to this image from adafruit. Only supply with 12 v instead of 5 v.
https://learn.adafruit.com/assets/59271

My question is: can I feed this with 12volts external power? I am a bit confused regarding the specs. Have read a different about this. On some pages it is said that it goes up to 12 V but as far as I can see it says max 6 V in the spec.

For example here at adafruit it says:
" If you have to, you can go higher to 12VDC, but if you mess up and connect VCC to V+ you could damage your board! "

https://learn.adafruit.com/16-channel-p ... er/pinouts

Im not planning to buy it from adafruit but from europe but I guess this is exactly the same:
http://www.nxp.com/docs/en/data-sheet/PCA9685.pdf

Can I drive my magnets with 12 v connected to the external powersupply input?

Thanks

pcmanbob
Posts: 6649
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 12 v for driving electromagnets PCA9685

Sun Aug 18, 2019 1:03 pm

You will not be able to drive electromagnets directly with the PCA9685 , because that is a servo controller chip ,
it provides pwm signals to the servo , these are low voltage 4-6V and very low current , the servo has its own power supply and control circuits within it that take the signal from the PCA9685 and use them to control the motor using the external power supply.

If you want to control electromagnets you will need to use a transistor driver circuit for each electromagnet which you may be able to drive from the PCA9685, but you would still need the 12v supply to actually power the electromagnets.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: 12 v for driving electromagnets PCA9685

Sun Aug 18, 2019 1:31 pm

The PCA9685 is designed to provide PWM to LEDs. It has an operating voltage in the range 2.3 V to 5.5 V and can supply roughly 25 mA per LED. It's not any good for 12V or electromagnets.

You probably ought to be looking at something like the ULN2803 series.

pcmanbob
Posts: 6649
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 12 v for driving electromagnets PCA9685

Sun Aug 18, 2019 1:39 pm

joan wrote:
Sun Aug 18, 2019 1:31 pm
You probably ought to be looking at something like the ULN2803 series.
Don't think the ULN2803 series would be suitable either maximum of 500mA per output, would expect electromagnets to be in the amps range, unless they are very small, which is why I said transistor driver circuit probably fet or mosfet
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: 12 v for driving electromagnets PCA9685

Sun Aug 18, 2019 1:42 pm

pcmanbob wrote:
Sun Aug 18, 2019 1:39 pm
joan wrote:
Sun Aug 18, 2019 1:31 pm
You probably ought to be looking at something like the ULN2803 series.
Don't think the ULN2803 series would be suitable either maximum of 500mA per output, would expect electromagnets to be in the amps range, unless they are very small, which is why I said transistor driver circuit probably fet or mosfet
Yes, it really depends on the electomagnets.

pcmanbob
Posts: 6649
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 12 v for driving electromagnets PCA9685

Sun Aug 18, 2019 1:52 pm

joan wrote:
Sun Aug 18, 2019 1:42 pm
pcmanbob wrote:
Sun Aug 18, 2019 1:39 pm
joan wrote:
Sun Aug 18, 2019 1:31 pm
You probably ought to be looking at something like the ULN2803 series.
Don't think the ULN2803 series would be suitable either maximum of 500mA per output, would expect electromagnets to be in the amps range, unless they are very small, which is why I said transistor driver circuit probably fet or mosfet
Yes, it really depends on the electomagnets.
left guessing as usual due to lack of specifications by OP.

must get my crystal ball fixed :lol:
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

perik
Posts: 28
Joined: Sat May 10, 2014 3:12 pm

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 2:53 pm

Thanks for the replies!

To be honest Im not 100% sure regarding the electromagnets. My idea is to create them myself, I just need to study a bit regarding a proper way of doing it to avoid heating problems ...

I created a sketch in Fritzing using an IRF520 MOSFET module. Any thoughts is very much apreciated! I guess this sketch also applies if I decide to lower the voltage to say 5 volt. Could be so, if I get heating problems.
electromagnets.png
electromagnets.png (96.29 KiB) Viewed 849 times
Thanks

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 3:10 pm

What is the point of the PCA9685? I can't see the relevance of PWM output to an electromagnet. Surely you want them on or off, not vibrating like a hive of demented bees.

perik
Posts: 28
Joined: Sat May 10, 2014 3:12 pm

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 3:15 pm

the idea is to idividually controll the strength of the magnets

danjperron
Posts: 3391
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 3:35 pm

You should use something else than the IRF520 mosfet. Use a mosfet with a lower Vgs like RFP30N06LE.

There is a kit from amazon. https://www.amazon.ca/gp/product/B0154KMLUC

B.T.W. if you are using PWM you will have to check how much the mosfet heat since it won't be a clear ON/OFF.

Do not forget to put a protection diode in inverse to the coil to kill the return EMF.

User avatar
davidcoton
Posts: 4019
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 7:37 pm

danjperron wrote:
Mon Aug 19, 2019 3:35 pm
B.T.W. if you are using PWM you will have to check how much the mosfet heat since it won't be a clear ON/OFF.
Yes it will. That is the point of PWM -- control is achieved by being full on for a variable period, and full off for the rest of the cycle. Thus, the device output is controlled without losses in the switching element. (there is of course some loss while the MOSFRET switches, but that is a short period compared to full analogue control.

OTOH PWM relies on the load characteristics to smooth out the signal. Thermal lag in the case of a heater, the human eye response in the case of LEDs. I'm not sure how well that works with an electromagnet.
Signature retired

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 10:22 pm

You'll have to use the Pi to drive the gate on a transistor.
The transistor in it's turn, will drive whatever else you've plugged in it.

User avatar
davidcoton
Posts: 4019
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 10:28 pm

ProDigit wrote:
Mon Aug 19, 2019 10:22 pm
You'll have to use the Pi to drive the gate on a transistor.
The transistor in it's turn, will drive whatever else you've plugged in it.
No, there are MOSFETs that can be driven directly from the Pi GPIO.
(Bipolar) transistors have a Base, MOSFETs have a Gate.
[pedant]MOSFET = Metal Oxide Semiconductor Field Effect Transistor[/pedant
Signature retired

perik
Posts: 28
Joined: Sat May 10, 2014 3:12 pm

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 10:45 pm

danjperron wrote: You should use something else than the IRF520 mosfet. Use a mosfet with a lower Vgs like RFP30N06LE.
VGS is the voltage where to MOSFET is turned on -> the gate is open right?
On the RFP30N06LE the specs says MIN 1v and MAX 2v
On the IRF520 the specs says MIN 2v and MAX 4v

What does this really mean?

Actually RFP30N06LE didnt existed anymore where I order my parts (in Sweden). Are there any good alternatives? Most places in Sweden do sell the IRF520 recommended for arduino and PI. Why is this not a good idea for me?
danjperron wrote: Do not forget to put a protection diode in inverse to the coil to kill the return EMF.
I also did put a diode on the electromagnets. I picked a LED for 12 v, I guess that works as good as a ordinary diode? Or how shall I pick correct diode?

Here is my updated Breadboard. Is it correct to put the leds the way I did?
electromagnets2.png
electromagnets2.png (106.46 KiB) Viewed 747 times

User avatar
davidcoton
Posts: 4019
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: 12 v for driving electromagnets PCA9685

Mon Aug 19, 2019 11:38 pm

perik wrote:
Mon Aug 19, 2019 10:45 pm

On the RFP30N06LE the specs says MIN 1v and MAX 2v
On the IRF520 the specs says MIN 2v and MAX 4v

What does this really mean?
It means that the turn-on voltage of an IRF520 might be 4V, which in turn means there is no guarantee that the Pi GPIO voltage (3V3) will turn it on.
perik wrote:
Mon Aug 19, 2019 10:45 pm
Actually RFP30N06LE didnt existed anymore where I order my parts (in Sweden). Are there any good alternatives? Most places in Sweden do sell the IRF520 recommended for arduino and PI. Why is this not a good idea for me?
Because it may not work -- see above. Choose a MOSFET with adequate voltage handling (VDS), adequate current handling (ID), and lower VGS max (<3V3).
perik wrote:
Mon Aug 19, 2019 10:45 pm
I also did put a diode on the electromagnets. I picked a LED for 12 v, I guess that works as good as a ordinary diode? Or how shall I pick correct diode?
No, an LED will NOT work well. You need to clamp the reverse voltage (coming from the coil when the current is turned off) to a lower voltage. Use a standard diode (1N400x series), cathode to +V.
Signature retired

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: 12 v for driving electromagnets PCA9685

Tue Aug 20, 2019 12:23 am

There are plenty of regular (bipolar) transistors that can handle 12-60V, 500-10.000mA devices. You just need to select the most appropriate option for your purposes.

danjperron
Posts: 3391
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 12 v for driving electromagnets PCA9685

Tue Aug 20, 2019 1:22 am

Yeah the RFP30N06LE is now obsolete.

Check your electronic part provider. Mouser, Digikey or Newark in Canada have parametric search.

Maybe the IRL2703PBF could be a good replacement part.

perik
Posts: 28
Joined: Sat May 10, 2014 3:12 pm

Re: 12 v for driving electromagnets PCA9685

Tue Aug 20, 2019 10:46 pm

Thanks. I now switched to a 1N4001 diode which blocks up to 50 v. That looks correct right?

Some questions reagarding finding the right MOSFET:
is this correct:
- Vgs - Gate-Source Voltage = Voltage for turning the gate off, if the voltage goes above this no voltage is passing through the MOSFET
- Vgs th - Gate-Source Threshold Voltage ? Voltage for open the gate, if the voltage goes above this voltage is aloud to pass through the MOSFET
- Vds - Drain-Source Breakdown Voltage = maximum voltage between drain and source

Anyways I will go for this one as recommended:
IRL2703PBF

I created my own MOSFET module by simply took the schematics from the IRF520 module and replaced the IRF520 mosfet with IRL2703PBF. The resistors in the module are at 1K. I think it would work? Please tell my if I am wrong.

Since the sketch got a bit messy I attach a closeup of the MOSFET module (here is the schematics for the IRF520 module http://hawking.stealing-fire.com/IFR520 ... ematic.png)
elektromagneter12v_module.png
elektromagneter12v_module.png (5.68 KiB) Viewed 665 times
New full sketch:
elektromagneter12v_3_.png
elektromagneter12v_3_.png (103.01 KiB) Viewed 665 times
Thanks a lot!

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: 12 v for driving electromagnets PCA9685

Tue Aug 20, 2019 10:54 pm

Why would you put a diode between the ground and line wire?
Even if it's only operating at 12V, if it ever gets to a certain voltage, the diode will short the circuit.

Also make sure you have the base, collector and emitter connected correctly.

danjperron
Posts: 3391
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 12 v for driving electromagnets PCA9685

Tue Aug 20, 2019 11:05 pm

The diode is needed to kill the back emf but it needs to be inverted. Cathode on V+ , Anode to drain.

When you remove the power on the coil it will create inverse voltage and the diode will kill it. Otherwise you risk the chance to burn your mosfet.

ProDigit
Posts: 374
Joined: Tue Aug 30, 2011 1:24 am

Re: 12 v for driving electromagnets PCA9685

Tue Aug 20, 2019 11:32 pm

I don't know if it's a good idea to just let that current go to ground, without any load on?
Maybe a small resistor in series with the Diode?

danjperron
Posts: 3391
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 12 v for driving electromagnets PCA9685

Wed Aug 21, 2019 1:30 am

I don't know if it's a good idea to just let that current go to ground, without any load on?
Maybe a small resistor in series with the Diode?
What will be the maximum current on the coil? What is the frequency of you PWM ? What will be the inductance of the coil.

The 1N4004 is able to handle 30A one shot. No need to put a resistor in series.

Sometimes a resistor in series is added not to protect the diode but to increase the de-magnetization.
https://www.allaboutcircuits.com/textbo ... -circuits/

User avatar
davidcoton
Posts: 4019
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: 12 v for driving electromagnets PCA9685

Wed Aug 21, 2019 8:33 am

ProDigit wrote:
Tue Aug 20, 2019 10:54 pm
Why would you put a diode between the ground and line wire?
Even if it's only operating at 12V, if it ever gets to a certain voltage, the diode will short the circuit.

Also make sure you have the base, collector and emitter connected correctly.
The diode I think you are referring to is an LED (with resistor built in) to indicate 12V is present.
EDIT The diode is for back EMF protection, when the electromagnet is turned off. It is currently shown the WRONG WAY ROUND (corrected in later posts).
MOSFETs have gate, drain and source, not base, collector and emitter.
Last edited by davidcoton on Wed Aug 21, 2019 5:06 pm, edited 1 time in total.
Signature retired

perik
Posts: 28
Joined: Sat May 10, 2014 3:12 pm

Re: 12 v for driving electromagnets PCA9685

Wed Aug 21, 2019 9:37 am

danjperron wrote:
Tue Aug 20, 2019 11:05 pm
The diode is needed to kill the back emf but it needs to be inverted. Cathode on V+ , Anode to drain.
hmm. yes you are right, I have now changed that.
https://en.wikipedia.org/wiki/Flyback_diode

I also read this article about MOVs vs diods.
https://progeny.co.uk/back-emf-suppression/
ProDigit wrote:
Tue Aug 20, 2019 10:54 pm
Also make sure you have the base, collector and emitter connected correctly.
Hmm, I think I have connected the gate, drain and source correctly?
danjperron wrote:
Wed Aug 21, 2019 1:30 am
What will be the maximum current on the coil? What is the frequency of you PWM ? What will be the inductance of the coil.

The 1N4004 is able to handle 30A one shot. No need to put a resistor in series.

https://www.allaboutcircuits.com/textbo ... -circuits/
Im not sure about how to calculate the maximim current and the inductance on the coil. Sorry ...
Regarding the frequency Im mostly been programming arduino where I control the PWM 0-255 where 255 is always on and 0 always off. I want to have this range here as well.

I go for the 1N4004 then ...

Do you think this circuit is ready for run with the components:
1 x Rasperry pi 3 (or 4)
1 x PCA9685

And per electromagnet:
2 x 1k resistor
1 led 12 v
1 mosfet IRL2703PBF
1 diode 1N4004


Another concern is the heating with the electromagnet so I might go down in power and drive it with 5v instead. I guess everything would stay the same except for exchanging the 12 v led to a 5 v led instead? Is that correct?

Full project again:
elektromagneter12v_4.png
elektromagneter12v_4.png (100.51 KiB) Viewed 588 times

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

Re: 12 v for driving electromagnets PCA9685

Wed Aug 21, 2019 10:39 am

perik wrote:
Wed Aug 21, 2019 9:37 am
I'm not sure about how to calculate the maximim current and the inductance on the coil. Sorry ...
Calculating the inductance of electromagnets you've wound yourself ... could be difficult!
But having wound them, you may be able to measure it.

The same goes for the maximum current.
But the maximum current is merely the maximum voltage divided by the resistance of the wire you used. Ohm's Law.

When first switched on, current is zero, and rises at the rate given by the volts and the inductance.
As the current rises, more voltage is dropped by the resistance of the coil, and less by the inductance, so the rate of rise tails off, until the current reaches maximum.

When it's switched off, the current tries to drop but the inductance tries to keep it going.
The flyback diode provides a path for the current, so only the resistance of the coil causes the fall in current.
The shape of the current/time curve is exactly the same, just inverted.
And per electromagnet:
...
1 led 12 v
...
There's no such thing as a 12v LED - just an ordinary one with built-in resistor.
Also, you've got it connected across the gate-source, so you want to design it for the drive circuit, not the load.
Another concern is the heating with the electromagnet so I might go down in power and drive it with 5v instead. I guess everything would stay the same except for exchanging the 12 v led to a 5 v led instead? Is that correct?
With the same coil, 5v instead of 12v will reduce the heating by the square of (5/12)
But the magnetic field will also drop

To keep the same magnetic field, you'll have to increase the current by using thicker wire.
Which will bring the heating back up to where it was!

Return to “General discussion”