why do my pins 2 and 3 both read the same values

So I bought an arduino and have decided to learn how to use it. My first question that i have been unable to google an answer for.

While doing the digitalreadserial basic built in tutorial, I was messing around with using different pins to read from, however i found that with the same code pins 2 and 3 would both read from the push button. I feel like I've been sufficiently vague as to my problem.

so in short same code i plug my input wire into digital pin 2, reads 1's and 0's when i push the button up and down, move the wire to pin 3 without changing anything programming wise gives me 1's and 0's.

I think I might eb asking questions beyond my current knowledge level but thanks for the input

Typical scenario when no pull up (or down) resistors are used on the offending pin.
The pin is electrically "floating, and could pick up the logic level from it's neighbouring pin, or hash from the wire/breadboard.

Two options.
External resistors or the internal resistors.
Enabling the inbuild pull up resistors is easy. No extra parts needed.

Use the internal pull up resitors on the pins by doing this in void setup():

pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);

Then connect the switch between pin and ground.
Logic is now reversed. The pin is HIGH when the button is not pressed, and LOW when the button is pressed.
Leo..

Hi,
If you connect the unused input to gnd, you will find that the open circuit input will not follow the other.

This because a digital input left open circuit is floating in potential, it can be any value from 0 to 5V.

In your case the open input is ghosting the adjacent input you have your button connected to.

Usually when using switches on inputs you use a resistor, usually 10K, to hold the input low if you are switching 5V, or hold the input to 5V if you are switching gnd.

Tom... :slight_smile:
Damn, Hi Leo, missed it by 59Seconds ha ha ha

Congrats on buying an Arduino.
Now you can spend as much time on it as we do :wink:

This is a good read about switches etc.

FYI

.