0
\$\begingroup\$

I am trying to build a circuit that will allow my arduino board to be turned on by a button (switch). Much like a power button on PC. Here is my schematic.

enter image description here

In real life I used a phone charger instead of the battery.

And here is arduino code. void setup() { pinMode(11, OUTPUT); pinMode(11,HIGH); } void loop() { // put your main code here, to run repeatedly }

The setup should work like this.

  1. The user press the button
  2. Arduino GND pin is connected to phone charger GND
  3. Arduino starts
  4. Arduino pin 11 goes high
  5. The pin activates the 2n2222 transistor
  6. The transistor connects other arduino GND pin to ground
  7. User releases the button
  8. Arduino stays on

The problem is, when I plug in the charger, arduino turns on without user pressing the button! I found the transistor to be guilty because if I disconnect the transistor collector from arduino gnd pin, arduino shuts down. Tried changing the transistor and no luck. Same thing happens if I put pin 11 to LOW in the code. I have no idea what's happening here and how is this possible. I'm relatively new to the electronics. Are there any possible workarounds that don't involve complicated circuitry? Also bare in my that I have only 2N2222 NPN transistors, so solutions involving FET, MOSFET, PNP and other transistors won't help me. Thank you in advance!!

\$\endgroup\$
2
\$\begingroup\$
  • Leave the Arduino powered permanently.
  • Make your code put the device to sleep at the appropriate time.
  • Look up examples of "wake from sleep".
  • You just wire the wake button to the wake-from-sleep input.

The micro will turn on at initial power-up.

\$\endgroup\$
2
\$\begingroup\$

It looks like Pinus already responded with what I would suggest but I thought I would add some insight as to why I think it may work. Before the MCU turns on the base of the transistor will essentially be floating. If it floats up the transistor should turn on and if it floats down it will turn off. The reason it is floating up is because of the internal resistances inside of the Arduino. There will always be some resistance (typically very high) between a GPIO pin and the Ground of an Arduino. This leads to essentially a very high resistance between the collector and the base of that transistor.

The first thing that I would try would be to add a pull down resistor from the base of the transistor to the ground of the power supply.

P.S. This is my first time posting so hopefully I didn't mess up some convention. Also I've never tried this circuit before so I may be totally wrong

\$\endgroup\$
1
\$\begingroup\$

When the Arduino is supposed to be OFF, you intend its GND connection to be high (close to the supply voltage). But to keep the 2N2222 off, it base drive must be off -- and its base connection is close to the actual GND voltage -- i.e. about 4.3 V below the Arduino's GND. The Arduino pin can't remain non-conducting in this condition (and could get damaged).

You can't do this robustly with just 1 transistor. Also, it is usually more convenient for further use of the Arduino to switch its supply, not GND.

Connect a 2N3906 (or nearly any PNP): Emitter = 5 V supply, collector = Arduino supply, base = 10k to 'X', and also add a 100k R between base and emitter. Now connect a 2N2222 (or any NPN): Emitter = supply GND, Collector = node 'X' (i.e. the other end of the 10k), base = 10k to pin 11 (or any other) of the Arduino. To keep the output on, drive the Arduino pin HIGH

\$\endgroup\$
0
\$\begingroup\$

Yes, im sorry, i've got it a little late. try to sold additional resistor between minus of the battery and the base of transistor.

\$\endgroup\$
0
\$\begingroup\$

SOLUTION USING ONLY NPN TRANSISTORS

enter image description here

All resistors are 1Kohm. There is a 0,8V voltage drop when using this solution (5V power supply leaves 4,2V for arduino). jp314's solution is likely much better but I hadn't had any PNP transistors to test it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.