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,

PixelMaster

AWOL

#1
Jul 22, 2012, 05:52 pm Last Edit: Jul 22, 2012, 05:54 pm by AWOL Reason: 1
There's nothing wrong, your pin is floating.

Quote
whenever it contects with a wire, which is not connected to an energy source.

That's what we call an antenna.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grumpy_Mike

Yes this happens, it is called a floating input and it seems to surprise beginners.
You must connect a digital input to something and not leave it unconnected. Look at pull up resistors.


AWOL

#4
Jul 22, 2012, 06:00 pm Last Edit: Jul 22, 2012, 08:33 pm by AWOL Reason: 1
It isn't part of a complete circuit.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

retrolefty


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,

PixelMaster


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.

Lefty


Grumpy_Mike

Quote
Anyone knows what might be wrong?

Nothing is wrong, read this:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

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)

http://www.cmiyc.com/tutorials/arduino-pull-ups/

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy