Digital pin reading always changing

i bought arduino uno R3 few weeks ago and just started to learn arduino by then (im completely newbie :slight_smile: ), so for curiosity i made a sketch just to read all the digital pin (except pin 1 and 0) and post it in serial terminal.

here is the code i made

int count = 0;

void setup() {
  Serial.begin(9600);
  for (int i = 2; i <= 13; i++){
    pinMode(i, INPUT);
  }
}

void loop() {
  for (int i = 2; i <= 13; i++){
    if(i==13){
      Serial.print(digitalRead(i));
      Serial.print(" [");
      Serial.print(count);
      Serial.println(" sec]");
    }else{
      Serial.print(digitalRead(i));
      Serial.print(" ");  
    }
  }
  count++;
  delay(1000);
  
}

but something i dont understand happens, the output shows that pin reading always changing quite likely in some pattern.

the output i get from the first 60 seconds is like this

0 0 0 0 0 0 0 0 0 0 0 1 [0 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [1 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [2 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [3 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [4 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [5 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [6 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [7 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [8 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [9 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [10 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [11 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [12 sec]
0 0 0 0 0 0 0 0 0 0 1 1 [13 sec]
0 0 0 0 0 0 0 0 0 1 1 1 [14 sec]
0 0 0 0 0 0 0 0 0 1 1 1 [15 sec]
0 0 0 0 0 0 0 0 0 1 1 1 [16 sec]
0 0 0 0 0 0 0 0 1 1 1 1 [17 sec]
0 0 0 0 0 0 0 0 0 1 1 1 [18 sec]
0 0 0 0 0 0 0 0 0 1 1 1 [19 sec]
0 0 0 0 0 0 0 0 0 0 1 1 [20 sec]
0 0 0 0 0 0 0 0 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 0 0 1 [54 sec]
1 1 1 1 0 0 1 0 0 0 0 1 [55 sec]
1 0 0 0 0 0 0 0 0 0 0 1 [56 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [57 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [58 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [59 sec]
0 0 0 0 0 0 0 0 0 0 0 1 [60 sec]

the output keep changing in the same pattern, is this something normal to happen in arduino or maybe my arduino not working normally?

im not native english speaker so i apologize if i use wrong grammar or write something confusing,
thanks

If there is nothing connected to those pins they are said to be "floating" and their state undefined. See this post.

What is connected to the pins you are reading?
If nothing is connected, then that explains what you are seeing.

Something has to drive the pin high or low to get a valid stable reading.
When nothing is driving the pin the input is floating which is unstable and is undefined, but will read high or low or can change which is what you are seeing.

If you don't drive the input pin with some other device, you can turn on the internal pullup resistor for the pin to pull the pin high when nothing is driving it.

i.e.

   pinMode(i, INPUT_PULLUP);

--- bill

Yes, the pins are not connected to anything, and that solve my question.
i thought the pins reading will stay at zero when nothing connected to it because something called pull down or pull up resistor or something like that (i dont quite understand what it's mean and what it does),
i guess i need to learn more about basic electronics.

Thanks for quick reply :slight_smile:
love u guys

There is a pullup which will make an unconnected pin read HIGH, but you have to turn it on.
--- bill