I don't understand how a button on the first image works. Do we just hope that there is some non zero voltage and hope its enough? I think the first image is really bad, but can't explain why.
There is a pullup resistor you don't see in the diagram because it is internal to the Arduino. I have added it in red. To make pin 7 an input, you can write:
, which not only makes the pin an input but also engages the internal ~20K pullup resistor.
So, you're right about the first diagram - it looks like the pin is left floating. Without the code, or an explanatory note, the pullup resistor isn't documented. In such a diagram, once you are familiar with the processor and know that there are optional pullups on the pin-drivers, you can assume that the optional pullup will be used.
Update: I drew in the resistor assuming the red rail was connected to 5v - I should have drawn that in, too.
The digital pins of an Arduino UNO, or rather the AVR microcontroller used in the UNO, have optional internal pull-up resistors that can be enabled with the
INPUT_PULLUP option to
pinMode. When you use
INPUT_PULLUP (as opposed to
INPUT) there is a functional resistor somewhere between 20kOhm and 50kOhm connected between VCC ("5V") and the digital pin. When you account for this internal resistor enabled, the circuits in your two images are structurally mirror images of one another:
The boxed numbers here are just to clarify what nodes in the wiring diagram correspond to what nodes in the schematic representation. Don't ask where box number 5 is; it's a mystery. I chopped part of the original second image so a new GND connection was hand-drawn in.
In your first image (left) the code would have to enable the internal pull-up resistor to establish a default
HIGH state on the digital pin. With
INPUT_PULLUP enabled you can imagine that internal resistor there when comparing with your second image (right). Here I've drawn a resistor symbol over the board to represent the internal one when enabled. When the button is pushed some current is drawn through that internal pull-up and the voltage at the pin falls to ground. Note you could just as easily have an external resistor there and use plain
Your second example image (right) is using an external pull-down resister to establish a default
LOW state. So when you push the button, the signal rises toward 5V/VCC or
HIGH, and some current flows through the pull-down resistor. This would be used with
INPUT mode rather than
INPUT_PULLUP; I have not annotated an internal pull-up on the right to indicate that the pull-up is not enabled in this scenario (plain
INPUT mode). Note that if you were to enable the internal pull-up in this second configuration it would form a voltage divider with external pull-down; for the 10K external pictured this could result default voltage at the pin which is only bordering on being a proper
Some people find it less confusing to have a
HIGH state when the button is pushed and also using an external resistor like this helps to explain the concept having a pull resistor altogether, because you can see it. In practice though, it's nice to able to use the internal resistors even if they pull in a more confusing direction. Note there do exist microcontrollers have optional internal pull-down resistors as well, but they're not as common; the UNO in particular does not have these.