why do we connect the pushbutton (to the pin on the arduino) on the resistor side of pushbutton.
like in figure 1 from the link above, the pushbutton is connected to pin 2 on the arduino. When i tried connecting pin 2 on the other side of the pushbutton (the side that's connected to 5V using the red wire), the project did not run the way it's supposed to.
can someone explain this to me? thank you in advance bye
That's called a "pull down resistor.". It connects the Arduino pin to ground when the switch is open. If this pin is not connected to ground, it will "float." When it floats, it could read any value and will randomly change voltage value. If connected to ground through a resistor, you know it will always be at 0 volts when the switch is open.
Kind of like a hot air balloon, if it is anchored to the ground, you know right where it is, on the ground. But if you cut the rope, it may be still on the ground, or it could start floating. We tie input pins to ground (through a resistor) to assure they are zero when the switch is open.