Go Down

Topic: digitalRead not working correctly (Read 1 time) previous topic - next topic


Hey guys,

The digital read appears to be random. it changes from high to low whenever it contects with a wire, which is not connected to an energy source. I debugged it with a serialconnection and it indeed showed a random stream of 0 and 1's while only plain wire was connected. I have used different digital inputs but the bug remained.

Anyone knows what might be wrong?

Thanks in advance,


As several have stated you are reading a 'floating' input. To put it simple, I would ask you what would be your expections on reading a input pin that has nothing wired to it (or even a wire which is not wired to anything but the input pin)? If you said it should read LOW that would be in error. The correct answer is that a input pin that is floating is not a legally defined input state and will randomly read either high or low as circuit noise determines. The input pin must be electrically be wired to a voltage source that is either 0vdc (low) or +5vdc (high) to operate correctly.



Anyone knows what might be wrong?

Nothing is wrong, read this:-


So if I connect the the pin to a ground it will work? (just making sure I have that correct)

James C4S

So if I connect the the pin to a ground it will work? (just making sure I have that correct)


Videos of what your pin is doing, along with an explanation of how to use the internal pull-ups to keep the pin from floating.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com


Go Up