Pin inputs giving the wrong result

Hello! When using Arduino & having an input on any pin, I don't get the result I want.
I am doing a separate project involving push-buttons, and so I try and see when the Arduino detects that the button is pushed by a pin input. However, doing this never tells me what I really do.

I must say that I'm pretty new at Arduino, so I might be thinking about some things wrong. If anyone wants to know more information about the specific things I use, please tell me.
I'm using Arduino R3.

Here's the code I used trying to solve this problem. (edited)

int Pins[] = {A0, A1, A2, A3, A4, A5};

void setup(){
  Serial.begin(9600);
  pinMode(Pins[0], INPUT);
  pinMode(Pins[1], INPUT);
  pinMode(Pins[2], INPUT);
  pinMode(Pins[3], INPUT);
  pinMode(Pins[4], INPUT);
  pinMode(Pins[5], INPUT);

}

void loop(){

  Serial.print(analogRead(Pins[0]));
  Serial.print(", ");
  Serial.print(analogRead(Pins[1]));
  Serial.print(", ");
  Serial.print(analogRead(Pins[2]));
  Serial.print(", ");
  Serial.print(analogRead(Pins[3]));
  Serial.print(", ");
  Serial.print(analogRead(Pins[4]));
  Serial.print(", ");
  Serial.println(analogRead(Pins[5]));

  delay(500);
  
}

Here are the connections (using Tinkercad, ask me if you want a photo):

Note that this applies on digital pin inputs and analog pin input the same way, but I used analog so I could see the exact number of voltage that that pin recieved.
Also, I wasn't using the buttons because they did nothing: they acted as a cable, transporting the current. That also needs to be solved, but I want to focus on following problem first.

Here's what happens:

Giving current to A0 or A1 does nothing.
Giving current to A2 makes A0 detect the current.
Giving current to A3 makes A1 detect the current.
Giving current to A4 makes A2 detect the current.
Giving current to A5 makes A3 detect the current.
Any combination acts accordingly. (Ex. Giving current to A1, A2 and A4 makes A0 and A2 detect the current)

Trying this on 'digitalRead' gives too many patterns that I will not cover to not waste your time.
This applies with changing "INPUT" to "INPUT_PULLUP"
Also, I tried deleting all the 'pinMode' and the result is about the same, but all the pins go like crazy and don't stay stable.
EDIT: Changing the voltage to 3,3V just decreases the maximum voltage the pin can recive to about 700. Using resistors also only puts a limt (I used 220Ω and 1kΩ resistors).

I'm sorry if I was too specific, but since I'm new and this is my first post I didn't want to leave any detail unchecked. Thank you for your time!

...wrong datatype...

int Pins[] = {A0, A1, A2, A3, A4, A5};

Changing it to that or using this it's the same, but it doesn't detect the current on A4 and A5 when giving current on A5.

void setup(){
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);
  pinMode(A6, INPUT); 

}

void loop(){

  Serial.print(analogRead(A0));
  Serial.print(", ");
  Serial.print(analogRead(A1));
  Serial.print(", ");
  Serial.print(analogRead(A2));
  Serial.print(", ");
  Serial.print(analogRead(A3));
  Serial.print(", ");
  Serial.print(analogRead(A4));
  Serial.print(", ");
  Serial.println(analogRead(A5));

  delay(500);
  
}

Are the terminals on the switches symmetric? If so are you sure they are connected correctly? On each side two pins are connected together, so there are really only two connections. The usual scheme is to use diagonal pins and ignore the other two.

Please don't change your original post. That makes answers look stupid.

A switch/button needs a pull up or pull down resistor, so the pin isn't "floating" when the button is not pushed. An unconnected pin (button not pushed) can float HIGH of LOW from static picked up by the wires, so readings become unreliably. There are three options.

  1. button between pin and ground, with a (10k) pull up resistor to VCC (5volt for an Uno).
  2. button between pin and VCC, with a (10k) pull down resistor (to ground).
  3. button between pin and ground, with internal pull up.

Option 3 is the easiest, because the processor has internal pull up that you can enable, so no resistor is needed. Just use pinMode(A0, INPUT_PULLUP); // switch between pin and ground
Leo..

Edit: With option 1 and 3, the pin reads HIGH when the button is not pushed, and LOW when pushed.

Problem solved! I used a friend's Arduino and seems to be working fine. Guess my Arduino wasn't working correctly.

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