Double Inverter Safe? Correct?

I have a system I am trying to control a system that is activated by a 24v digital input. My system is a 5v system.

First challenge control 24v with 5v.

Well my answer was to throw in a n-channel fet with a couple resistors and bam! I have something. It is inverted but it should work right? (see attached)

Second challenge, this 24v system has different configurations sometimes it is active high and some times it is active low. So I would like to have access to a signal that is inverted so I can just choose which wire to hook up.

Okay so why not just invert the signal again using another fet and a couple resistors? Would this work? (see attached)

You might be wondering why not just invert the signal in software. The reason for this is that I want that in the case that my system loose power (0v into the first FET) the 24v system will receive an inactive input (sometimes high sometimes low depending on the application)

Once again what I was thinking is attached. I call it the Double Inverter but it is kind of like a Darlington pair where I have access to everything. Is this what I want?

Just use a 10K pull down resistor on the gate, then you need only one FET and it is off on an inactive input.

Grumpy_Mike: Just use a 10K pull down resistor on the gate, then you need only one FET and it is off on an inactive input.

Mike I see what you mean with the pull down on the gate. This would allow the gate to drain on a loss of power and not float.

How can I only use one FET? I would still like access to two outputs. The second being the 24v inverse of the first.

How can I only use one FET?

By inverting the controlling signal in software like you said.

Why do you need the second output then?

Grumpy_Mike: By inverting the controlling signal in software like you said.

Okay now that I reread that i see that it is a bit confusing. What I was trying to say is that I don't want to invert in software because I want this device to be more universal, able to work on a 24v active high system or a 24v active low system without any need for software change. Probably just a jumper that can be changed on the board that selects which output gets sent through.

I would say a flipped bit in software is as easy… You could even use a jumper and an input to set it. Heck, even the current output if you make it selectable between pull up or pull down (via a jumper). Simply measure the “output” before you drive it.

septillion: I would say a flipped bit in software is as easy... You could even use a jumper and an input to set it. Heck, even the current output if you make it selectable between pull up or pull down (via a jumper). Simply measure the "output" before you drive it.

Yeh a flipped bit is easy but I don't want to have 2 software versions in the field (assuming that I ever sell any of these things). I really like your first option but I just ran out of GPIO.

Your second option seems interesting. So you are saying to read the pin before I make it an output. Then based on that reading I should know how to drive it?

Yep, assuming the pulled direction is the inactive state. You can simply read which way it’s pulled before driving the pin (aka setting it output);

const byte DrivePin = 5;

bool activeLow;

void setupDrivePin(){
  //if it's pulled high now we know HIGH is the off state, aka it' active low
  activeLow = digitalRead(DrivePin);
  
  //Now really drive the pin in the same way it' pulled
  //IN THIS ORDER! Otherwise the pin might be LOW shortly is it' an active low pin
  digitalWrite(DrivePin, activeLow);
  pinMode(DrivePin, OUTPUT);
}

//uses the saved state. So a x = HIGH will always result in an active output, no matter if it's active high or low
void setDrivePin(int x){
  digitalWrite(DrivePin, activeLow ^ !!x);
}

pull_check.jpg

septillion: Yep, assuming the pulled direction is the inactive state. You can simply read which way it's pulled before driving the pin (aka setting it output);

I like this a lot. Only uses one GPIO and does exactly what I want it to.

One question though. Is it bad to pull a GPIO pin up to 24v?

"Is it bad to pull a GPIO pin up to 24v?"

Very bad.

.

Indeed bad. In the case of 24V for the output, simply connect the pull up on the gate to Vcc of the Arduino and the pull up on the “output” to 24V.