Custom project in need of assistance with mosfets

Hey all, I've been over on the AVR forums and thought it might be better to come to the arduino board directly. I'm working on a project and i'm having issues with one small aspect, it won't turn off. so here's the basic points:

P channel Mosfet, Arduino Pin 7 as output to gate, Source to +5V battery, Load to Raspberry Pi. 10K ohm resistor between gate and source.

when battery is turned on, the initial charge powers up the Pi and the arduino gets its power from the Pi USB. (pin 7 stay LOW)

When shutdown on teh Pi is executed, the arduino is suppose to force pin 7 HIGH, and it does, but once the Pi has no power, neither does teh arduino, so the pin goes low again. all of this happens within a msec.

End Goal: to shutdown the Pi and Arduino without using a SPST switch on the battery.

Is this possible? perhaps using a cap to hold the gate for a few seconds?

Thank you

Yes, increasing the series resistor and adding a big cap will hold the voltage up longer.

Try making the pin an input when you want to shut down so it is high impedance instead of pulling the line to high voltage, which becomes low voltage when the FET turns off.

Sounds like you need this:
P channel mosfet with source to +5. drain to devices power pins.
Arduino drives gate, gate also has pullup resistor to +5.
Push button pulls gate low, arduino powers up & holds gate low.
At power off time, arduino drives gate high, power to devices cuts off, resistor holds gate off so power stays off.

Ok, so I see both of you understand my goal, can anyone offer better assistance on how I can actually accomplish this? Is there a formula that can calculate discharge time of the cap in my build? how much higher does the impedance of the gate to source resistor need to be? Am I to understand that it's an either/or process, (ie. either make the resistor higher, OR add a cap). If I use a cap, I would think that 2 seconds should suffice, but I'm not sure, I would have to test this. Also, would changing the gate pin to an input still drive the gate? I'll be home tonight to test, but I thought that changing input to output and vice versa was a bad thing to do in sketches.

I don't think that any solution in involving driving the mosfet gate direct from an Arduino pin will work. The problem is that when the Arduino power is turned off, the pin protection diode in the Arduino will pull the mosfet gate down the the Arduino supply voltage. So powering off the Arduino is bound to turn the Pi on.

I would drive the mosfet via an NPN transistor. Connect emitter to ground, base to Arduino output pin through a 10K resistor, collector to +5v supply (the real one, not the Arduino supply) through 1K. Then connect the mosfet gate to the collector. You will need to set the Arduino output pin high to keep the power on, low to turn it off.

Ok, so leave the Arduino powered up and go into Power Down Sleep Mode.
IO pins stay at levels last commanded, so pin can be written high & wil stay there.
Works best in a real custom project where the regulator, LEDs, USB/Serial interface can actually be turned off.

dc42, thanks, I'm going to give this a shot, standby for a whiteboard to make sure I understand it correctly. Crossroads, I tried that already, but the arduino is powered by the Pi, so it would lose power and go low anyway.

Thanks guys!!

is it a correct assumption dc, that the mosfet source should be direct to the 5V source that is going to the NPN?

Yes, the same as you have it now (to the +5v battery), same for the top end of the 1K pullup resistor. btw you can keep your 10K pullup resistor instead of using my suggested 1k, that will reduce current consumption. The base resistor can then be anything in the range 10K to 100K.

So like this yea?

Yes, that's what I had in mind.

Alright, cool, thanks for the assistance! I'll try to draft it up on a breadboard and post if there are any issues.

Thanks again!