Connect button to test in Mega

button 1
button 2
hello dear helper
I'm learning how to use the Mega and this week I bought different buttons on Amazon to test. But something went wrong with testing.
I chose this connection method below, but I found that I have some problems with the connect button.
arduino-with-button

I'm a little confused and don't know how to connect these buttons.
I would like to know if there is a proper connection method.
I really appreciate it and thank you

Use connections on the diagonal of the switch between ground and the input pin.

Also, the processor has pullup resistors available - it isn't normally necessary to add external ones

(This isn't an installation or troubleshooting issue)

1 Like

Hello bursttheatomicbomb
Take view here to gain the knowlegde about button und Led connections. Many thanks to LarryD.

Have a nice day and enjoy coding in C++.
Дайте миру шанс!

1 Like

Hi,
see in the image I posted how the button is internally.
Pin A is always connected to pin D, and pin B is always connected to pin C.

The way you connected your project the GND (black wire) is always connected to pin 2 (green wire).
By pressing the button, you simply connect the resistor to the GND.

I also agree that the best solution is to use the arduino pull-up resistors, but if you want to keep your external resistor, connect as in option B.

Push_button

1 Like

Thank you, I will try it right away😆

Thank you, I'm still trying to understand the picture. But thanks for the information you gave me.:raised_hands:

Thank you, I'll try it right away, thanks for all the info🙌

Do you mean you don't know a) which wire should go where or b) how best to physically establish connection, eg solder / breadboard / chewing gum etc?

1 Like

Hello, I'm actually a little confused on both of these. But thanks for pointing it out, it gave me a clearer way of thinking. At the moment I'm going to debug based on the previous suggestions, but regarding b) I'm trying to place the buttons on an uneven spot, so I'm trying to avoid using a breadboard. I'm going to try using glue to attach the buttons to it, the idea is still a bit difficult at the moment.:raised_hands:

If you mean to glue the wires to the switch I doubt if that will work, since I'd be surprised if glue conducts electricity. But you can apparently get liquid solder.

1 Like

thank you for your reply. deeply appreciate it.
I found that when I try to connect the project through 5v and gnd, the usb is automatically disconnected, I want to know if there is a suitable solution...

S3 in post #3 is best, and use input pullup as suggested there. So only two wires to the switch:

  • your green from Arduino pin to any pin on switch
  • your black from Arduino ground to the pin diagonally opposite the green wire on the switch
  • lose your red wire and resistor
  • pinMode(2, INPUT_PULLUP);
  • the Arduino pin will read high with button not pressed and will go low when pressed, so your digitalRead must look for a low in your if to do anything with pressed button.
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.