MOSFET Switching Problems


I guess I should have been more clear, my apologies. For the project I am doing I plan on having this one power supply power the entire system. I’m trying to make a stand alone garden that plugs into the wall. So he supply would have to power all of my pumps, valves, and sensors as wells as my Photon. I know ill need a 5v linear regulator and now i know i wont need a 12V.

In regard to the board; I have had a feeling that i would eventually need to make the switch. I so far have been just testing everything individually before i start to put it all together. Do you think I should do my entire circuit on the soldered board or just the higher power things?

Now back to the original problem, for the heck of it I tried the above circuit as is and it worked from the jump without the jumper connected to the resistor. When i connected the photon while it was running the valve failed to open and close. So essentially the problem i was having that made me want to come here for support was fixed by the solution you suggested and now that same solution doesn’t work and the original problem works. Any thoughts on why this is acting so strange?



It seems that we have made some progress here. But, just to recap and to make sure I have this right. :wink:

  1. For your project, all your solenoids and pumps require 12V which you will supply with a single 150W 12V power supply.
  2. In addition, you need to power your Photon and that will require a 5V buck regulator (linear or switched, your choice) to reduce the 12V down to 5V.
  3. We agreed that any of the components that draw more than 2A would need to move to a soldered breadboard and those circuits would need solid core wire to carry the higher-current.

I would suggest you move your entire project to the soldered board if you intend to leave it in operation for any significant amount of time. I would also suggest you use consistent colored wires and try to be neat to make troubleshooting and future improvements easier.

As for the weird behavior, I think you need to troubleshoot this in a methodical manner. The first step is to isolate the systems and validate them individually such as the MOSFET circuit and the Photon control lines. Ideally, you can confirm that each is working correctly before you connect them. Then, if you are getting an unexpected result, you may need to make some measurements of what is happening in your circuit. For example, if you could measure the Photon pin that is controlling the MOSFET, you could validate it is delivering the right signals. An oscilloscope is ideal for this as some issues are transient in nature and may not show up on a volt meter.

Sometimes a circuit simulation is helpful. Here is one I created for this circuit (you will need to use Chrome to open this link)

Can you try to collect some more data and let us know what you find?



Chip, Thanks again for such great information. I’lll have to work to further isolate the problem and get back to you as time allows. I have tried previously to wire 4 of these circuits to a soldered board but none of those work, from what i assume is the same problem, and that is what drove me to move back to the bread boards. Ill have to somehow find the problem using some of the tools you’ve provided and then move to the soldered board.

The regulator I am using is linear, L7805CV, I have yet to try and wire it up but it looks simple enough, one in, one out, and a grounding pin. Any tricks of the trade when working with those? Now that i think about it, I have the power shield which has an input for 7 to 20v that it can use to power the board and charge the battery. If i were to go that route should I use a 12V regulator or a 5V, or just wire straight to the power supply (this seems wrong). The only thing that concerns me is the power shield somehow getting overloaded with current and damaging the board.

I am not going to mark this as solved until I figure this out, and report back for others having similar issues.

Thanks again


Before I start wring it up I wanted to post a picture of my diagram. This is the one i plan to build for all of my switching circuits. I want to know if i’m using the decoupling capacitor in the correct way, and i also added the resistor to ground the data pin as @ScruffR suggested. If i were to add a fuse where in the circuit would make the most sense? I would think in-between the load and the MOSFET, is this correct?


Your 220 ohm resistor to ground is probably too small. If R1 is also 220 ohms, the voltage at the MOSFET gate will only be 1.65 volts (half of 3.3 v) when D0 is HIGH. The threshold voltage for your MOSFET is 1 to 2 volts, so it might work for some devices, and not for others. A 10k ohm resistor should be more than adequate to make sure the gate stays low if D0 is in a high impedance state.


To illustrate the meaning of your flyback diode D1 I’d actually move the coil of your solenoid into the main route.
This should also help to see that the polarity of D1 is wrong. Flyback diodes are meant to be blocking in normal mode and only short back the negative EMF that’s produced when the magnetic field collapses.

Also the polarity of your battery is inverted - you got the + pole on GND.


I have made the changes to the circuit per your suggestions. do you think 100nF is enough capacitance for my application? I am slightly confused by your change regarding the flyback diode but after some googling i believe I have it right. Does this look correct?


I have wired up the above circuit and the simple code that I am running to test it. And am still having the problems that led me to open this topic.

When I plug in the power supply I the valve, normally closed, opens but no switching. I have tried the above circuit with and without the 10Kohm, to no avail. When the power supply is unplugged the valve slowly closes. When I measure the drop across the diode it reads ~12v. I feel their is something I am missing. here is the code I am running;

#define valve1 = D0

void setup(){



void loop(){




One thing you definitely need is another delay after digitalWrite(valve1,LOW);


ah good catch, but did not fix my issue


I don’t understand what your problem is. In a post you made 7 days ago, you said, "Grounding the data pin has worked!"So what’s changed since then? Didn’t you have it working at that point?


Sorry for the lack of clarity, as I am just frustrated with this circuit.

Grounding the data pin did work initially, but sparingly. Sometimes I would have to unplug the valve then replug it, then it would switch as intended. Other times it wouldn’t switch at all just be open until I unplugged it. I know that it’s something simple and when I get it ill kick myself for stressing this much about it, but in the moment it sucks.

I feel that every change that is suggested works for a few cycles of turning on and off the power supply and/or the photon, but nothing has working consistently? Is their a set of guidelines i should follow?

Thanks for your help, I don’t know what’d i’d do without this forum.

EDIT: here is a picture of the trouble maker, I spread the components out to try and make sure it was all correct, the power supply plugs into the rails that are second closest to the camera.


This sounds like some kind of hardware problem, I think your setup is ok (as far as I can see). What valve are you using?


If by values you mean the values of the components,

Resistor - 220 ohm
Diode - rated for 12V 5W -1N5349B (and no change when its removed)
N-Channel MOSFET - RFP30N06LE

I’ve been moving the circuit and switching the wires out out to try and avoid any sort of contact problem


Values? I asked about the valve you’re using.


Wow, I completely misread that HAHA. Its this one. I have two and have switch them them out periodically also.


The specs for that valve have this statement: “The valve has a gasket arrangement inside, so there is a minimum pressure requirement of 0.02 Mpa (3 PSI)”. I’m not positive what that means, but I think it means the valve needs to be under a minimum pressure to operate properly. Are you testing it when it’s hooked up to a liquid source with at least that minimum pressure, or are you testing it dry?


Thats correct, I have been running it dry. Even when running it dry I can feel and hear the solenoid switching on and off when I had it working initially. I tried blowing the valve when it was open and it did require a little pressure before allowing air through.


I think you need to test it with the proper water pressure applied to it, in order for the test to be meaningful.


I successfully add a Mosfet to Arduino to control power and speed to 3 x 12v high-speed fans. It should also work just fine for your project even if you don’t need to PWM the power to the 12v pumps.

Just ignore the potentiometer in the Arduino schematic, I didn’t use that, just wire the MOSFET up like you see it on the breadboard and pull the Gate PIN high and you should get power flowing to your 12v motor.