Pages: [1]   Go Down
Author Topic: Arduino with Software off  (Read 876 times)
0 Members and 1 Guest are viewing this topic.
Zürich, Switzerland
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Shall a gadget be useful?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi community

I'm trying to build an Arduinosystem that can be turned on using a simple button that pulls the up the basis of a NPN transistor which leads to powering the arduino (see schema). Once the arduino is running, it sets it's digital out pin nr. 4 to HIGH, which should do the same as pressing the button. At the right moment, the arduino would be able to simply pull digital out pin 4 to LOW hence powering itself down.

The arduino poweres up when the button is pressed and I measure 4.96V on the digital out pin 4, but as soon as I let go of the button, the arduino is shut down.

What do I do wrong?

I would appreciate your help very much!
Thanks,
Dani

The arduino-Code:
Code:
unsigned int transistor_basis_pin = 4;

void setup(){
  pinMode(transistor_basis_pin, OUTPUT);
}

void loop(){
  digitalWrite (transistor_basis_pin, HIGH); 
}


* schema.jpg (40.09 KB, 635x602 - viewed 20 times.)
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The voltage at the digital-output D4 is slightly lower than the voltage on the "5V" Arduino pin, due to losses inside the chip.  And the voltage on the emitter of the transistor is lower than on the base, causing the voltage on the power pin to drop, causing the voltage on the D4 pin to drop ... until the whole thing switches off.

A better option is to exchange the NPN transistor for a PNP transistor, which is turned on by a digital-output set to 0V.  However you then have problems turning the PNP transistor off, so you need to drive the PNP with an NPN, connected something like the following:

PNP
collector : Arduino power
base : NPN collector via 1k resistor
emitter : +5V

NPN
collector : PNP base via 1k resistor
base : Arduino digital output via 10k resistor
emitter : ground

Alternatively, it is possible to put the Arduino into a deep sleep mode which consumes very little current.  It can then be woken via an interrupt, triggered by a level-change on one of the digital inputs.  The advantage of this setup is that you can use the same button to turn the system off or even do other things.  Check the Playground for details.
Logged

Zürich, Switzerland
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Shall a gadget be useful?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Tim

Thank you for your tips. I tried to establish the layout as you suggested (see image below) and I succeeded in turning the arduino on permanently when pressing the button only shortly. However, I can not turn the system off again.

When I set the digital pin 4 to LOW, the voltage measured on pin 4 only goes down to 3.98V (compared to 4.82V when set to HIGH).

Do you have any idea what I should change in order to get LOW to be low (0V)?

Thanks, Dani


* schema2.jpg (43.18 KB, 622x627 - viewed 15 times.)
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's not great to connect D4 to 5V via the switch.  It would be better to put the "on" switch between the collector and emitter of the PNP transistor.

To switch the circuit off, you can put a second switch between the base and emitter of the PNP.

For software-controlled power-off, you might need to add a 10k resistor between the NPN base and ground.  I'm not sure why you measure 4V on D4 with the output written low.  Maybe try another pin.
« Last Edit: September 27, 2011, 04:46:27 pm by tim7 » Logged

Zürich, Switzerland
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Shall a gadget be useful?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed the switch to be between the collector and the emitter of the PNP transistor --> turning the system on still works fine. The software turning off however remains unchanged ... with or without the 10k resistor. The voltage at pin 4 goes from 4.83V (HIGH) to 3.98V (LOW) and does so similar at other pins... I'll redo everything once more to see wether I connected something wrong. Thanks for your advice!
Dani
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It sounds like something is wrong.  Try measuring the voltages at the digital outputs with the Arduino powered normally and nothing else connected.
Logged

Zürich, Switzerland
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Shall a gadget be useful?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Tim

Indeed, something was wrong - it was me writing a wrong piece of software. In the loop I set the output pin to high every time instead of just in the setup. So the wrong code looked like this:
Code:
unsigned int transistor_basis_pin = 5;

void setup(){

  pinMode(transistor_basis_pin, OUTPUT);
}

void loop(){
  digitalWrite (transistor_basis_pin, HIGH);  

  if (millis() > 7000){
    digitalWrite (transistor_basis_pin, LOW);  
  }
}

I'm sorry I have bothered you too long. The added schema together with the following code works perfectly! Thank you very much, Dani

Code:
unsigned int transistor_basis_pin = 5;

void setup(){
  pinMode(transistor_basis_pin, OUTPUT);
  digitalWrite (transistor_basis_pin, HIGH);  
}

void loop(){
  if (millis() > 7000){
    digitalWrite (transistor_basis_pin, LOW);  
  }
}


* schema3.jpg (38.17 KB, 577x648 - viewed 16 times.)
« Last Edit: September 27, 2011, 05:28:26 pm by local_dani_21 » Logged

0
Offline Offline
Shannon Member
****
Karma: 159
Posts: 10409
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using a logic level MOSFET is much easier - no appreciable voltage drop too.  I think p-channel is the simplest circuit.
« Last Edit: September 28, 2011, 08:23:56 pm by MarkT » Logged

[ I won't respond to messages, use the forum please ]

Zürich, Switzerland
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Shall a gadget be useful?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That sounds interesting. Could you recommend a specific part (with a curcuit)? Thanks,
Dani
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mark, could you expand on that?  I'm less familiar with MOSFETs.

BTW, the circuit with 2 bipolar transistors doesn't cause any appreciable dropout.  I'm using exactly this arrangement to save battery power, by switching a circuit which lacks any built-in low-power mode.  With a BC327 pnp transistor the dropout is less than 10 mV.
Logged

Pages: [1]   Go Up
Jump to: