Is Arduino UNO going bad?

has my arduino gone bad, or have I done something wrong in the code ?

These prints where taken without doing any physical changes to the arduino, if you notice pin 10 state is changing between LOW and HIGH without any physical changes or connections !
while the prints where taken pin 10 was not connected to anything.

What could it be ?

An unconnected input is "floating" and its state will be random, just as you observed. To prevent floating we connect the input to a known state. That is where pullup or pulldown resistors come in.

See the digital pin tjutorial.

No surprise there if you do not have a pullup or pulldown resistor connected to the pin to keep it in a known state. It is picking up electrical signals from the environment

Try pinMode(10, INPUT_PULLUP); to turn on the Arduino's built in pullup resistor

Please follow the advice given in the link below when posting code , use code tags and post the code here to make it easier to read and copy for examination

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.