[Answered] Protecting an Arduino from back-powering. Would this circuit work?

BASIC QUESTION:
I’m trying to protect an Arduino board (Adafruit Itsy (5v / 16mHz)) from the possibility its power gets turned off while devices connected to its analog pins remain powered on. Details on why this may happen are below, but I was hoping someone could take a look at this circuit and tell me if it would be effective, or point me in a better direction etc.

DETAILS:
I’m using an Adafruit Itsy-bitsy to to monitor and manage the power for a few external devices (wall wart power, some 5V, some 18V plus USB coming from a Mac Mini). That’s all working fine. Now I realize I need to protect the Arduino in case it gets turned OFF. This is my first effort.

My thought with this circuit is that while the Arduino is powered ON, one of its pins could keep a MOSFET turned on, allowing an external device to be monitored from an analog pin. If the Arduino’s power were to be removed, the pin would stop supplying current/voltage, the MOSFET would turn OFF and the Arduino pin be safe from back-powering (as discussed in Analog input draws current when arduino is turned off)).

It seems to work just fine on a breadboard, but before I startup updating the pcb etc, I was hoping for other opinions etc.

I should mention that eventually there would be 4 or 5 devices given this treatment, each attached to another analog pin on the Arduino.

My questions would be - would the MOSFETs react quickly enough? Would I be better off powering a MOSFET directly from the 9V source that the Arduino uses (although I’m not sure how to best do that with many devices)?

A simplified circuit png is attached (I hope!).

Thank you in advance for any wisdom imparted in my direction.

WHY THE ARDUINO’S POWER MAY BE INADVERTENTLY TURNED OFF:
This device will be used in an orchestra pit of a Broadway show that I work on. Many departments are in charge of turning power on and off, which they do often, during a typical work / performance day (Lighting, Sound, Electrics etc). It’s also not uncommon for workers to be ferreting around my station while troubleshooting or updating various systems throughout the theater. So the possibility of a wall wart or power plug being inadvertently disconnected is not remote. Even the ‘always on’ power should be interpreted as ‘always on - in theory’. I’m just trying to be prepared for any eventuality.

Apologies, attached corrected schematic (A4 pin label now attached to correct Arduino pin)

I don't understand your post. Please explain what it is that you are monitoring via the analog inputs (voltage levels, AC/DC, etc.) and how you are doing it. The schematic diagram is unclear.

How, exactly, is the MOSFET supposed to prevent back powering?

Note that current flow into the analog input of a powered down Arduino can be reduced to a safe level simply by using a series resistor (10K-100K depending on the voltage). However such a situation is to be avoided if at all possible.

Make the values of the voltage divider(s) much higher, and the problem disappears.
Not a problem to make that divider 100k:220k or even 1Megohm:2.2Megohm.
Just add a 100n capacitor from analogue pin to ground, to stop possible cross-talk between analogue inputs.
A double-read might also be needed.

Another option is to drop the voltage with a divider to <=0.5volt,
and read the analogue inputs with 1.1volt Aref enabled.
Leo…

I don't see how the mosfet protects A4.

High value resistors would probably work. But another approach would be to have the power sources being monitored each drive a cheap NPN transistor that grounds an Arduino pin with internal pullup resistor enabled. If power to the Arduino is turned off, its pins are still just grounded, which doesn't hurt anything. Of course that only tells you if the monitored supply is on or off.

Whatever you connect to an Arduino analog input, have it instead connect to the anode of a diode whose cathode goes to the Arduino 5 V line, and the cathode of another diode with anode to ground, and a 2k2 resistor from that point to the actual Arduino analog input. This prevents any current greater than 250 µA feeding into the protection diode.

Wow, amazing. Thank you so much for your responses and advice. I really appreciate it.

I won't be able to respond properly until Monday (called away unexpectedly from this project).

Until then ... p

Greetings:

Looking at my schematic again after a few days with fresh eyes I can clearly see why it won’t work as I had hoped. Thank you for helping me see that.

I should mention that the only information I need to monitor from the various power sources is their ON or OFF state. They are currently connected to analog inputs only because of the development process I went through, I could easily just use the analog input as digital, or reroute the power sources to actual digital inputs if and when I redo the pcb boards. I somehow edited that out of my original question.

In thinking it through, I realize I got as far as switching off power to an LED (D1) when power was removed from the Arduino. The next step would be somehow substituting the Arduino’s analog input for the LED.

As to the responses I’ve gotten so far:

@jremington, @Wawa and @ShermanP - Thank you for the push towards resistor based solutions. I’ve definitely read much about them, and your reinforcement really helps me trust that path.

@ShermanP - NPN transistor - yes!!! I’d like to ask more about that. Separate post is coming.

@Paul__B : I’m fascinated by that diode idea as well - I haven’t yet used them very much, but I did buy a bunch of 1N914 and 1N4148 diodes when I built a few MIDI circuits a few months ago - are those the types I should use? I have a tentative grasp of Zeners and Schottkys, but I’ve never designed a circuit with them. And Digikey shows 50,000 results for ‘diode’, so I have a lot of reading to do.

I was also wondering if a relay could be placed between the incoming 5V and the arduino analog input, with the input - would a solid state relay be fast enough to be effective (turn off the incoming 5V DC before it hits the analog pin if the arduino is turned off)? I’ve never used one, so the finer points in the data sheet are a bit beyond my current reach.

I found this on Digi-Key: TLP222AF

Or this one on Mouser: AQY282EH

As to other solutions I have seen around the web, here’s one where the Vcc that powers the Arduino is also split off to the gate of a MOSFET, the incoming 5V goes to the Drain and the Source goes to an analog input of the Arduino. example, Majenko’s answer found here: analog input draws current when arduino is turned off

Because I will eventually have 4 or 5 analog inputs to protect, and not being sure how to properly split the incoming Arduino 9V power in so many ways, I was hoping to use Arduino pins to control the gates of the MOSFETs, as is suggested here by none other than the Bald Engineer (answer #4): arduino pins contolling gates of a transistor

I’ve also tried researching High-Side Switching circuits, but they always seem to be paired with P-Channel MOSFETS, and the logic is inverted (I need Gate HIGH, MOSFET ON). But I do remember reading somewhere that one could drive the P-Channel’s gate with another MOSFET to invert the logic. That’s when my brain started to overload, a sign the solution was not the most elegant one.

Anyway, this continues to be a useful teaching moment for me. Thank you all for your generous help with that. When I arrive at a solution that works best for my situation, I’ll post the details.

Many thanks, p

@ShermanP

…But another approach would be to have the power sources being monitored each drive a cheap NPN transistor that grounds an Arduino pin with internal pullup resistor enabled. If power to the Arduino is turned off, its pins are still just grounded, which doesn’t hurt anything. Of course that only tells you if the monitored supply is on or off…

Yes in fact I do just need to monitor just the ON or OFF state of the supply devices, so this is very enticing to me!! I’d love to think this through, and try to get my noob-ish brain wrapped around the details.

By ‘driving an NPN transistor’, do you mean connect the monitored source directly to the transistor’s Base? And by ‘grounding an Arduino pin’ do you mean connecting the pin to the transistor’s Collector, and connecting the Emitter to Ground?

Or am I getting this all backwards …

I have a handful of NPN’s just waiting for their moment of glory. (mostly PN2222A NPN’s from Adafruit - #756 - PN2222A datasheet)

I’m doing more reading and trying to figure out data sheets and watching you tube videos … I’ll eventually get this right.

Thanks again,
p <

@jremington

... Please explain what it is that you are monitoring via the analog inputs (voltage levels, AC/DC, etc.) ...

Apologies for the lack of clarity as to the kind of voltages being monitored. I need to keep track of the state of DC devices running on power adaptor 'wall-wart' style 5V 2A.

I only need to know their ON or OFF state.

paul_crescendo:
@ShermanP
Yes in fact I do just need to monitor just the ON or OFF state of the supply devices, so this is very enticing to me!! I’d love to think this through, and try to get my noob-ish brain wrapped around the details.

By ‘driving an NPN transistor’, do you mean connect the monitored source directly to the transistor’s Base? And by ‘grounding an Arduino pin’ do you mean connecting the pin to the transistor’s Collector, and connecting the Emitter to Ground?

Or am I getting this all backwards …

I have a handful of NPN’s just waiting for their moment of glory. (mostly PN2222A NPN’s from Adafruit - #756 - PN2222A datasheet)

I’m doing more reading and trying to figure out data sheets and watching you tube videos … I’ll eventually get this right.

Thanks again,
p <

You would connect the monitored supply to the NPN base through a resistor, maybe 100K. The NPN collector would be connected to the Arduino I/O pin you are using, which would need to have its internal pullup resistor enabled. The NPN emitter would be connected to ground.

If the monitored supply is off for some reason while the Arduino is on, then no current would flow through the transistor, and the internal pullup resistor would pull the I/O pin high.

If the monitored supply is on, it will turn on the transistor, which will ground the I/O pin. So a low on that pin is what you would hope to read.

If the monitored supply is on, but the Arduino has been turned off, then the transistor will ground the I/O pin, but that doesn’t cause any problem.

So the transistor either grounds the I/O pin, or doesn’t, but in no case does it send positive voltage from the monitored supply to the I/O pin - unless the transistor fails in some strange way, which it won’t.

I should say that I’m assuming here that the grounds of the Arduino and all the monitored supplies are connected in common. If that’s not true, then you may have to switch to optocouplers to do this.

So you would need to have an NPN transistor and a resistor for each supply you are monitoring. The PN2222 would work fine. Really, any small NPN would work fine.

@ShermanP - thank you for the explanation.

I actually had a breadboard wired up that way, thanks to your initial reply, but found myself hesitating to power it up. Great to have confirmation that it would work. Which it did.

This solution seems very workable to me. And I even understand the theory better now that some hardware is in place. It's a beautiful thing ...

I'm glad it worked. I think it's a pretty robust solution that can't harm your Arduino. Just be careful about dealing with all of the power supply gounds involved. Don't just assume you can connect them all together.

@ShermanP

Just be careful about dealing with all of the power supply gounds involved. Don't just assume you can connect them all together.

Would you mind expanding that thought ... I think it might help me with another issue I'm having with this same project.

This might be more suited for a separate thread (which I'm preparing), I just always assumed that with MOSFETs (and transistors) the 'load' being switched had to share the ground with whatever was driving the gate (or base).

Yes, the grounds need to be shared for your system to work, but if they are all shared, then they are all connected together. If all of them are floating supplies, not referenced back to Earth ground, then there typically should be no problem connecting them. And of course they may already be connected through cable shields, etc. But it depends on how the supplies are generated. At this point someone who is a trained EE needs to explain more about this, but one test I sometimes run is to use my voltmeter to see if there is any potential between the two grounds I'm about to connect. Usually there isn't, so connecting them is not a problem. You just don't want large currents to flow when you connnect two grounds together.

If this is an issue, even potentially, the solutipn would be to use optocouplers such as the 4N25. The two sides of the optocoupler are not electrically connected at all, not even their grounds, but you can still tell if the power is on or off.