I'm trying to determine if this circuit is going to work exactly as I think:

Expected behavior is:

  1. When we press S1, arduino turns on and digitalRead(7) will give us HIGH value (INPUT_PULLUP is used) + digitalRead(8) will give us LOW value.
  2. When we press S2, arduino turns on and digitalRead(8) will give us HIGH value (INPUT_PULLUP is used) + digitalRead(7) will give us LOW value.

Is this correct?

Okay, we found that is more or less working circuit, now another question:

How this would change if I power Arduino through it's RAW pin, using 12v battery? Do I still need to protect input pins using diodes and resistors or it's not necessary since internal voltage will always be the same 5v?

UDATE: I think I found another way of solving the problems with digital pin overvoltage:

Logic is pretty much the same, the only difference is that now digital inputs are pulled low using optocouplers, so the difference in the current between digital pin and the ground to which is connected - disappears, since it's the same ground as for Arduino.

  • \$\begingroup\$ It's exactly opposite. But in general, for what problem do you need a circuit like that? \$\endgroup\$
    – FRob
    Commented Jan 20, 2016 at 11:13
  • \$\begingroup\$ Do you mean it's not gonna work as I expect? The problem is following: key fob for remote lock. In order to save the battery arduino starts up (powered) only when one of those buttons are pressed (I know about sleep modes and stuff like that, but I prefer to avoid it). Press button, power on arduino, arduino determines which button is pressed - that's complete behaviour. Btw my issue would be easily solved by using DPST switches, but it's impossible to find such. \$\endgroup\$
    – Ruslan
    Commented Jan 20, 2016 at 11:17
  • \$\begingroup\$ Sorry for my english, "arduino turns on" - means "power on", "power up" I don't know how to explain it differently. \$\endgroup\$
    – Ruslan
    Commented Jan 20, 2016 at 11:21
  • \$\begingroup\$ It's much better to switch the 5V rather than ground. However, a 'proper Arduino' can have a depressingly long start-up time; the button may be released before the code gets as far as reading the switches. It's much quicker if you program it using Assembly rather than C. \$\endgroup\$ Commented Jan 20, 2016 at 11:53
  • \$\begingroup\$ If I switch 5v then I wont be able to control input lines using this circuit. I burn my sketch directly without bootloader, in this case startup is way more faster than in "proper Arduino" scenario. Btw if the button released before the code gets as far as reading switches - then we didn't reach this point anyway, by the nature of this circuit, because Arduino will loose power :) \$\endgroup\$
    – Ruslan
    Commented Jan 20, 2016 at 12:09

2 Answers 2


I see a few issue with this circuit, although I think it will basically work the way you intend it to.

But first one correction, already pointed out: since you're using internal pull-ups and connecting the switches to ground, pressing S1 will pull pin 7 low (not high) and S2 will pull pin 8 low.

The first issue is that your processor will see a ground that's about 0.7 volts above the actual ground due to its being connected to ground thorough a diode. So if your battery is delivering, say, 3V (it's a key fob so probably not 5V right?) then the processor only gets to use 2.3V. Also its idea of "high" and "low" will be offset from all the other components in your circuit.

The next issue is that when you press a button, the corresponding pin will be connected directly to ground, which will be at -0.7V relative to the processor's ground (also already noted). That may generate a current from the processor's ground, through the pin's internal protection diode, and then out the pin to the actual ground. If that happens, it could be a lot of current, because there's no resistors anywhere in the circuit to control it. On other hand, if the internal diodes have the same forward voltage as your external diodes then maybe no current. But it seems iffy.

Another issue is that the user is directly controlling the power supply with the switch. Bad contacts on the button may cause the processor to startup with very low voltage, or gain and lose power a couple of times before the switch is fully engaged. Also there's the chance that the user will release the button before your program is able to complete its task. I think you're aware of these issues.

I really think your best bet is to keep the processor powered but in sleep mode. Sleep mode is specifically designed for this use case. Even in its deepest sleep mode, the ATmega processor can respond to pin interrupts.

  • \$\begingroup\$ Great answer! Thank you. Maybe it make sense to protect input pins with another couple of diodes (same as on the circuit), rather than resistors? I'm aware of issues related with debouncing and startup time but still, I want to give it a try to see what happens, in this case I can always get back to the sleep mode in the future. \$\endgroup\$
    – Ruslan
    Commented Jan 20, 2016 at 13:43
  • \$\begingroup\$ I guess you could put diodes in series on pins 7 and 8 too to eliminate the -0.7V input issue. \$\endgroup\$ Commented Jan 20, 2016 at 14:34

This circuit is somehow dangerous. Depending on the type of the diodes and the power consumption of the controller, the voltage on your input pins can drop below -0.5 V. If this happens, you leave the permitted voltage range specified by most microcontroller manufacturers. The controller may be damaged.

How to cope with that? You can provide the same diodes to the inputs, but probably you have to add additional pullup resistors to make sure, the voltage on the inputs exceed the voltage on GND at any given time. This requires some testing.


simulate this circuit – Schematic created using CircuitLab

Furthermore: Are you sure, the duration of the time, the button is pressed is sufficient to trigger all actions you need to performe including boot and setup of the controller?

And don't forget to debounce the keys, otherwise you may encounter really strange effects.

  • \$\begingroup\$ Not sure if I understand you correctly, but as I've mentioned in the description, I set pinMode to INPUT_PULLUP so I use internal pullup resistors proveded by arduino... or I need to put additional ones? If so then where? \$\endgroup\$
    – Ruslan
    Commented Jan 20, 2016 at 12:04
  • \$\begingroup\$ About duration and debouncing: this is only the part of it, in the final device I'm planning to add "something" (ssr or optocoupler), which is being connected to one of output pins will allow me to bypass all this buttons circuit, in order to connect ground directly to Arduino. In this case arduino will be responsible for powering off itself (will happen as soon as it's done), same goes for debouncing. \$\endgroup\$
    – Ruslan
    Commented Jan 20, 2016 at 12:04
  • \$\begingroup\$ The internal pullup of Atmel MCUs is very weak (20-50 kOhms), depending on model. The pullup may not be able to drive the input above GND, so I recommend adding a lower pullup resistor like 10k. But you have to add diodes to your inputs, to bring their respective levels up. \$\endgroup\$
    – Ariser
    Commented Jan 20, 2016 at 21:53
  • \$\begingroup\$ Thanks! You use schottky diodes because of their low voltage drop right? \$\endgroup\$
    – Ruslan
    Commented Jan 21, 2016 at 5:42
  • \$\begingroup\$ Yes. That was my intention. BAT 54 may be a little bit weak drpending on the number of peripherals but if you only have an arduino tgey may do well \$\endgroup\$
    – Ariser
    Commented Jan 21, 2016 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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