Arduino Forum

Using Arduino => Installation & Troubleshooting => Topic started by: stealthbadger747 on Mar 30, 2019, 04:55 am

Title: Arduino Uno pins not reading correctly
Post by: stealthbadger747 on Mar 30, 2019, 04:55 am
Basically I cannot get the values to change when using INPUT_PULLUP even when I connect a wire to a pin that carries the 5v directly to it. So Pin 4 will print 1 for being off and 1 for being "on".

Second. If I use my analog pins, all pins will read roughly the same input on all the pins at the same time.

I made a simple test program:
Code: [Select]
int prevHighMilli = 0;

void setup() {
  delay( 3000 ); // power-up safety delay
  Serial.begin(9600); // This defines baud of serial connection
  Serial.println("--- Start Serial Monitor SEND_RCVE ---");
  pinMode(2, INPUT);
  pinMode(4, INPUT_PULLUP);
  pinMode(A0, INPUT);
  pinMode(A4, INPUT);
}

void loop() {
  unsigned long currentMillis = millis(); // grab current time
 
  //if((unsigned long)(currentMillis - prevHighMilli) >= 1500) {
    Serial.print("A0:  ");
    Serial.println(analogRead(A0)); 
   
    Serial.print("A4:  ");
    Serial.println(analogRead(A4)); 
 
    int sensorValue = digitalRead(2);
    Serial.println(sensorValue);
    int sensorValue4 = digitalRead(4);
    Serial.println(sensorValue4);
   
    Serial.println("\n");
   
    prevHighMilli = millis();
  //}
}
Title: Re: Arduino Uno pins not reading correctly
Post by: stealthbadger747 on Mar 30, 2019, 05:17 am
I disconnected my ground connection and this seems to let it read correctly sometimes.

it will be like 1 1 1 0 1 1 0, on pullup mode.
Title: Re: Arduino Uno pins not reading correctly
Post by: pert on Mar 30, 2019, 07:28 am
Basically I cannot get the values to change when using INPUT_PULLUP even when I connect a wire to a pin that carries the 5v directly to it.
The internal pull-up resistor you turn on with INPUT_PULLUP pulls the pin HIGH (1). A connection to 5 V also pulls the pin HIGH. So this is the expected and correct behavior. With a pull-up resistor, the reading when nothing is connected to the pin is HIGH, then when you want to change the value, you connect the pin to ground, which pull it to LOW (0).

Second. If I use my analog pins, all pins will read roughly the same input on all the pins at the same time.
It's not clear what you mean by that. What do you have connected to the analog pins?