Pages: [1] 2   Go Down
Author Topic: Auto Power Off - not working :(  (Read 3540 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I've tried a couple of ways to make Arduino cut power through a digital pin.
The first is based on a PNP (push button to start power, then digital pin set LOW to maintain it, set HIGH to cut).


The second is based on an NPN (push button to start power, then digital pin set HIGH to maintain it, set LOW to cut).


In both cases, if I don't connect the digital pin, pushing on the button, power goes on. But if I connect the pin, power goes on immediately.
Is it something related to the fact that, by default, pins are INPUT? Please help, do you have any suggetion?
Thanks!
« Last Edit: May 15, 2012, 04:35:51 am by ArJack » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need more than an Arduino to do anything like this. You need some code on the Arduino. If that code isn't working properly, and you want help to fix it, you need to do something about the fact that we can't see your code.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks PaulS, you're right, Here's my code for the first case:

Code:
/*
  Blink
  with auto-power-off (PNP)
 */

void setup() {               
  pinMode(2, OUTPUT);      // digital pin as output
  digitalWrite(2, LOW);   // keep power on
 
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  for (int i=0;i<10;i++)   // blink LED ten times
     {
  digitalWrite(13, HIGH);   // set the LED on
      delay(3000);
      digitalWrite(13, LOW);    // set the LED off
      delay(1000);
}
 
  digitalWrite(2, HIGH);  // force power off
}

and here's the code for the second case:
Code:
/*
  Blink
  with auto-power-off (NPN)
 */

void setup() {               
  pinMode(2, OUTPUT);      // digital pin as output
  digitalWrite(2, HIGH);   // keep power on
 
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  for (int i=0;i<10;i++)   // blink LED ten times
     {
  digitalWrite(13, HIGH);   // set the LED on
      delay(3000);
      digitalWrite(13, LOW);    // set the LED off
      delay(1000);
}
 
  digitalWrite(2, LOW);  // force power off
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think we need to see a wiring diagram, now. What are you trying to cut power to?

In both of the sketches, the blinking LED does nothing useful. After 40 seconds, one sketch will unconditionally turn the pin off. The other will unconditionally turn the pin on.

Neither knows anything about the button you are pushing.
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3089
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Neither knows anything about the button you are pushing.
The first entry shows two variants even.
Quote
In both cases, if I don't connect the digital pin, pushing on the button, power goes on. But if I connect the pin, power goes on immediately.
Is it something related to the fact that, by default, pins are INPUT? Please help, do you have any suggetion?
If pushing the button has any effect, your wiring must be different.
You cannot use an Arduino input pin, to switch the Arduino ON (probably I misunderstood your post)
You are feeding a high base current into your transistors. Are they still alive?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
thanks a lot for your response.

My idea as a newbie was to apply the same schema used to control a load through an Arduino pin using a transistor - the only difference being that the load is the Arduino itself.

In both the schematics, I first bias the transistor into conduction by pressing the external momentary push button (normally open) in the schema. Then I'd expect that stating digital pin OUTPUT and putting it in the proper state should have worked...

Consider that, in both cases, if I don't connect the digital pin 2 of Arduino board, I'm able to power the board as long as I keep button pressed (don't know if it's safe for the transistor)

but, as soon as I connect the wire to the digital pin, without pressing the pushbutton, power goes on immediately...
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your schematics must be wrong.  Same error in both.  You can't have the base of the transistor hardwired to Gnd or to 5v.
The pushbutton should have no effect other than to put some current through the 2k resistor.

Secondly, I wouldn't put the Arduino software into the turn-on loop.  How long must the user push down the button, then?
A second transistor, inverting the first, can provide immediate latching current to keep the first transistor on, even after the briefest push.

To turn off, the Arduino output pin, through another resistor, either turns off the first transistor, or turns on the second.

Lastly, use your first configuration.  It doesn't compromise the Arduino ground by the .2 v C-E voltage drop.  Ground is universal.
The Arduino can run on 4.8 instead of 5.0 volts.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! I'm really sorry, I've realized that the schematics are wrong... they don't correspond to the current wiring...

Here's the correct one for the first option I've tried:


And here's the correct one for the second option I've tried:


Sorry for messing things up

Without connecting digital pin 2, in both options a short push on the button turns on the board, but connectiong digital pin 2 the board goes on immediately... is it because at startup digital states are dangling?
Thanks a lot for your answers
« Last Edit: May 15, 2012, 04:37:06 am by ArJack » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try a pulldown resistor on the base (second circuit), maybe touching the pin 2 wire is triggering the transistor.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you need a pulldown (or pullup for the first circuit) on the transistor base.

Perhaps even a small capacitor in parallel with that resistor to eliminate any brief startup glitch from acting like a real digital actuation.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for the suggestions.

I've tried to add a pull-down resistor (in option 2):



But it has no effect. As soon as I give power, the board goes on. Another strange thing is that, after 10 blinks I set digital pin2 LOW, but it has no effect (the board remains on).

Code:
void setup() {                
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);   // keep power on
  
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);    
}

void loop() {
// do something  
for (int i=0;i<10;i++)   // blink LED ten times
     {
 digitalWrite(13, HIGH);   // set the LED on
      delay(3000);
      digitalWrite(13, LOW);    // set the LED off
      delay(2000);
}
  
digitalWrite(2, LOW);  // force power off   <<<<<<<<<<<<<<
}

I also tried connecting the pulldown resostor from digital pin 2 to ground...same behaviour...

I'll try to add a cap, but I really don't understand why, setting pin2 LOW, it does not cut power...
« Last Edit: May 15, 2012, 04:37:58 am by ArJack » Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3089
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As soon as I give power, the board goes on.

Sure. Assume the transistor is off, Arduino has no GND connection, so everything ( including pin2 ) is at 5V level.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im not really sure what the overall goal is here but ill try to help anyway
maybe try a circuit where the transistor is between the 5V source and the 5V input of the arduino.
Pin 2 needs to be hooked up to the transistors emitter and use the pushbutton to bypass your transistor.
if you want u could also use a pull down resistor

on a related note, what kind of power source are u using? (usbcable,battaries of adapter cable)
and please be sure that the power you try to cut is not the 5v output on the arduino board and that if your board is still connected with a usb cable tinkering with supply voltage is rellay not recommended (by me) and also pretty difficult.



Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks daatse for your suggestion.

My goal is to build some sort of light game for kids. I'd like to switch it on pressing a button and then have it automatically switch off after some time.

I've moved the transistor and now, when I connect digital pin2, the board does not go on (as I wanted). When I press the temporary push button it goes on (as I want). The only problem remaining is that it does not remain on, even if I state digital pin as an OUTPUT and set it HIGH.

The schematic I'm using now is the following one:


To be sure that digital pin2 is HIGH, I've tried to detach it from the base of the transistor and I've connected it to a LED: the LED lights up as expected... Any suggestion why it is not able to bias the transistor into conduction?
Thanks!
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 112
Posts: 5281
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The emitter of your transistor goes to 5V on the Arduino (which is HIGH). So pin 2 HIGH means the same voltage level as the emitter has. No voltage difference, no current from base to emitter. You probably need an additional transistor to drive the base?
Logged

Pages: [1] 2   Go Up
Jump to: