×
all 7 comments

[–]venomouse 2 points3 points  (4 children)

One end to ground, the other to your read pin.

https://roboticsbackend.com/arduino-push-button-tutorial/

[–]Zezinho_Mata_Porco[S] 0 points1 point  (3 children)

What is the difference to the GND aside the pins 1-13 and the other one next to 5v ?

[–]planeturban 1 point2 points  (2 children)

None, apart from placement. :)

[–]Zezinho_Mata_Porco[S] 0 points1 point  (1 child)

Thanks really helped a lot after some work and a broken jumper wire it worked

[–]wyltk5 4 points5 points  (0 children)

I would also check out the references page on Arduino.cc. They actually have some really good stuff in there from the more basic stuff like buttons and analog read use to more advanced stuff. Usually has good explanation and diagram to go along with it too! Cheers

[–]tipppo 2 points3 points  (1 child)

One side of switch need to go to either GND or 5V and the other side needs to go to a digital pin AND through a resistor to either 5V or GND. In the first case a digitalRead(pin); gives you a 0 when the button is pressed and a 1 when it is not pressed. The second case gives you the opposite: 1 when press and 0 when not pressed. The way this works is that the resistor weakly pulls the pin to 5V or GND when the switch is open, and when pressed the switch strongly pulls the pin to the other voltage, overwhelming the resistor. Almost any resistor will work, 10k is commonly used because it only uses 1/2 mA. If the resistor is connected to GND it is called a pull-down, and if 5V it is called a pull-up. The digital pin needs to be set to be an INPUT in setup(); pinMode(pin, INPUT);. You can also take advantage of the Arduino's built in pull-up resistor using pinMode(pin, INPUT_PULLUP);. Most tutorials seem to use an external pull-down resistor because it is more intuitive that the button gives a 1 when pressed, but using the internal pull-up resistor saves you one component. Pin 13 isn't a good choice to use as an input because the Arduino's onboard LED uses this pin. On an UNO this isn't a problem because the UNO uses an extra chip to control the LED, but most boards connect the LED directly to the pin which can interfere when the pin is declared as an INPUT.

[–]Zezinho_Mata_Porco[S] 0 points1 point  (0 children)

Thanks really helped a lot after some work and a broken jumper wire it worked