Electromagnets controlled by esp32 (pwm) and mosfets, problem with voltage drops and esp not working for high pwm values

Hey guys,

I’m in some dire need for some help.

Ive build up the following circuit (for part 1 of the question without magnet 3 & 4).

It does work as intended, as I use a pwm-signal form the esp32 pins, to set an specified voltage for the irlz44n, and therefore a specified current for the electromagnets 1 and 2.

But this only works kind of for every magnet on its own.

In this table if measured the voltages. Why is there so much variance? The mt3608 produce quite stable voltages, the magnets with their corresponding mosfets are all in parallel..

Voltage Magnet 1 Duty Value Magnet 2 0 100 175 250
Duty Value Magnet 1
100 1,5 1,6 1,1 0,6
175 4,2 3,8 3,1 2
250 7 6,9 6,8 6,4
Voltage Magnet 2 Duty Value Magnet 1 0 100 175 250
Duty Value Magnet 2
100 2,2 2,2 1,8 1,1
175 4,8 4,5 4 3
250 7,9 7,8 7,6 7,2

The maybe even bigger problem: i need to have two electromagnets per one mosfet. I tried this, and then the voltage of the magets broke completely down. After long testing I found out, that the esp32 seems to struggle. Its currently reading html (its controlled by another eps via webserver), then applies the values to the output pins and then waits for 5secs. It has one bright led-flash every 5 secs.

If I have 2 magnets per mosfet connected, it seems to struggle, and flashes bright every second. The voltage for the magnets goes up from 0 to 1/2V and immediately goes down to 0.

I dont understand, why there is so much voltage drop, and why the esp32 seems to fail.
Im stressed out :frowning:

You need a MOSFET that has a specified maximum Rds(on) at 3.3V or less.

Also NEVER connect batteries in parallel

1 Like

Hey, thanks for the answer.

As far as i understood, the irlz44n isnt the optimal choice, yes, but it should work?
I could set a driver, to eliminate this problem, right?

Why shouldnt i? I need the bigger capacity, while have a convinient way of charging?

I think that you have found out that is not true.

I could set a driver, to eliminate this problem, right?

Yes

1 Like

There is nothing to stop one battery from discharging into the other and that could lead to a very dangerous situation.
Charging in parallel is even worse.

Hm, well i that case i need to review on this topic again.. thanks for the heads up

Just like no two MOSFETs will have the same Rds(on) no two batteries will have the same internal resistance and that will cause them to charge and discharge at different rates.
Will the magnets work on 7.4V (3.7 x 2)?

If you are planning on using (discharging the 2S 7.4V battery) at the same time as charging, you need a lot more circuit components. See the following video https://youtu.be/T70mBHeIOZA?si=2RUgcwpZMmzxMMMw
Obviously you will need more than a 5V charger. NEVER put 18650's in parallel without a BMS.

After reviewing your schematic and the datasheet, I’ve identified several issues. The most significant problem lies in your gate circuit.

  1. The 10k resistor should be connected to the port pin, not directly to the gate. It is costing you about 0.25V on the gate voltage.
  2. The gate resistor value should be around 25 ohms. While this adjustment might get your circuit working, it will still be borderline since the MOSFET is not being fully enhanced.

To improve the design, consider using a logic buffer. Since 5V is available, you could use an HCT device such as the 74HCT04. Parallel two gates to drive the MOSFET gate, and use a third gate to invert the ESP signal. This configuration will provide additional gate drive and bring the voltage above the 4V required, as stated in the Vishay datasheet.

Remember, the Vgs value listed in the datasheet is a threshold voltage, not the voltage needed for optimal operation. Refer to the datasheet graphs or text to determine the proper gate drive voltage for your specific MOSFET.

Having trouble setting the mosfet driver up, since this is not really working..
The transistors are BC337.
The voltages of the magnets are lower then before, gate to drain are mere 2V..

The 10K resistors need to be 1K and connected to 9V not 5V
The 1K resistors connected to the base should be about 330.
The transistors will invert the signal so the PWM will be backwards.

Batteries should not be in parallel

1 Like

Ignore the misinformed comments about batteries in parallel. That is a common configuration in commercial battery packs, and not the problem with your setup.

Most likely the electromagnet power supply and switching circuitry cannot handle the required current draw, especially the second schematic. What is the coil resistance?

2 Likes

Okay, so now it works as it did before, since i have voltage drops, when i have both outputpins on high pwm-values.
with this circuit i got high voltages with high pwm values, dont i?

hm, it should not be a problem. the magnets have like 60ohms, so like 150mA, in total about 600mA.

That should have been stated in your first post.

No just the oppsite
Again batteries sould NEVER be put in parallel.

Did you change the resistor values?
Connect the collector resistor to 9V?
What is the PWM frwquency? It cannot be to high or it will not work.

Yes i did, both. But as stated, with high pwm values i got higher magnet-voltages. For one magnet at 250 pwm=> 7V. Both magnets at 250pwm= around 3-4V per magnet..

ah, okay, could try a lower one

I keep looking at this thread, hoping to see something about what the OP is trying to do with the electromagnets. Nothing yet. All magnetism is current related and electromagnets have a core material, probably ferromagnetic. The material has a permeability which limits how quickly the material can be magnetized. Using pulsed DC will cause a phase shift between the voltage applied and the current applied. So a voltage registered by a volt meter will not give a true measure of the current/magnetism of the electromagnet.

2 Likes