I used this code to check the state of Arduino pin 8. To see if the pin is High or Low but my output continuously changes from high to low.
I am not connecting anything to pin 8 while running this code.
const int Pin = 8;
int Reading=0;
void setup() {
Serial.begin(9600);
delay(2000);
pinMode(Pin, INPUT);
}
void loop() {
Reading = digitalRead(Pin);
if(Reading == HIGH)
{
Serial.println("HIGH");
delay(2000);
}
if(Reading == LOW)
{
Serial.println("LOW");
delay(2000);
}
}
But my Output Comes like this: OUTPUT:
HIGH
HIGH
LOW
LOW
HIGH
HIGH
LOW
LOW
HIGH
HIGH
LOW
LOW
HIGH
HIGH
LOW
LOW
Don't know what to do ??
pinMode(Pin, INPUT);
, so it might be more like floating input issue. - KIIV