Hello,
I am trying to understand the push button implementation. https://www.arduino.cc/en/tutorial/button
The schematic is the following:
Here is my question. Can I do something more simple like :
Thanks for your answer !
rocky2019
Hello,
I am trying to understand the push button implementation. https://www.arduino.cc/en/tutorial/button
The schematic is the following:
Here is my question. Can I do something more simple like :
Thanks for your answer !
rocky2019
Yes, the second approach is preferred.
Just remember to use pinMode(pin, INPUT_PULLUP)
, and remember that a value of LOW means that the button is pressed.
This is what's going on under the hood:
As you can see, when the switch is open, the pin is at a high voltage (through the resistor built-in to the Arduino), and when the switch is closed, the pin is pulled down to ground (low voltage).
Pieter
I understand what you are saying, thank you for the tip !
Are there pull-up resistors on all pins ? I am using the arduino pro mini.
rocky2019:
Are there pull-up resistors on all pins ? I am using the arduino pro mini.
Yes, on all pins, except A6 and A7.
(Note: even though A0-A5 are labeled as analog pins, they are full-fledged digital pins as well, so they also have a pull-up resistor. A6-A7 are analog only, so no pull-up.)
Great! Thanks for the help !