Push Button Wiring official guide question

There's a schematic demonstrating the several ways to wire the button and ranks the options:

Does someone have the canonical link to this diagram and any discussion around it? (ETA: Share tips you have come across - #999 by LarryD -- There's some discussion there and at https://forum.arduino.cc/t/wiring-a-button-pull-down-bad-vs-input-pullup-best/116298566 )

The Arduino tutorial chooses the BAD S1 wiring:


The danger I see in the tutorial's circuit is that any code run on the circuit with a line like:

    pinMode(2,OUTPUT);

would, when the button is pressed, short the 5V to ground through the Arduino, potentially sinking more than the 40mA limits on pins.

Here's some code that, if properly edited, could demonstrate the hardware vulnerability of pull-down button wired Arduinos to malicious software:

void setup(void) {
  for ( int i = 0; i <= NUM_DIGITAL_PINS ; ++i) {
    // pinMode(i, 0UTPUT) // smoke-test for non-current limited 5V inputs
  }
}

void loop(void) {
}

Maybe the pull-down tutorial advice helps sell replacement Arduinos?

ETA: Nick Gammon has a tutorial:

1 Like