Arduino power on/off using MOSFET

Thread Starter

circuitdiver

Joined Nov 13, 2020
18
I've successfully used an Arduino to replace my car factory stereo with a MP3 player. The problem I have now is that I want to power down the external amplifier before the MCU turns off. Originally I had it powered using the car's accessory line (controlled by the ignition switch). I have the accessory line going through a power converter circuit to reduce the voltage to 9V and clean up the signal.

So to have a "shutdown" process, I believe I need to instead using the constant 12V line to the battery and use the accessory line to signal a power on & shutdown. When accessory voltage is high, turn on the MCU; when the accessory voltage is low, the MCU can read that and begin a shut down process (which will include powering down the amplifier first).

I think MOSFETs are the solution, and I'm looking at something like this: https://circuitjournal.com/arduino-auto-power-off
My primary power souce will be the car battery (constant, not the accessory) converted down to 9V. Both share the same ground.

How can I integrate the accessory line into a circuit like this?

Thanks.
 

Cozendey

Joined Mar 9, 2021
12
I think, in this case, the simplest option would be to pass the car's accessory line through an additional transistor controlled by an Arduino pin.

This way, the power on sequence would be: Arduino is turned on, then Arduino turns on the accessory line, and at shutdown the accessory line is turned off by Arduino and then Arduino turns itself off.

Keep in mind that the circuit you linked to needs that the user keep the button pressed until Arduino boots up. There's this other circuit, that resembles that one, but instantly latches on, even before the MCU boots up (the video shows an ESP32, but the circuit for Arduino is the same):
 

Thread Starter

circuitdiver

Joined Nov 13, 2020
18
Thanks Cozendey, this video is great! A few follow up questions:

This circuit in the video is using 3.3v. will it work with 5v or 9v?

Since the accessory line is 12v, is there a particular type of transistor that you'd recommend? I thought that I would have to use a relay there, or maybe another mosfet.

I'd like the stereo to be powered by that constant 12v from the battery, but turned on when the accessory line goes high. It seems like the simplest solution there is to replace the switch in that circuit with the accessory line. Would that also involve a relay or mosfet?
 

Thread Starter

circuitdiver

Joined Nov 13, 2020
18
My schematic so far is below. The problem I'm having now is in the orange box at the top (it's incomplete). The issue is that the TIP120 would have to be on the high side because the amp is far away and has it's own ground wire. Everything shares the same ground (the car chassis). Would a reed relay be better here and can I use a relay if the ground is shared? Another factor is that the car batter could have spikes above 12V, which isn't a problem for the amp, but could be a problem if were creating a high side switch that required negative voltage.
schematic1.png
 

Cozendey

Joined Mar 9, 2021
12
I think you might consider eliminating the 2N3904, and use any power transistor that can be driven directly by the Arduino.
If you keep the 2N3904, you might consider increasing the pull-up resistor, because the AMP is competing for current with it, since they become parallel.
 

Cozendey

Joined Mar 9, 2021
12
I think you might consider eliminating the 2N3904, and use any power transistor that can be driven directly by the Arduino.
If you keep the 2N3904, you might consider increasing the pull-up resistor, because the AMP is competing for current with it, since they become parallel.
Looking at it again, I see the gate-source voltage might not be enough to drive the mosfet directly.
 
Last edited:

Cozendey

Joined Mar 9, 2021
12
Looking at it again, I see the gate-source voltage might not be enough to drive the mosfet directly.
In other words, I think you might eliminate the 2N3904, and use a power transistor where, even with the 5V to 12V gate/source difference, it will be enough to make it conduct.
 

Thread Starter

circuitdiver

Joined Nov 13, 2020
18
My knowledge of transistors is limited, but I'm trying to learn. Is the TIP125 an example of a power transistor? All of the example circuits that I see using that still having another transistor (such as 2N3904). Also, this probably isn't clear in my diagram, but the 12V going to the AMP in this circuit is not powering the amp, it's just turning it on (the amp using a remote wire to turn on/off). The amp has it's own heavy guage wire connected directly to the battery for power.
 

Cozendey

Joined Mar 9, 2021
12
My knowledge of transistors is limited, but I'm trying to learn. Is the TIP125 an example of a power transistor? All of the example circuits that I see using that still having another transistor (such as 2N3904). Also, this probably isn't clear in my diagram, but the 12V going to the AMP in this circuit is not powering the amp, it's just turning it on (the amp using a remote wire to turn on/off). The amp has it's own heavy guage wire connected directly to the battery for power.
I think the best way would indeed use the circuit you posted (with a BJT and a Mosfet) and just consider if a higher pullup resistor should be used. Because the pull-up is also working as a voltage divider. Even when the BJT conducts, the 12v will be over the pull-up resistor and not over Arduino. Since the BJT depends only on current to conduct, the 5v from Arduino won't matter. The Mosfet, on the other hand, will depend only on voltage, even if only minimal current is being spent on its gate.
 

Cozendey

Joined Mar 9, 2021
12
I think it can work. It's really a matter of energy efficiency. I would start with 10M (or the highest resistor you easily have available) and go down from there until it's just enough to pull-up the MOSFET and also leave plenty of current in the AMP side.
 

Thread Starter

circuitdiver

Joined Nov 13, 2020
18
Okay, I finally had time to breadboard the auto power off circuit today and I can't get it to work. Pictures are attached. I hope they are clear enough to see what's going on. In the pictures, the barrel jack is connected to a 5V wall power supply, the button is never pressed and it's aways 5V. Red wire coming off of the board would go to Arduino VIN, blue wire coming off the board would go to the latch off pin, and the yellow wire coming off the board would go to the status pin. I was expecting it to be 0V until the button is pressed, then remain at 5V until pressed again.

I was able to use the same components to get the other power off circuit to work (referenced in the original post), but I'd prefer your circuit because auto latches.
20210313_140015.jpg

20210313_140032.jpg

20210313_140054.jpg
 

sghioto

Joined Dec 31, 2017
2,395
It is for detecting if the user presses the button a second time so that the Arduino will power off the circuit.
OK. I edited the schematic above in post #16 to include an isolation diode on the switch.
It's possible the status pin on the Arduino may have a low enough impedance when not powered up to switch the mosfet.
 

Thread Starter

circuitdiver

Joined Nov 13, 2020
18
sghioto, I believe the 10K resistor that was removed closes that part of the circuit and is necessary for the self latching feature that I'm trying to accomplish. Without it, wouldn't the latch pin have to stay high in order to work? With the changes you've made, it more closely resembles the circuit here: https://circuitjournal.com/arduino-auto-power-off.

For the other part of the circuit, thank you for fixing the 2N3904.
 
Top