Pages: [1]   Go Down
Author Topic: digitalRead not working correctly  (Read 1042 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 22, 2012, 10:54:35 am by AWOL » Logged

"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.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34551
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There's nothing wrong, your pin is floating.

Whats that?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It isn't part of a complete circuit.
« Last Edit: July 22, 2012, 01:33:25 pm by AWOL » Logged

"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.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34551
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Anyone knows what might be wrong?
Nothing is wrong, read this:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the Help smiley I fixed it
Logged

Pages: [1]   Go Up
Jump to: