Turning off (not on) LED with Transistor

I'm working on a project with an external battery pack powering a Arduino Nano through USB. I added a switch between the battery and the board that controls the battery (part of the battery pack). The battery pack has a button I have to push to start it. So, I would have to switch on and then push the button to turn it on.

My idea was, why not pushing that button with a transistor on the Arduino – or in other words: close the circuit and open it with the Arduino when it runs. Could that work? Are there any risks I don't see?

I've found a lot of tutorials how to turn something on with a transistor, but not how to turn something off… So, what transistor should I use (I think a PNP, right) and how can I wire it? Thanks a lot for your help.

I think you are asking either for a self-latching power switch circuit or one that uses the microcontroller to latch it? There are several threads on this if you search for "latching power" or "soft power switch" or similar.

The only devicex that cannot turn off are thyristors and triacs

Thanks a lot for the hint, but I don't think I'm looking for that.

The battery pack has a battery management with a display and everything, so I do not want to build the power management by myself.

I just want instead of pressing that (external) button on the battery pack, permanently close that external circuit and open it with the Arduino after the Arduino got power.

Do you have a hint, for what I should search for?

You want to use an external battery that has it's own on switch. You then have another switch that turns the power from the battery pack on to the Arduino.

Once you turn on the battery pack, you want an automatic power to the Arduino using something across the external switch. This can then be turned off via the Arduino.

Is this correct?

Weedpharma

No matter what though the transition to external power should be "glitchless". (?)

I can see a flaw in your plan.

You want the Arduino to turn on the battery, but without the battery already being on what is there to power the Arduino, so that it can turn on the battery?

JohnLincoln: I can see a flaw in your plan.

You want the Arduino to turn on the battery, but without the battery already being on what is there to power the Arduino, so that it can turn on the battery?

jonaskamber: I'm working on a project with an external battery pack [u]powering a Arduino Nano through USB[/u].

You can set an output pin to default high, when the button (switch) is pushed it is pulled low.

Just make sure that the components are rated for the current draw.

Look in the example sketches, there is a sketch called 'Button' under the digital section. It would do exactly what you want. If you want the output reversed, then simply swap the HIGH with LOW for the output.

Basically you are just using a on / off function if I understood your question correctly. As long as your switch is not momentary you will be ok.

My question is... if you are closing the switch on the battery pack permently, and using the Arduino to 'open' a transistor when powered up to turn off the LED. Your battery pack will drain pretty fast if you don't keep the arduino plugged in to keep the LED off when not in use. Is that what you intend?

Taken directly from the example sketch.

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Edit: crap. I shouldn't answer when I'm tired. Hold on, let me see if I can find what you're actually looking for.

Use a PNP transistor, wired through a pull down resistor to ground. When the arduino is off, it will sink current through the gate and allow the LED to be on. Once the arduino powers up you pull the gate high and it will open and not allow current through.

It's at least a starting point. Maybe someone else will chime in, I'm a bit tired and my brain is shutting down. I would make sure you double check that before trying to implement it!

I think you are after this: https://www.pololu.com/product/751

Press a button, power is turned on. When arduino wants to power down, it drives the OFF pin High to turn off the power.