I'm doing arduino project where I use small battery as power suply and it need to last long time. I'm thinking to make latch power ciruit like this one latching-power-switch-circuit-auto-power-off-circuit, but I wonder can I use that button as input for arduino when ciruit is powered up and what kinda output it would give for me?
Yes.
Once the arduino is "On" the subsequent press of the button can be sensed by an input pin: digital or analog. Probably through a 1K or so resistor, just because.
Use a digital input pin, not analog, for multiple functions based on timing. But remember, turning off is an issue unless you sense a long-press and then wait until button release. (If still depressed, it would turn back on!)
The problem is that if you use the same button to power down the arduino that you used to power it up, you are going to complete the power circuit with the button while it is closed keeping power on to the board.
No, I'm not going to use that same button directly powering down the board. as in the schematic arduino can shutdown itself. I'm thinking if I user press the button more than 5s arduino is going to put that pin to 0v so it's shutdown.
this looks promising, but I don't understand well how diodes work, so can you explain what kind voltage does arduino get to it's input pin when button is not pressed and when it's pressed?
I have done simulation and I don't understand how does arduino can read from that "Input" pin It says there isn't anything after that diode. Even when pressing button it doesn't change it's state
Is that mosfet P-Channel Enhancement Type MOSFET or P-Channel Depletion-type MOSFET.
The mosfet is enhancement mode. An NDP6020P would be perfect, but they aren't made anymore, so I don't know where you would find one. A diode blocks current from flowing in one direction, but permits it to flow in the other direction, but with a 0.6V drop across the diode.
You would use the pinMode() function in Arduino to set the input pin to INPUT_PULLUP. That connects an internal resistor of about 35K from the pin to the 5V power rail. Then that pin would be at 5V, and would read high. When the button is pressed, current would flow through the diode, bringing the input pin down to about 0.6V, which you would read as low. You would check the status of that pin in your loop(), so you would detect when the button has been pressed. Or released.
The output pin you would digitalWrite() as high, which turns on the NPN transistor, which in turn will continue to ground the mosfet gate when the button is released. You would do this very early in your sketch code. Then when you are ready to power down, you would change the output pin to low, and the mosfet would turn off.
The diodes would be 1N4148, which is the standard signal diode. The NPN could be a 2N3904, or 2N2222, or anything similar.