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.
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
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.
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.
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.
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.