variable electromagnet

Hi I'm starting a project where I need to be able to vary the strength of an electromagnet. I've been trying hard to do some research and have been seeing transistors, mosfit, relay, all kinds of things that I'm really not too familiar with. Much of the information I've found on this topic tends to be for a switch set up but I want to be able to control it for not just on/off but all strength levels in between.

I'm thinking I will want to run anywhere from 0-3 or 4 amps through a maybe 4-8ohm resistance solenoid. Probably will use 20 or 22 awg magnet wire and maybe a 11.1v or 14.8v lipo battery.(these can change just ballpark)

Also I was confused by some of these setups because they would have a diode one way but I want to be able to run the solenoid both ways to allow to switch North and south poles. I thought maybe this would work with a dc motor driver but I talked to a guy on the phone of a place online that said they run on pwm which isn't what I'm looking for(although I did see something from a comment online that said you could use pwm but it may not have been a reputable source so idk) and to look for a solenoid driver. I wasn't able to find anything like that though.

but im thinking I need to be able to reduce the current through the solenoid to adjust the strength which could be from something like a potentiometer to increase the resistance(reduce the current) or something to lower the voltage(lower the current)

Any suggestions? Thanks!

The part about moving it 'both ways' by changing polarity would require the solenoid to be a permanent magnet instead of just a ferrous material. What I mean is, current direction doesn't change solenoid direction in most cases, so re-evaluate what it is you want to accomplish. Most solenoids have a spring that works as the return, the current just works against the spring. Same thing at work in speakers, come to think of it.

Oh my bad I should've been more clear Im going to wind my own electromagnets over a soft iron core. so theres no spring or anything like that and depending on which way I send the current thought the coil that will make the left north and the right south and visa versa. So its not your typical "solenoid valve" thing you initially think of. Which is why I'm having trouble finding a ton of material on this

You can use PWM to vary the strength of an electromagnet. And, a motor driver will work with PWM "both ways".

I'm thinking I will want to run anywhere from 0-3 or 4 amps through a maybe 4-8ohm resistance solenoid. Probably will use 20 or 22 awg magnet

Have you done this before? Have you researched the Ohms per foot (or per meter) for 20/24 AWG wire? ...That's at least couple-thousand feet of wire!

Ya it is a lot but I think its not actually as much as it sounds like. I made a program with a servo and a light detector whatever its called to count the turns and I think ill get it made alright. Ok I was thinking that was my best option but I called SparkFun and the guy was pretty adamant that it wouldn't work and pwm will not do well for this.

This is the motor driver I was looking at SparkFun Monster Moto Shield - DEV-10182 - SparkFun Electronics

And if its doing a lower speed lower pwm does that take less power from the battery to allow it to last longer or is it the same no matter what pulse.

Also since its pulse I think it would be sending the max current that the battery would do for the pulses like lets say 14.8V battery, 4ohm electromagnet, 3.7Amps. It would be sending 3.7A not all moments as opposed to like 14.8V with current reduced somehow to a continuous 2A. Would these get the coil equally as hot? Would they each allow for efficient battery life

Also I know the pwm is like really fast but this wouldn't cause and vibration or non smooth jolts would it? May be pretty unnoticeable but idk

Also just side thought would there be any benefit or cost to dividing the electromagnet into two and putting one in each port or will that not do anything. I guess it would mean a lower voltage battery. Not sure if thats good or not or doesn't matter

@Jordanar / @learn24, stop cross-posting.