Question about serial

Hello,

I have a question about serial communication, or digitalRead.

int input8 = 8;

void setup(){
  
Serial.begin(9600);


pinMode(input8, INPUT);


}


void loop(){
  int I8A = digitalRead(input8);

  Serial.println(I8A);

  delay(10);
}

Whenever I apply power to input 8 in the serial monitor it shows it, but when i take it out it sticks around for a few seconds. This does not happen when I apply power to it, only when I take away the power.
I would be very grateful if someone could help me.

  • ManOfPanda

dc you have a pull down resistor between the pin and ground. if not the digital pin is "floating" when disconnected and the state is undefined. to have a dfininate state the pin must be connected either to +v or ground. the resistor can be 1K to 10K.

Best is to use a pull up resistor, from input to +5V and then connect it to ground. Connecting power to inputs is a bit dangerous as it is unforgiving of mistakes.