user34045:   const int BUTTON      = 8;


void setup() {
  Serial.begin(9600);
  pinMode(BUTTON, INPUT);
}



void loop() {

  Serial.println(digitalRead(BUTTON));

}

I have connected a cable to pin 8. It's not connected to anything else nor have I any other cables connected.
I am expecting constant zeros, but I keep getting ones and zeros all the time, e.g. when shortly touching the cable.
I didn't experience that before. Did I accidentally damage my Arduino?

user30005: The pin is floating. Use pull up or pull down to help define its logic state.

user31105: If you don't connect it to anything, it can be a result of a flipping 'input' ... try to use a pullup or pulldown resistor.
Or better:
PullUp
Use something like:
 pinMode(BUTTON, INPUT_PULLUP); 


34045: <pre><code>  const int BUTTON      = 8;


void setup() {
  Serial.begin(9600);
  pinMode(BUTTON, INPUT);
}



void loop() {

  Serial.println(digitalRead(BUTTON));

}
</code></pre>

<p>I have connected a cable to pin 8. It's not connected to anything else nor have I any other cables connected.
I am expecting constant zeros, but I keep getting ones and zeros all the time, e.g. when shortly touching the cable.</p>

<p>I didn't experience that before. Did I accidentally damage my Arduino?</p>
 30005: <p>The pin is floating. Use pull up or pull down to help define its logic state.</p>
 31105: <p>If you don't connect it to anything, it can be a result of a flipping 'input' ... try to use a pullup or pulldown resistor.</p>

<p>Or better:</p>

<p><a href="https://www.arduino.cc/en/Tutorial/InputPullupSerial" rel="nofollow noreferrer">PullUp</a></p>

<p>Use something like:</p>

<pre><code> pinMode(BUTTON, INPUT_PULLUP); 
</code></pre>
