Switching 5V current between two solenoids

Greetings Arduino community, absolute novice here.

I've got two push-pull solenoids that I need to switch the 5V supply between. The way I approached this was by dividing the voltage from I/O pin #2 between the gates of 1 N-Channel MOSFET and 1 P-Channel MOSFET, with this pin toggling between HIGH and LOW every 200 milliseconds. So ideally one of either of the MOSFETs would allow the current through depending on the state of the pin. However, the P-Channel MOSFET seems to be in an "always open" state from what I can tell, and I'm not certain as to why.

Push-pull solenoid: https://www.amazon.com/gp/product/B013DR655A/
N-Channel MOSFET: RFP30N06LE
P-Channel MOSFET: FQP27P06
Resistors: 1k ohm
Diodes: 1N4001

Below is what my setup currently looks like (click to enlarge).

And the very small amount of code:

void setup() {
  pinMode(2, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(2, !digitalRead(2));

  digitalWrite(13, digitalRead(2));

  delay(200);
}

Thanks for any and all assistance.

The easiest thing is two output pins and two N-channel MOSFETs.

And, there's no need to read anything. Just write high & low...

Write high to the 1st relay and low to the 2nd relay.
delay
Write low to the 1st relay and high to the 2nd.
delay
loop

There are other ways to do it (there always are) but that seems like the most straightforward way.

That was my original thought but that wouldn't allow me to use the one 5V pin, correct? I need to switch it between both solenoids as they both need 5V to operate.

The solenoid coils can both have 5V on them. If they need higher current, do not power them from the Arduino 5V pin, you'll take out the 5V regulator, or blow the USB fuse.
Do connect the external supply's Gnd to the Arduino Gnd.

Use two N-channel parts, and two output pins. Which ever one has a high on it's gate will have current sunk thru it's coil to energize the solenoid, just what DVDDoug said.

Gonna make quite a clatter turning on/off 5 times a second.

You could do it with 1 pin by using the first MOSFET as an inverter to drive the 2nd MOSFET.

Hi,
Welcome to the forum.

Please note;
This is not a circuit diagram.


It contains no info on pin labels or component names or types.
It may be good to help assembly, but it provides very little component information

This is a circuit diagram.


Although it is done in CAD, a photograph of a hand drawn circuit is just as good.
It has component and pin labels and shows signal flow.
It takes time to learn a good layout technique, but I suggest you begin drawing circuits of your projects as it helps immensely with project description.

Tom... :slight_smile:

Excellent contributions everyone, thank you kindly for the information. I will give that inverter route a shot.

Be aware that the inverter circuit will ensure that one of them is powered at all times - at start-up Q2 (mislabeled as Q1 in that diagram, the right-hand one should be Q2 - there are two Q1s!) will be on, and K2 will be on.

Using two pins you can have both solenoids off at the same time (or both on at the same time).

Up to you to decide which option works best for your project!

Should be fairly powerful solenoids to actually switch fast enough to make the 0.2 second interval. And indeed quite a noise. You're likely to need an external power supply to make this work well. Saves a lot of power spikes on the Arduino side, too.