My perf board for a solenoid valve controller

I want to control this solenoid in 2 ways:

  1. Time-controlled sketch (ie 5 seconds on, 5 seconds off, etc)

  2. Manual override with a button

So I've got the timed control option working with this sketch posted below. The diagram is here:

soleperfdiagram.jpg

and here is the image

My question is about the manual override button. The idea is that it will close a path from the 9V battery pack through the button, down to 220Ohm resistor towards the mosfet gate. However there is an alternate path which is towards the arduino pin and through the 10kO resistor to ground. It probably wont go through the 10kO resistor having a 220O option, but what about the arduino pin?

NOTE: The red pen connections on the diagram are made underneath the perf board.

int gatePin = 3;  // connection to mosfet gate
int ledPin = 13;
void setup() {
  pinMode(gatePin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  delay(5000);
  // Open solenoid by sending voltage to pin3
  digitalWrite(ledPin,HIGH);
  digitalWrite(gatePin,HIGH);

  delay(5000);
  // Close solenoid by sending low
  digitalWrite(ledPin,LOW);
  digitalWrite(gatePin,LOW);
}

Part number ?

The mosfet is a IRLB8721, the solenoid is a 12V being run off a 12V lead acid battery. The arduino is run from a 9V battery pack.

What are the specs for the solenoid ?

The idea is that it will close a path from the 9V battery pack through the button, down to 220Ohm resistor towards the mosfet gate. However there is an alternate path which is towards the arduino pin and through the 10kO resistor to ground. It probably wont go through the 10kO resistor having a 220O option, but what about the arduino pin?

Can you just draw a schematic on a sheet of printer paper and post a photo ?

Ok here it is on fritzing:

Just to reiterate, my question is; Since I want to operate the gate at the mosfet from a time-controlled sketch that opens and closes the gate every so often, but I want to add a manual override button, would the correct way to do it be to add that push button switch in that way?

Hi,
No that switch is going to connect a controller output to your 5V supply, that is not good.
You will need to do some diode switching at the MOSFET gate so you can use the arduino output and the bypass switch in parallel.

Your bypass wants to turn the solenoid ON I presume?

Tom... :slight_smile:

You mean like this:

Define "Manual Override button"

Exactly what does it do ? (ie: does it turn it ON when it was OFF or turn it OFF when it was ON or BOTH ?)
Is it MOMENTARY (until you release you finger) or is it a toggle on/off ?)

You will need to do some diode switching at the MOSFET gate so you can use the arduino output and the bypass switch in parallel.

I believe what TomGeorge means is insert a diode from the GPIO pin to the gate resistors and use the push button to pull the gate low. (at least that's my guess)

The manual override would be used to open and close the valve manually. Of course, thats not what you meant, I see...I guess if I try to connect it to the gate, it would have to remain pressed to hold the valve open, which would be uncomfortable. It might be better to just have the button press run a method to hold it open manually for about 5 seconds and then close it. In that case the button would just need to call another method that pulled the existing digital pin high for 5 seconds instead of just waiting for the sketch to run through its normal cycle. but that sounds easy enough to do.

What I meant was actually to have the button open the gate/valve while pressed and close it when let go.

What I meant was actually to have the button open the gate/valve while pressed and close it when let go.

Just connect the button as a pullup to 5V on the mosfet gate. When you press the button , it shorts the gate to 5V and opens the valve until you release it.

I thought that's what I was doing in the diagram on post #4. I connected the button to that 3-way junction but I'm worried it'll affect the D3 pin circuit?

Marciokoko:
I'm worried it'll affect the D3 pin circuit?

It will.
If D3 is LOW and you hit the p.b. (pushbutton), applying 5V there... you can figure out the rest.
A heavy-duty toggle (or p.b.) between FET drain and Gnd would turn it on.
Writing your sketch to poll for your p.b. input (manual/test) is another option.

Actually I can't figure it out. What would happen if d3 is low and I send 5v to it? Will it make current flow into the pin and ruin the board?

Ok so if that happens, then I need to check of the button is pressed then set d3 to high?

I thought that's what I was doing in the diagram on post #4. I connected the button to that 3-way junction but I'm worried it'll affect the D3 pin circuit?

D3 doesn't have a current limiting resistor in series in that schematic. (see Tom's schematic in the following post)

Hi,
This should help...

Tom... :slight_smile:

I would need a diode that will have a peak inverse voltage of 5V? What about maximum forward current, 40mA?

I can't answer for TomGeorge but I can tell you for a fact that any schematic that simply shows a diode with no further clarification or specifications is intended to mean a 1n4001 silicon diode. If it were germanium or something smaller like a 1n4148, the part number 1N4148 would be given. If it were larger, like a 1n4007 , the part number would be given. If it were a SCHOTTKY diode, the schottky diode part number would be given, as there are many different ones. The fact that no part number is given tells you that a garden variety 1N4001 will work fine. Of course Tom will have to confirm that but that's my conclusion as someone with 35 years electronics experience. I think I would probably bet money I'm right about that.

Hi,
D1 and D2 can be 1N4148 preferably or 1N4001 or 002 or 004 or 007.
D3 can be 1N4004 or 007.

I keep a strip each of 1N4148 (x100) and 1N4007 (x100) diodes, forget 1N4001 etc, waste of space when 1N4007 will do the job.

Tom...... :slight_smile:

I can picture you wearing them like a 50 Cal ammo belt...