Useless Box Power Management

Hello everybody, :slight_smile:

I am building a Useless Box using an Arduino Nano (for those who don't know what a useless box is, here is an example: Useless Box with Surprises - YouTube).

It is powered by 4x 1.2V AA batteries (4.8V).

My first setup used 2 switches: One "Top switch" controlled by the user & the servomotor arm.
One hidden "Power switch" to power the Arduino board, & the servos, in order to remove power when not being used (to save power).

The issue with this two switch configuration is that although it works well, it is not what I would call the "spirit" of a useless box: if you first have to power it up, that's not very fun !

Here is the above-described setup:

My idea is to modify this setup to only have one switch, on the top of the useless box. The user would close it, and it would distribute power to the setup. When it is opened (by the servomotor), the power should not be interrupted, so that the Arduino board can continue controlling the servomotors, keep its variables in memory, etc..

To do so, I use two new components:

  • 1x OR gate
  • 1x transistor

The switch, closed by the user, now sends a 1 signal to one of the inputs of the OR gate. As a result, its output goes to 1. This output is connected to the grid of the transistor, which controls the power distribution to the Arduino & to the servomotors.

As the switch will be opened by the servomotor, another way of controlling the power is needed, otherwise it would be interrupted: As soon as the Arduino is powered, it will apply a voltage to the other OR gate input, so that if the switch is opened by the servomotor, the state of the transistor remains unchanged:

The setup can now be turned on by the user "mechanically" and turned of by the Arduino "programmatically".

Hereafter is a representation of this improved setup:

The components I used are the following:

OR gate: SN74HCT32
Transistor: IRFB4321PbF

Links to their data sheets:
OR Gate
MOSFET transistor

Now, here is my issue:

I don't get sufficient voltage from the transistor output.

Using a multimeter:

The OR gate outputs 5.11V when it is in its high state (0V when low), the output is connected to the grid of the transistor (this seems fair to me).

I have 3.95 V between the drain and the source. (This seems pretty high to me, as the grid is at 5.11 V).
Drain voltage is 5.11 V.

I only have 1.11 V of power available after the MOSFET (to run the Arduino & the Servos) => It won't work !

Now, I have never been an electronics specialist, and I might have poorly chosen my transistor.

Is it an issue with my setup or is it a transistor issue ? Which one should I use ? Are there alternative setups I could use ?

Your help would be highly appreciated ! Thank you very much !

Greg.

Can you post a circuit diagram of what you're trying to do? That would help a lot.

That MOSFET is probably not a logic level one. Look for IRL types.

Here is a simplified diagram.

Power is applied (by the transistor) if:

  • The switch is closed OR
  • The Arduino sends a signal to keep power on

I didn't represent the rest of the circuit as I believe this is not relevant.

About the Transistor I used, I didn't know this difference between IRF and IRL. Unfortunately mine seems to be IRF (although I'm not sure about what it means). Would my setup work with an IRL MOSFET ?

You need a logic level gate or it won’t switch on. Look for the VGS(th) value, this should be about 2V. Yours is 3-5V, and it’s fully open at about 10V.

In this circuit you also need a p-channel FET, and your part is an n-channel (use those for low side switching). The symbol in your schematic is also for an n-channel FET.

Note that for your p-channel FET it will switch on when the output of the gate is LOW (0V, or -5V VGS). So you will need a NOR instead of OR gate.

This way you will connect the Arduino’s pin to 5V while it is still powered off. That’s a bad idea, and it will kill the pin. Adding a 10k resistor there will protect the clamping diode from burning.

The switch also needs a pull-down resistor (on the side of the OR gate), to make sure the OR gate gets a LOW level signal when the switch is open.

This should do much better (sorry, no suggestions for suitable MOSFET here - do a search on this forum or Digikey):
schematic.png

While the switch is open and the Arduino is off, both inputs of the NOR are pulled low (pin 2 via R2 and R4, pin 3 via R5), and the output is high, switching off the MOSFET. R3 is to limit the current rushing in to charge the gate, protecting the NOR output (usually can not supply more than 10-20 mA, depending on the part).

When the switch closes, the Arduino is still off, but R2 limits the current through the clamping diode to <0.5 mA which is safe, especially as it lasts only a very short time: until the Arduino is powered up. The pin 2 of the NOR is pulled high, the output goes low, and the MOSFET is switched on.

Now you can set the Arduino pin “Arduino_power_signal” to high to keep the power on, even when the switch goes off.

Thank you very much for this detailed answer. :slight_smile:

wvmarle:
You need a logic level gate or it won’t switch on. Look for the VGS(th) value, this should be about 2V. Yours is 3-5V, and it’s fully open at about 10V.

I understand that my lack of voltage comes from the VGS(TH) value: the grid voltage is not high enough to have a full commutation, so I should look for a lower VGS(TH) value. I will buy a new transistor.

wvmarle:
In this circuit you also need a p-channel FET, and your part is an n-channel (use those for low side switching). The symbol in your schematic is also for an n-channel FET.

Note that for your p-channel FET it will switch on when the output of the gate is LOW (0V, or -5V VGS). So you will need a NOR instead of OR gate.

I don’t understand the reason why I should use a P-channel MOSFET + a NOR gate rather than a N-channel MOSFET + a OR gate ?

With a P-channel MOSFET + a NOR gate the low state leaving the NOR gate will allow the current to flow through the transistor.

With a N-channel MOSFET + an OR gate the high state leaving the OR gate will allow the current to flow through the transistor.

From my perspective, given the same inputs (on the logic gate), I should have the same behavior for both cases in terms of output from the transistor, no ?
Obviously I am wrong, but I would appreciate if you could explain to me the reason why using a P channel FET (+ corresponding NOR gate) is the only solution here ?

wvmarle:
This way you will connect the Arduino’s pin to 5V while it is still powered off. That’s a bad idea, and it will kill the pin. Adding a 10k resistor there will protect the clamping diode from burning.

Thank you very much, I will make sure to add a resistor to protect the Arduino’s pin.

wvmarle:
The switch also needs a pull-down resistor (on the side of the OR gate), to make sure the OR gate gets a LOW level signal when the switch is open.

Actually there is already a pull down resistor, which I didn’t draw on my simplified schematic, but thank you. :slight_smile:

wvmarle:
While the switch is open and the Arduino is off, both inputs of the NOR are pulled low (pin 2 via R2 and R4, pin 3 via R5), and the output is high, switching off the MOSFET. R3 is to limit the current rushing in to charge the gate, protecting the NOR output (usually can not supply more than 10-20 mA, depending on the part).

When the switch closes, the Arduino is still off, but R2 limits the current through the clamping diode to <0.5 mA which is safe, especially as it lasts only a very short time: until the Arduino is powered up. The pin 2 of the NOR is pulled high, the output goes low, and the MOSFET is switched on.

Now you can set the Arduino pin “Arduino_power_signal” to high to keep the power on, even when the switch goes off.

That’s exactly the behavior I want to implement. As I said above, I just don’t understand the importance of using a P-channel FET + NOR gate for it to work. I would like to understand the “whole story” before I can order the new parts.

Thank you very much for your help :smiley:

How about you build a bare-bones Arduino (or remove power LED, and probably regulator) and just use sleep mode so it doesn't burn power when not in use? You'd probably need to switch power to the servos with a FET though, IIRC servos have a non-negligible idle current.

DrAzzy:
How about you build a bare-bones Arduino (or remove power LED, and probably regulator) and just use sleep mode so it doesn't burn power when not in use? You'd probably need to switch power to the servos with a FET though, IIRC servos have a non-negligible idle current.

It is true that I could have used the interruptions. :slight_smile:
In fact this project began as a simple quick project , and I didn't want to spend too much time on it, so I chose simplicity, used the Arduino Nano + an additional switch to shut it down.
Recently I changed my mind (actually I will give it as a present so it needs some improvements as compared to the "two switches variant") and decided that it would be better to avoid having this power switch, but I didn't want to do too many modifications to the code / hardware setup, that's why I chose to go for the OR gate + transistor. Plus as you say I would need a transistor to drive the servos anyway, so why not drive the Arduino through the transistor as well.

If I had planned to use the sleep mode from the beginning it would probably have been the best solution, but now that I have something working (except the power management currently under modification), I would prefer sticking to the original design for simplicity.

Thank you for this suggestion anyway, it would indeed make sense !

A p-channel MOSFET (like PNP transistor) is for switching high side (positive line of a battery/power supply).

An n-channel MOSFET (like NPN transistor) is for switching low side (negative line of a battery, GND of a power supply).

Also the gate voltage has to be handled accordingly.

You know a regular useless box turns itself off when the arm retracts? There is always a second, hidden switch.

wvmarle:
A p-channel MOSFET (like PNP transistor) is for switching high side (positive line of a battery/power supply).

An n-channel MOSFET (like NPN transistor) is for switching low side (negative line of a battery, GND of a power supply).

Also the gate voltage has to be handled accordingly.

Thank you very much ! It reminds me of something at school when we were designing logic gates from transistors, now I see what you mean.

So I will buy a new P-Channel FET with a low enough VGS(TH) value, and a NOR gate.

MorganS:
You know a regular useless box turns itself off when the arm retracts? There is always a second, hidden switch.

Indeed, I have seen the schematics of regular useless boxes with two switches (a hidden microswitch inside the box) used to turn off the useless box and reverse the polarity of the motors. Those don’t even need a microcontroller to operate. But I didn’t want the same behavior on each utilisation, so I use a microcontroller + a random function with a certain number of scenarios.

Look for "logic level" MOSFETs. Much more info about this you can find on the sites of Adafruit and Sparkfun. They also have such parts for sale.

wvmarle:
A p-channel MOSFET (like PNP transistor) is for switching high side (positive line of a battery/power supply).

An n-channel MOSFET (like NPN transistor) is for switching low side (negative line of a battery, GND of a power supply).

Also the gate voltage has to be handled accordingly.

One last thing:

I didn’t think about this solution first, but in order to use my OR gate (and avoid buying a new NOR gate), I could also place the transistor (N-channel, but with a low enough VGS(TH) value) on the ground line back to the batteries, no ?

Like this:

Is there a reason to prefer a solution over another ?
I believe this would work as well, and I would only have to replace the transistor.

wvmarle:
Look for “logic level” MOSFETs. Much more info about this you can find on the sites of Adafruit and Sparkfun. They also have such parts for sale.

Thank you for the advice, I will go have a look ! :slight_smile:

N-channel switching is usually used for 'dumb' loads like lamps and motors. The N-channel devices are cheaper/smaller/lighter for the same power handling. (Electrons more mobile than holes in the semiconductor.)

It's not usually used for 'smart' loads like the Arduino. The reason is that the Arduino is connected to so many other things, many of which can provide alternative paths to ground. The Arduino won't be fully switched off if it still has a few buttons or switches connected to ground.

If you design the circuit properly, it can be done but for a one-off where you don't care if the transistor costs $1 more, it's easier to design with the switch on the positive lead from the battery.

MorganS:
N-channel switching is usually used for 'dumb' loads like lamps and motors. The N-channel devices are cheaper/smaller/lighter for the same power handling. (Electrons more mobile than holes in the semiconductor.)

It's not usually used for 'smart' loads like the Arduino. The reason is that the Arduino is connected to so many other things, many of which can provide alternative paths to ground. The Arduino won't be fully switched off if it still has a few buttons or switches connected to ground.

If you design the circuit properly, it can be done but for a one-off where you don't care if the transistor costs $1 more, it's easier to design with the switch on the positive lead from the battery.

That makes sense. Let's avoid wasting power unnecessarily, the pull down resistors in my previous drawing could be an alternative path to the ground.

As you said the components are really cheap (and delivery fees will be by far more expensive than the components), so I will go for a NOR gate + logic level P-channel FET.

Thank you very much everybody for your detailed contributions ! Can't wait to receive the new parts :slight_smile:

MorganS:
you don't care if the transistor costs $1 more, it's easier to design with the switch on the positive lead from the battery.

You can get logic level power MOSFETs at less than that. I paid RMB 0.18 for the IRLML2502TRPBF n-channel, and RMB 0.20 for the IRLML6401 p-channel. Switches 3-4A loads just fine with 3.3V gate. That's a price difference of RMB 0.02 (about USD 0.0033). Minor disadvantage: SOT23 packages.

Why put a sense on the switch?

Does using the switch multiple times mean the machine does multiple things?

Why not put your FET across the switch and,

Arduino powers up, first task, turn on FET to retain power.

Task complete, shut down Arduino, last thing turn off FET.

Daz1712:
Why put a sense on the switch?

Does using the switch multiple times mean the machine does multiple things?

Why not put your FET across the switch and,

Arduino powers up, first task, turn on FET to retain power.

Task complete, shut down Arduino, last thing turn off FET.

Indeed, there is a kind of sequence:

On the first use of the switch, the Arduino does something. On the second use of the switch, it does something else, etc...

I count the number of successive cycles using a variable. I want this variable to be kept in memory (I don't want the Arduino to be turned off immediately after the arm's retraction, to be ready in case the switch is used again).

I could maybe store the variable in the EEPROM memory before shutting down the Arduino, but in this case it would always start from where it was left, which is not what I want. (I want the sequence to begin from the start after a prolonged inactivity = after the Arduino has been powered down following a "long" inactivity).

Two Questions.

Are you using rechargables at 1.2v or drycells at 1.5v?

Did you realise that the Vin you connected the batteries to then runs through a 5v reg, as this will not be high enough?

greg765:
Currently I am using 4x 1.2V batteries (4.8V).

It is indeed well below the 7-12 V specified for the Nano, but so far it seems to work correctly despite this low voltage.

Then use the Vcc pin instead of the Vin/RAW (exact naming varies between boards). That way you bypass the regulator.

Daz1712:
Two Questions.

Are you using rechargables at 1.2v or drycells at 1.5v?

Did you realise that the Vin you connected the batteries to then runs through a 5v reg, as this will not be high enough?

[http://arduino.cc/en/uploads/Main/ArduinoNano30Schematic.pdf]http://arduino.cc/en/uploads/Main/ArduinoNano30Schematic.pdf]http://arduino.cc/en/uploads/Main/ArduinoNano30Schematic.pdf](http://arduino.cc/en/uploads/Main/ArduinoNano30Schematic.pdf)

Currently I am using 4x 1.2V batteries (4.8V).

It is indeed well below the 7-12 V specified for the Nano, but so far it seems to work correctly despite this low voltage.

I limited the voltage because of the Servomotors (2x SG90) which are limited to 4.8V. I could have added a voltage regulator for the servomotors though. Should I ? I mean, knowing that it works with the current power supply, can I continue with this low voltage or should I increase the voltage and add a voltage regulator to power the servomotors ? (I haven’t bought the NOR gate / P-channel MOSFET yet, so I can still add a voltage regulator for the servos if this is necessary).


About the P-channel MOSFET, I’ve seen on Sparkfun the NDP6020P Sparkfun

Datasheet here: Datasheet NDP6020P

VGS(TH) is between -0,4V and -1V.

I believe this one could be used for my project ?

I am now trying to find a NOR gate that matches the NDP6020P.

If I am right, it should have a low-state voltage that is below 3.8V (4.8V - 1V), and a high voltage above 4.4V (4.8V - 0.4V). Is it correct ?

So far, the closest I have found to those requirements is the Texas Instruments CD4001UBE.
Datasheet CD4001UBE

But I think I can find a better one!