Arduino voltages go crazy with MOSFET in circuit - am I using it wrong?

Hi,

I am trying to make a circuit where my Arduino nano can power itself off using a MOSFET as a low-side switch, as can be seen here:

(link to the schematic)

VCC/GND is a custom PSU with adjustable voltage (normally 7V). The idea here is that the Arduino boots up, immediately sets pin D2 to High, which in turn opens the MOSFET gate, and allows the power to Arduino (the initial boot-up is done with a button or by touching wires, not important right now). Then, under certain conditions, Arduino sets the D2 to LOW, which closes the MOSFET, and turns off the Arduino.

Right now the code is simple... Just setting the D2 as Output, and then setting it to High. Nothing else.

The problem is that for whatever reason, Arduino outputs 6V on the D2 pin, indicating that something is very, very wrong here. No pin should ever output more than 5V. If I increase the voltage on my PSU, the voltage from D2 pin also goes way up, reaching as high as 7 or 8 volts... Of course I shut everything down before any damage could occur.

I thought the voltage regulator onboard Arduino is broken, so I tried several more Arduinos, as well as other MOSFETS (suspecting that the diode is broken and allows backflow), but I always get the same result. It does look like a backflow through the GND pin, but I have no idea what could be causing it. Even if I disconnect D2 from MOSFET gate, the D2 still outputs 6V.

What is going on here?

Well, there just isn’t any way you can low side switch power, in this context. End of discussion. Next topic.

You’re measuring your own 7 volt supply. With no ground, everything is 7 volts above ground and back feeding through one of the pin ESD diodes somewhere. Every pin has a diode from the pin to vcc and another to gnd.

Time for a high side switch.

WattsThat:
Well, there just isn’t any way you can low side switch power, in this context. End of discussion. Next topic.

You’re measuring your own 7 volt supply. With no ground, everything is 7 volts above ground and back feeding through one of the pin ESD diodes somewhere. Every pin has a diode from the pin to vcc and another to gnd.

Time for a high side switch.

Thank you for your answer, but could you please elaborate why can't I use a low side switch here? I am quite new to electronics, but I just don't understand why it wouldn't be possible.

Have a look at the image below. The diodes from the pin (Pxn) to vcc and to ground are there for ESD protection.

When you open the ground (or vcc) pin of the AVR processor, any other pin with a valid logic level can and will become a current path through the ESD protection diodes - which result in the processor being powered though those diodes. This is referred to has phantom powering and it significantly complicates low power designs that attempt to place the processor in an unpowered state. It’s just not possible when the i/o pins contain valid i/o levels.

In general, you need to use high side switching of the power to both the processor and the i/o supplies in order to power down the device.

You’ll find many examples of what you tried to do here on this website with similar stories to yours. Phantom powering is something gets novices quite confused because you cannot see the diodes, they don’t appear on schematics and it is very easy to think the processor has an internal short or some other failure when there is absolutely nothing wrong with the device.

Well, there are a couple of problems. Or a few.

Firstly, your diagram seems a bit odd to me - or us if we include WattsThat and all the others.

It has only three connections. What use is an Arduino Nano with only three connections? What is is supposed to do? Sit there and flash its LED? That does not sound very useful.

Hang on! Maybe you want to connect other things to it. Well, that means you would have to connect all their grounds to the low-side switch too. That may be tricky, as they may have their power supplies grounded to the same ground as yours, so the low-side switch will simply be shorted out.

Going back to just the three connections, if your FET attempted to turn off, then the voltage across the Nano would drop to zero, so the GND would pull up to 7 V (and more about that later!). This means the D2 will also pull up to 7 V - but wait! That means the FET is turned on, so you cannot have the FET turned off.

If you really want your Arduino - a Pro Mini (because if you are using the USB connection on a Nano, then turning it off is nonsensical) - then you need two transistors or FETs, a PNP (P-channel) and an NPN (N-channel). And if you have those, it makes sense to use the "P" device to high-side switch as the "N" device which connects to ground, turns it on.

But that said, putting the ATmega to sleep should be just as effective without any extra components.

Hmm, I now see WattsThat has more to say ...

Perhaps this thread can help with a solution, I’m sure there are many other possibilities.

Lots of info on lowering power consumption using sleep mode:

http://www.gammon.com.au/power

An external switch that can be turned of with an i/o pin. It must control all power to the i/o pins in order to prevent phantom powering of the processor.

When you set D2 to 0 you are connecting it to 0V. 0V comes from the drain of the MOSFET connected to ground. The MOSFET turns off, D2 is no longer connected to 0V so D2 cannot keep the MOSFET off. As the only power connection to the Arduino is now to Vin then the only voltage that can possibly appear on D2 is the Vin voltage, whatever that is. That voltage turns the MOSFET back on.

Thank you very much for taking the time to explain how this works, guys. I understand it now. Indeed, it is rather confusing for a newbie like myself, but it kind of makes sense. I suppose I'll have to go with a high-side switch like in the examples you provided. I also found a similar tutorial here. Might be useful for others as well.

I know my initial schematic didn't reveal what is the purpose of this turn-off feature - it is a part of a larger project, an autonomous Arduino robot powered by a single cell LiPo battery. Since discharging LiPo is dangerous, I want my robot to shut off automatically if the battery voltage drops too low. Sure, I could use sleep modes to suspend ATmega, but there will be more devices connected directly to the battery (or through a boost converter, including the Arduino, since it cannot run on 4.2V that a single LiPo cell provides), so the sleep mode wouldn't turn off these devices and they would continue discharging the LiPo. Which is why I needed a way to break the whole circuit. I though that a low-side switch with a MOSFET would make more sense here, considering how many devices there will be in this circuit, but I guess I'll have to make do with a high-side switch.

laukejas:
What is going on here?

This is an old problem - many threads exist on this.

There is no way to auto-power switch a CMOS logic chip like this without using multiple
active semiconductor devices, either 2 transistors, 2 FETs, 2 logic gates, opto-isolator.
Simply impossible, trust me, due to the lack of isolation in a semiconductor switching
device, and the fact they are all voltage inverting.

Generally, to prevent over-discharge of the battery, you use a battery protector module (which uses vow-voltage FETs).

Since most of the logic is CMOS, each of the attached devices really should use no power when not active.

A 3.3 V 8 MHz Pro Mini - with regulator and pilot LED removed - will run just fine on 4.2 V.

Boost converters are interesting. They have a "disable" input but it merely shuts off the boost function so that the output voltage becomes the same as the input.

I know my initial schematic didn't reveal what is the purpose of this turn-off feature.

One of the problems of asking questions on here is deciding whether to post your entire project, which is helpful in that the rest of us can see what you are doing and might be able to offer useful advice beyond what your immediate problem, but then makes for an awful lot to read through, or post the minimum that exhibits the unwanted behaviour as you did, in which case it's difficult to offer more general advice.

I have a UPS system in my house to keep the lights on when there's a power cut. It has a 50V power supply, a 50V 12Ah lead acid battery and an inverter. Originally it had no control, so if the mains when off it would discharge the battery completely if left alone. Lead acid batteries can withstand some abuse so I wasn't too concerned. LiPos are a lot more fussy. I did however build a control system that disconnects the load if the batteries become too much discharged and I then had your problem. After some experimenting I realised that once the load was disconnected there was enough charge in the batteries to keep the controller running for ages before that would need to be disconnected too. As a result I have a phased disconnection, the last thing to be disconnected is the controller. As has been commented by others, this cannot be done with 1 transistor of any kind, my control circuit uses 2 MOSFETs.

I hope that helps a bit.

Paul__B:
Generally, to prevent over-discharge of the battery, you use a battery protector module (which uses vow-voltage FETs).

Since most of the logic is CMOS, each of the attached devices really should use no power when not active.

A 3.3 V 8 MHz Pro Mini - with regulator and pilot LED removed - will run just fine on 4.2 V.

Boost converters are interesting. They have a "disable" input but it merely shuts off the boost function so that the output voltage becomes the same as the input.

I think I know what kind of battery protector module you're talking about, and I did consider it, but turns out, it takes up way too much space in my robot (it is very small, 12x10 cm). So I thought I could integrate that functionality myself, since I still have one I/O pin for switching the MOSFET, and one analog I/O pin for measuring voltage (before the boost converter, of course).

Maybe I'll try the Pro Mini next time, but I have a bunch of Nanos lying around, so I designed my circuit around it specifically. That mini USB port is very convenient for uploading new code to the robot once it's complete.

PerryBebbington:
One of the problems of asking questions on here is deciding whether to post your entire project, which is helpful in that the rest of us can see what you are doing and might be able to offer useful advice beyond what your immediate problem, but then makes for an awful lot to read through, or post the minimum that exhibits the unwanted behaviour as you did, in which case it's difficult to offer more general advice.

I have a UPS system in my house to keep the lights on when there's a power cut. It has a 50V power supply, a 50V 12Ah lead acid battery and an inverter. Originally it had no control, so if the mains when off it would discharge the battery completely if left alone. Lead acid batteries can withstand some abuse so I wasn't too concerned. LiPos are a lot more fussy. I did however build a control system that disconnects the load if the batteries become too much discharged and I then had your problem. After some experimenting I realised that once the load was disconnected there was enough charge in the batteries to keep the controller running for ages before that would need to be disconnected too. As a result I have a phased disconnection, the last thing to be disconnected is the controller. As has been commented by others, this cannot be done with 1 transistor of any kind, my control circuit uses 2 MOSFETs.

I hope that helps a bit.

I know!! Still, I thought I'd take the challenges on at the time, which is why I described just a specific part of my project that I can't get to work. Besides, in my experience, telling too much about the project often results in derailed topic, as people start pointing out problems/suggestions about other parts of that project, then some people get into arguments, and in the end, I still don't have the answer to the original question :smiley: So I'm trying to keep it simple.

I will try this setup with 2 MOSFETs, or a MOSFET and a BJT. Not sure which is better, some examples feature 2 MOSFETs, while others have one MOSFET and one BJT. I guess both would work.

I will try this setup with 2 MOSFETs, or a MOSFET and a BJT.

2 MOSFETs, no argument there. BJTs are current operated devices and therefore need current to work. A MOSFET, correctly wired, uses as close to no current, and therefore power, as makes no difference. That's why all processors are full of MOSFETs, not BJTs, that's how they achieve such low consumption while in sleep mode, and not a huge amount more while doing stuff.

I've not done it for my UPS but another step you can take is to take advantage of sleep mode and maybe wake the processor every 30 seconds to check if power is available.

PerryBebbington:
2 MOSFETs, no argument there. BJTs are current operated devices and therefore need current to work. A MOSFET, correctly wired, uses as close to no current, and therefore power, as makes no difference. That's why all processors are full of MOSFETs, not BJTs, that's how they achieve such low consumption while in sleep mode, and not a huge amount more while doing stuff.

I've not done it for my UPS but another step you can take is to take advantage of sleep mode and maybe wake the processor every 30 seconds to check if power is available.

Thanks for explaining it. So I guess this example is not the best one, since it suggest using BJTs, right?

My intention is very similar to what you suggested. I plan to program my robot so that it goes to sleep when there's nothing to do (no human activity around it), and wakes up regularly to check it's surroundings, as well as the battery state. I have a separate switch to disconnect everything from the battery EXCEPT the Arduino, so that no device would draw the power during Arduino's sleep mode. I know that most CMOS devices should not draw power when not doing anything, but my tests show that some of them still draw a few miliAmps, so I think it would be safest to shut them down via another switch, just to be sure. The lower the battery, the less frequently the robot will wake up, to extend the lifetime to maximum. If the LiPo hits 3.5V, which is the lowest safe boundary (with some margin, of course), it will shut itself down permanently via this MOSFET switch that I asked about in this topic. Sort of a last resort in case I forget to charge it.

laukejas:
I think I know what kind of battery protector module you're talking about, and I did consider it, but turns out, it takes up way too much space in my robot (it is very small, 12x10 cm).

What? You mean you cannot fit this:

Paul__B:
What? You mean you cannot fit this:

Oh, sorry, I thought you meant one of these...

What is the model number of that device you linked to? I can't seem to find a datasheet for it.

P.S. Also, is it possible to adjust the voltage of the over-discharge sensor? It says "Overdischarge detection voltage: 2.45±0.1V", but I'd like to have that detection at 3.5V.

laukejas:
Oh, sorry, I thought you meant one of these...

No way. There are a lot of small protection/ charge boards for one, two or more cells. That is the one that goes on the end of a 18450 but there are many little square ones supposedly rated at 3 A. Search term was "battery protection board".

Fixed your link above.

laukejas:
What is the model number of that device you linked to? I can't seem to find a datasheet for it.

The image suggests it is a "HX-1S"

laukejas:
P.S. Also, is it possible to adjust the voltage of the over-discharge sensor? It says "Overdischarge detection voltage: 2.45±0.1V", but I'd like to have that detection at 3.5V.

Don't know. Would need to identify the IC. (One chip is IC, one is FET.)

Paul__B:
No way. There are a lot of small protection/ charge boards for one, two or more cells. That is the one that goes on the end of a 18450 but there are many little square ones supposedly rated at 3 A. Search term was “battery protection board”.

Fixed your link above.
The image suggests it is a “HX-1S”
Don’t know. Would need to identify the IC. (One chip is IC, one is FET.)

Okay, thank you, I will investigate this option.

Back at the MOSFET switch solution, now I’m thinking, if I’ll make a high-side switch, won’t the MOSFET create a voltage drop, reducing the efficiency of the setup?

laukejas:
Back at the MOSFET switch solution, now I’m thinking, if I’ll make a high-side switch, won’t the MOSFET create a voltage drop, reducing the efficiency of the setup?

Yes, as would a low-side switch if that was actually a realistic option. Which is why simply putting things to sleep is better.

But these FETs have far better performance than bipolar transistors.