Arduino AutoShutdown Using 5V DC Relay or MOSFET

I’m learning how to use relays. I understand their basic function and have managed to build a few projects. But I came across an example that uses a relay or MOSFET to Auto Shutdown Arduino and I’m not sure if I’ve understood the circuit correctly.

When I built this project, the Arduino powers off as soon as I release the button!

THIS IS HOW I SEE IT: The relay (which is using NO) is initially LOW, meaning COM and NO are not connected and therefore the Vcc into Arduino’s 5V pin is not going to ground, so the circuit is open. When the button is pressed COM and NO are connected, which closes the circuit, so the Arduino powers up. Code in the Arduino immediately sets the relay signal HIGH which keeps COM and NO connected. After 5 seconds the relay signal is set LOW which opens the circuit again.

AUTO SHUTDOWN USING MOSFET OR RELAY
Arduino Auto Shutdown

  1. Have I understood the circuit correctly?
  2. Why would one use a relay instead of a MOSFET?
  3. I thought it was not advised to power Arduino via the 5V pin. Would this example work using the Vin pin instead?

ilovetofu:
I’m learning how to use relays. I understand their basic function and have managed to build a few projects. But I came across an example that uses a relay or MOSFET to Auto Shutdown Arduino and I’m not sure if I’ve understood the circuit correctly.

My advice is to keep well away from that website! :astonished:

ilovetofu:
3. I thought it was not advised to power Arduino via the 5V pin. Would this example work using the Vin pin instead?

My advice is to forget about powering an Arduino from “Vin” or the “barrel jack”. Powering from the “5V” pin is the proper way to power it. Using the USB connector is second best, has some limitations.

Yes, it (“Vin”) will work for a UNO or similar (Nano, Pro Mini)if you have nothing else connected and using power, but even adding a relay module is likely to get you into trouble as the on-board regulator has very little heatsink and cannot maintain much current.

Self-shutdown circuits are around. What you have stumbled across on that website is extremely misleading. Just forget about it. What is is you really want to do anyway?

My thoughts: 1. Yes, you seem to have understood the circuit correctly (nice job trying to fix your problem yourself before making a post!). Here is what I believe is going on:

(Yes that is Microsoft Paint, I don't care how bad it is, it illustrates the point.)

  1. You can use either a MOSFET or relay, they would both function the same. A relay uses a magnet to pull a switch, requiring power and generating heat over time. A MOSFET is like a more powerful transistor, capable of driving larger currents, possibly generating heat, and it runs on magic smoke and monkeys flipping switches (it actually has to do with how different silicon-based compounds and isotopes conduct power when transfering electrons, but that's too complicated for just this post). I would use a MOSFET, as it would use less power and would make a clicking sound like a relay would!

  2. Well... It depends on what you are doing and your power source. Vin goes in the same way the barrel-jack goes, into the Arduino's power-regulator. The regulator can take from 9-12 volts of power (but just use 9, it's better for it!). The regulator has no way to dissipate heat from extra energy it needs to get rid of or energy it draws too quickly. The 5v pin is meant to be used as an output, and it also supplies power to the Arduino itself. If you apply power through the 5v pin, the Arduino has no power regulator and no protection from surges or fluctuation in current. If you power through 5v, make sure you are putting 5v regulated through the pin, or you may let the magic smoke out of your Arduino!

My question is: what are you doing with this? What is the goal you are shooting for? Where is the exact code you are using, or are you using code from that sketchy site? You seem to have done it correctly, but try increasing the delay before the pin goes to LOW, and make sure that it is HIGH upon startup. The delay may be expiring before you release the button, so maybe set it 10 seconds first and see if that makes a difference. Also remember to check your relay, make sure the pins work with a multi meter or some LED's before you try anything else. Good luck!

Relay Example.png|405x334

Thanks KingDubDub and Paul__B for your input - it's much appreciated.

5V. This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it.

Yet, provided I don't exceed 5.5V on the +5V pin, I believe I can use it to supply the Arduino, but I bear the responsibility of ensuring that it doesn't exceed 6V (ie. using regulated 5V supply).

I think a MOSFET is going to be a more elegant solution than a relay - no clicking sound, less space, less wires. I don't have any specific project for this yet - I'm just learning how to use various components. I was interested in the Auto Shutdown using MOSFET or relay for when I have a specific task to do and once done, have the Arduino shutdown to save power for mobile project.

I found out why the Arduino was switching off when I released the button - I just wasn't holding it in for long enough, so it never reached the code that sets the relay on. Doh! It works as expected now.

When I research and Google MOSFETs, there are so many options all with different model numbers and packages, it's difficult to know which one's to buy/use. Is there a popular MOSFET that's best suited for functioning as a switch? Ideally I need one that has no voltage regulation (ie. 5V I/O) and one that accepts up to 12V input with regulated 5V or 3.3V output. IMO getting the power and voltages right for a project and its various components, is the most difficult part!

@KingDubDub most of the time I use a regulated 9V supply or USB from computer to power the Arduino. For mobile projects I currently use a 5V power bank connected to +5V or Vin.

A mosfet is usually better than a relay because you avoid the relay coil current, and thus save on battery usage. But mosfets can be a bit more complicated to use. An N-channel mosfet would act more like the relay in your circuit, but in order to turn it on, it’s gate has to be brought to a higher voltage than the voltage you’re switching. So to switch 5V, you would need to apply 7-8V to its gate, which the Arduino’s I/O pin can’t do.

So these switches are usually done with P-channel mosfets, which are “Australian” mosfets where everything is upside down and backwards. To turn on a P-channel, you apply a gate voltage which is lower than the voltage you’re switching. This in turn presents a problem because when the power is turned off, all the pins of an Arduino will sink current to ground. So trying to control the gate directly from an I/O pin would leave the mosfet on all the time.

The solution is to use a second transistor to control the gate, a transistor which requires a high output from the Arduino’s I/O pin to turn it on. In the attached circuit, the mosfet is held off by the 100K pullup resistor. It is turned on by pushing the button, which grounds the gate, or by turning on the NPN transistor, which also grounds the gate.

To use a P channel MOS as a switch you have to have the gate (Vgs) negative to the source if it is N channel MOSFET, you have to have its gate voltage (Vgs) higher than the source. If you connect the gate to the source (Vgs=0) it is turned off. For example we have a IRFZ44N which is a “standard” MOSFET and only turns on when Vgs=10V – 20V, however if you look at a SUD50N06-09L it will turn with a Vgs in the 4.5 volt range. That is basically the difference from a normal and a logic level FET. This FET is a 50 Amp 60 Volt with an avalanche rating. To control a FET gate voltage is always referenced to the source regardless if P or N channel. Here is a good application note: https://www.vishay.com/docs/68214/turnonprocess.pdf for additional information go to: https://www.quora.com/What-amount-of-voltage-is-required-to-switch-MOSFET. To use an N channel FET connect the grounds to the drain and the output of the power supply (-) to the source. Connect the gate to the pin of your choice. Then simply place your push button across source an drain. When you push the button the arduino will start, then your code will place a high on the gate. At this point you can let go of the button. Good Luck & Have Fun! Gil