digitalWrite() state when powered off

Psykokwak

Member
Hi all,
I need to control a device that has a wire.
  • If the wire is not connected (open drain), the device is OFF.
  • If the wire is put to its GND, the device is ON.

So, I configure as the following :
Code:
#define PIN 4
void setup() {
  digitalWrite(PIN, HIGH); // Turn off the device
  pinMode(PIN, OUTPUT_OPENDRAIN); // Set the pin as output opendrain
}

void enableDevice(bool on) {
  digitalWrite(PIN, !on);
}

it works like a charm. But... When the Teensy module is powered off, it puts its "PIN" to almost GND. So my device turns on :(

The question is : Is there a way to change this behaviour ?!

Thanks.
 
You could put a FET like a BS170 between the Teensy and your device under control. The FET when off will have a very high resistance. This will reverse the logic in your program as the FET will invert the signal.

Wire the Drain pin of the FET to your device, wire the Source pin of the FET to ground, wire the Gate pin of the FET to the Teensy pin, pin 4 in your example.

Edit: and you would not want pin mode open drain in your program.
 
But... When the Teensy module is powered off, it puts its "PIN" to almost GND. So my device turns on :(

The question is : Is there a way to change this behaviour ?!

Thanks.
The reason this happens is protection diodes on the chip (nearly all CMOS devices use these to prevent ESD damage) such diodes clamp all the signals to ground when powered down, by about 0.6V (a diode-drop) - using an external FET or BJT is one method to solve your problem, an opto-isolater is another.
 
Thanks for these information.
I already bought some BS170. I hope they will do the job as the it has a high Vgs.
 
The BS170 is a 12V MOSFET, its unlikely to work from 3.3V - I'd simply use a 2N2222 or similar BJT for this kind of duty as BJTs can be used from any voltage given a suitable base resistor.
However it might be an idea to identify the current draw from the "device" and what bandwidth you are expecting (I assume low if you switching it on and off, but its best to be sure about this).
 
I dont know the current draw by the device but it should be quite low. I tried with a digital output (max 4mA ?) from the teensy.
And the switching is very low too. Something like 1 switch per week in normal operation. Let says maximum 1 switch per second.
 
Then any low-side switching approach should work, FET, BJT, relay, opto-isolator... Just make sure that the polarity will be what you want for the powered-down condition.
 
Back
Top