Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15238

Pin inputs giving the wrong result

$
0
0

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!

6 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 15238

Trending Articles