arduino power switch with a push button...

I will first say that im not good at this stuff, ill try my best to understand and im happy to learn, but please do might i might not know what you mean.

I'm trying to create a single push button to power on the arduino with a 5v input.
I would like it to work like so:

  1. Push the button once and it turns on the arduino, and stays on when you let go.
  2. Puch and hold the button for (3-5 seconds) and the arduino shuts off.

Now i did something like this with 5v relays but sadly they are to weak to hold the connection when you drop it or hit it softly, so im thinking i need to replace it with a transistor.

The idea here is that once you press the button it will apply voltage to the transistor and make a GND connection.
Once the arduino is powered on it will apply power to the D8 pin, allowing you to let go of the button while it remains on.

So at this point it powers itself, now hold the button for a few seconds and with the help of a bit of code i can detect that on D10, and that will stop power on D8.
Then when you let got of the button is shuts off.

The issue here is that last part, where it will only turn off when you let go of the button, i would like it to turn off recardless of you still holding the button.

Also i tried to build this and it spontaneously combusted, so im doing something wrong.

I appreciate every bit of help at this point because i don't really understand all this, and that makes googling it a bit hard, Thank you.

I might be able to use a relay for the turn off part, if I use the nc part to hold the connection, it wont switch if I hit hit.

Then i just need to power the relay at the same time and stopping power on D2 allowing it to shutdown.

What relay do you have?

What switch do you have?

What transistors do you have?

You only want to use one switch?

larryd:
What relay do you have?

  • srd-05vdc-sl-c
    What switch do you have?
  • some cheap 30 cents button
    What transistors do you have?
    -none right now :stuck_out_tongue: but some npn one is needed i think
    You only want to use one switch?
  • yes

Edit
Corrected schematic.

Im not sure what im looking at here, can you explane?

Closing S1 applies +5V to top of the relay through D1, transistor Q1 turns on via D2 to 5 volts from S1.

Relay picks, contact 4 to 8 closes providing alternative power for the top of the relay and the Arduino 5 volt pin.

The Arduino pin D2 applies 5V (HIGH) through D4, an alternative turn on voltage for Q1.

Opening S1 applies 0V to Arduino pin D3 through R2 10K.

Later, after closing S1 for ~3 seconds, then opening S1 causes a timer to expire, dropping voltage on Arduino pin D2 to 0 Volts (LOW).

Transistor turns off, relay drops, contacts 4 to 8 open removing power from Arduino.