Two Arduinos hooked up to one mosfet

I've been trying to get this to work for a while. I have two separate arduinos that I need to both interface with one mosfet (so as to control the same item). Arduino 1 is an Uno with an ethernet shield running this code.

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,167);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

int LEDpin = 4;
String readString = String(30);
String state = String(3);

void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  
  //Sets the LEDpin as an output
  pinMode(LEDpin,OUTPUT);
  
  digitalWrite(LEDpin,LOW);
  state = "OFF";
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply

        if (readString.length() < 30) {
          readString.concat(c);
        }

        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          int LED = readString.indexOf("LED=");

          if (readString.substring(LED,LED+5) == "LED=T") {
            digitalWrite(LEDpin,HIGH);
            state = "ON";
          }
          else if (readString.substring(LED,LED+5) == "LED=F") {
            digitalWrite(LEDpin,LOW);
            state = "OFF";
          } 
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.print("LED is ");
          client.print(state);
          client.print("

");
          
          if (state == "ON") {
            client.println("<a href=\"./?LED=F\">Turn Off<a>");
          }
          else {
            client.println("<a href=\"./?LED=T\">Turn On<a>");
          }
          
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    readString = "";
    // close the connection:
    client.stop();
  }
}

Arduino 2 is also an uno, an I'm going to use code something like this. (Not finalized yet)

/* This code is made to function like an alarm. Due to not wanting to use the Time library it has been made using a simple delay function, while this is not optimal since I must start it at a specific time and it uses all of the time it will work fine due to the low cost of Arduinos. 
The program will need to be started at 12:00 exactly in order for the alarm to go off at the right time. 
The alarm functions by turning on a mosfet so as to allow for current to flow, with this a 150 watt LED is powered, thus turning on the lights to as to wake me up. 

*/


int led = 13;
long hour = 3600000;
long minute = 60 * second
int second = 1000

void setup() {                
  pinMode(mosfet, OUTPUT);     
}


void loop() {
  digitalWrite(mosfet, LOW);    //turn the mosfet off [12:00 AM]
  delay(hour * 12);               // wait 12 hours (This program would be started at 12:00)
  digitalWrite(mosfet, HIGH);   // turn the mosfet on [12:00 PM]
  delay(minute * 10);               // wait for 10 minutes to make sure I'm awake 
  digitalWrite(mosfet, LOW);       //turn the mosfet off now that I have woken up [12:10 PM]
  delay(minute * 50);            //delay for another 50 minutes to get it back on the hour [1:00 PM]
  delay(hour * 11);            //wait another 11 hours [12:00 AM]
}

I thought I could get this to work by just tying the two output pins together in parallel so that they both connect the the mosfet to switch the mosfet on or off, but I can't seem to get that to work. The one with the Ethernet shield seems to "override" the signal from the other one.

Any suggestions?

Suggestion: Diode OR'ing - each output should go through a diode, anode to Arduino out, join the cathodes at the FET gate.

Tying two Arduino pins together with one HIGH and the other LOW will kill the pins.

What you want is an OR gate.

Ok, so I guess I'm lucky that all of the pins are still fully functional. :wink: So would a 2 diodes work or should I find a OR gate chip?

I would not have suggested "2 diodes" knowing that it wouldn't work.
It's done all the time.

http://www.allaboutcircuits.com/vol_3/chpt_3/10.html
[link added]

scaru:
Ok, so I guess I'm lucky that all of the pins are still fully functional. :wink:

Try putting in a multimeter and see how much current flows... (let us know!)

@Runaway Pancake, thanks. I'll do that, I'm guessing I would want to use a Schottky Diode?

@fungus, I think I'm gonna pass on that one...

A couple of possible snags to look out for with this method.

  1. There would need to be a pull-down resistor wired from the FET gate to ground for the case of when both arduino output pins are low, otherwise the FET gate would 'see' a floating input state and would not reliably turn off or be slow to turn off when desired.

  2. Some 'logic level' FET gate voltage full turn on voltage specification may be marginal with the gate voltage having to go through the diode which causes a small voltage drop.

But it can be made to work in principle.

Lefty

scaru:
@Runaway Pancake, thanks. I'll do that, I'm guessing I would want to use a Schottky Diode?

Every little bit helps, I suppose.
Depends on the FET you're using, its ID vs. VGS characteristic. Could be no big deal either way.

retrolefty:

[quote author=Runaway Pancake link=topic=170613.msg1268534#msg1268534 date=1370522365]
Suggestion: Diode OR'ing - each output should go through a diode, anode to Arduino out, join the cathodes at the FET gate.

A couple of possible snags to look out for with this method.

  1. There would need to be a pull-down resistor wired from the FET gate to ground for the case of when both arduino output pins are low, otherwise the FET gate would 'see' a floating input state and would not reliably turn off or be slow to turn off when desired.
    [/quote]

There ought to be one there anyway.
If we talk about shoes do we err if we don't mention laces (too)?

There ought to be one there anyway.
If we talk about shoes do we err if we don't mention laces (too)?

[/quote]

Well not all shoes use laces. :wink:

I can't tell you how many circuit drawing posted I've seen on this site using FETs where there is not a pull-down gate resistor or a series current limiting gate resistor which is also recommended depending of the gate capacitance of the specific FET in question, but it's a lot. So I don't think I was in error or being too obvious by mentioning it in context with this posting.

Lefty

It can be done in software. If you make sure you never have one of the pins configured as OUTPUT when it's LOW.

Dangerous, though.

TanHadron:
It can be done in software. If you make sure you never have one of the pins configured as OUTPUT when it's LOW.

Dangerous, though.

Maybe doable if both pins were on the same Arduino. If they're on different Arduinos then you'd have to sync them together.

...and there's a thought.

Why not have one Arduino control the MOSFET let the other one signal when it wants the MOSFET on.

Arduino A -> Arduino B -> MOSFET.

All you need is an output pin on (A), an input pin on (B) and you can do the rest in software.

scaru:
@fungus, I think I'm gonna pass on that one...

Oh, go on, I'd love to know the amps between two pins.

You've already been doing it for ages ... a few more seconds won't hurt. :slight_smile:

Not sure why you would have to sync them. You might need a pull-down resistor, but as long as they're both configured INPUT, the pins should be tri-stated and there wouldn't be a problem. When either one or both gets turned on HIGH on the output, it triggers the mosfet. What would be the problem?

fungus:

TanHadron:
It can be done in software. If you make sure you never have one of the pins configured as OUTPUT when it's LOW.

Dangerous, though.

Maybe doable if both pins were on the same Arduino. If they're on different Arduinos then you'd have to sync them together.

...and there's a thought.

Why not have one Arduino control the MOSFET let the other one signal when it wants the MOSFET on.

Arduino A -> Arduino B -> MOSFET.

All you need is an output pin on (A), an input pin on (B) and you can do the rest in software.

By any chance can you (or someone else) explain exactly how I would do that?

Pull-up on the gate. The pins are used as open-collectors which gives them two states: INPUT, OUTPUT LOW. pinMode is the only function used to change the state of the pin / control the transistor.

Or, pull-down on the gate. The pins are used as open-emitters which gives them three states: INPUT, INPUT w/ PULLUP, OUTPUT HIGH. As long as the pin is correctly transitioned there is never a problem (INPUT to INPUT w/ PULLUP to OUTPUT HIGH to set HIGH, OUTPUT HIGH to INPUT w/ PULLUP to INPUT to set LOW).

The only extra hardware is a pull-up or pull-down resistor which should be present anyway.

As a bonus, the transistor state can be read by the processor not trying to control the transistor.

Plan B;-

USE Dual-gate MOSFET, one for one and no fight. This is a way overkill plan.

Plan C;-

Add one more mosfet, now share the load, one for one and no fight.

Has anybody mentioned that a logic level MOSFET probably should be used?

sonnyyu:
Plan C;-

Add one more mosfet, now share the load, one for one and no fight.

I actually like that method, mosfets are pretty cheap and using two to perform the OR'ing directy is viable.

Lefty