Go Down

Topic: Disconnected pins changing state (Read 2121 times) previous topic - next topic

greywolf001au

Not sure if this has been covered but I have tried Googling for an answer and am not able to find one, I have written a sketch for my Arduino Duemilanove 328 board which during the setup process loops through each digital pin, gets its high/low state and stores it in an array.
In the loop method I am scanning the pins for changes, I also added an array holding a list of "linked" pins, so if for example a switch on digital input pin 2 changes state the linked pin will also change state (output pin). Any state changes are then written to serial, when I have no "linked" pins, a switch i have attached to pin 2 only triggers the state change on pin 2 (this is as expected), when I link pin 2 to output pin 13 (onboard L.E.D) and the switch is triggered pin 2 changes (good), pin 11 changes (huh), pin 13 changes (ok) and pin 11 changes again, I know pin 11 is in no way linked to pin 2 or 13 in my code, why is 11 changing states, there is nothing attached to pin 11, i changed my switch to other pins and noticed pin 5 in some circumstances is also changing of it own accord, any ideas why this could be happening.

robtillaart

Post your code please, so the forum can have a look.

you may have to use the internal pullups to get a more stable reading. A pin connected to nothing might float ...
this is how its done
Code: [Select]

  ...
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);  // enable internal pullup
  ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

greywolf001au

I have attached my code although I do not believe the code is triggering the change it is possible due to the method used to extract integers from string although this should really not affect 2 pins. to test this sketch I start with the switch closed (pin 2 high) then issue the following command through putty:

link 02 13
show

i attempted to set pin 2 as input and set to HIGH this did not appear to have an affect on the result, pin 11 still changed, I should add I have connected a toggle switch to the ground and reset pins using a 10uF capacitor could this affect it in any way.

Grumpy_Mike

Quote
why is 11 changing states, there is nothing attached to pin 11,

It is called a floating input, all electronics behaves like this, you need pull up resistors:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

greywolf001au

#4
Jun 28, 2011, 03:49 pm Last Edit: Jun 28, 2011, 04:08 pm by greywolf001au Reason: 1
ok you are correct however the pull-up resistor on 11 needed to be set not on pin 2 where my switch is, still do not understand why one pin affects another, pin 11 does not change unless both 2 and 13 (in this case) change, is this due to the diversion of power to the other pins. please forgive any ignorant questions I am teaching myself.

Upon inspecting the switch further I see it is attached to the ground via a 10k ohm resistor which i am guessing is why activating pin 2's pull-up resistor did not work, thanks for all the help.

robtillaart


Pin 2 was just as an example. If one pin is floating it is affected by all the electric fields around it - as one teacher said : "every wire is an antenna"

There are even a magical instrument made based upon this effect - http://www.youtube.com/watch?v=w5qf9O6c20o - also used for the theme of several movies and TV series.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

greywolf001au

I see, as I had set pin 2 as the switch I assumed you were referring to the pin with the switch to have the pull-up resistor activated, so I should activate it for all floating pins.
I believe the instrument was also demonstrated on big bang theory.

Grumpy_Mike

Quote
so I should activate it for all floating pins.

Only necessary if you actually read them, if you ignore them then there is no need for a pull up.
One pin affects others because they are so close together inside the chip.
While a Theremin might look like it is the same effect, and you can make a Theremin of sorts with the floating input effect, a Theremin uses a different principal to actually work.

greywolf001au

the code is to go through and read the state of each pin, is there a method of determining if a pin is connected to something or floating

Grumpy_Mike

No the code needs the knowledge of what is connected and what is not, there is no way of telling if an input floats and gives random zeros and ones or that is the signal.
I suppose you could always activate the internal pull up resistors in that way you always read a 1 if it is disconnected.

greywolf001au

I see that does make a lot of sense, thanks again :)

Go Up