Problem with using a pull down resistor to prevent floating input pin

Hi guys,
I have run into an issue where an input pin is behaving like its floating even though i have used a pull down resistor. It seems to be sensitive to when i connect any wiring up to it. I have an led that turns on when the relay shown in the diagram closes. As soon as i connect any wiring to the input pin, the led dimly flickers even when the relay is open.

Can anyone help? I've uploaded a schematic to show how its set up.
Thanks

Show us a picture of your wiring, maybe you have a faulty jumper wire.
Always show us your code.
.

Wiring up an input like that is not the best way to do things. Inputs should be wired between pin and ground and the internal pull up should be enabled.
You should not be touching the wiring or attaching anything to the pin when the Arduino is powered up anyway. That will cause the problems you are seeing.

LarryD:
Show us a picture of your wiring, maybe you have a faulty jumper wire.
Always show us your code.
.

The wiring is on a prototype board is a bit messy and would be hard to follow. I have a full schematic on paper with all the inputs which i can put up if needed but i thought id just show only the part that's not working. There are three of these circuits all up on the board and they all have the same problem. Each have there own 10k pull down resistor.

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, INPUT);
}

void loop() {
  relayState = digitalRead(relayPin);
 
  if (relayState == HIGH) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

Grumpy_Mike:
Wiring up an input like that is not the best way to do things. Inputs should be wired between pin and ground and the internal pull up should be enabled.
You should not be touching the wiring or attaching anything to the pin when the Arduino is powered up anyway. That will cause the problems you are seeing.

Ah ok, sounds like ive done it wrong then.
I followed this guide and substituted the switch for a relay.
http://playground.arduino.cc/CommonTopics/PullUpDownResistor

You'll have to excuse my lack of full understanding as this is my first project. I have two pins on a pcb which connect to the relay. I noticed if i simply put a jumper between the pins, it works fine but as soon as i connect the pins to the relay the problem comes back.

Hi,
What is the relay in.
Are you sure you are connecting to the Norm Open contacts on the relay and nothing else in the associated relay circuit?

A picture is worth a thousand words, please post us a picture.
If your layout is a rats nest, what other wiring have you got that was not shown in your circuit diagram?

Tom..... :slight_smile:

I followed this guide and substituted the switch for a relay.
Arduino Playground - HomePage
You'll have to excuse my lack of full understanding as this is my first project.

That is fine, you are not to know that the tutorial you linked to is some what of a maverick in the electronics world. While it will work, it is not what 99% of electronic engineers do.
Have a look here for the full story:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

I noticed if i simply put a jumper between the pins, it works fine but as soon as i connect the pins to the relay the problem comes back.

This is a problem of "noise immunity". The long wires act as antenna and pick up all sorts of interference, most of which is mains causing the input to look like it has a rapidly changing signal on it ( which it has ) this is why your LED looked dim because it was being rapidly turned on and off.

The wiring is on a prototype board is a bit messy

That adds to the signal an un-terminated wire will pick up. The solution is to make your wiring neater and also drop the values of your pull up / pull down resistors. The lower the value the more interference they will withstand, but the more current they will take when the switch is on. Try using a 1K resistor instead of 10K, I would also use it in the pull up mode rather than the pull down mode.

TomGeorge:
Hi,
What is the relay in.
Are you sure you are connecting to the Norm Open contacts on the relay and nothing else in the associated relay circuit?

A picture is worth a thousand words, please post us a picture.
If your layout is a rats nest, what other wiring have you got that was not shown in your circuit diagram?

Tom..... :slight_smile:

The relay is in a IR beam sensor which is set to normally open. The wire that connects the relay to the pull down and input pin seems to be super sensitive. Even if i disconnect from the relay completely but leave the wiring still connected to the pins the led flickers just more faintly. I have tried different wiring but no change, how ever if i remove the wiring aswell, the problem goes away.

Ill put up a couple of photos. Hopefully that will show my setup better

Hi,
Check the value of your resistor, is it really 10K?

Tom... :slight_smile:

Grumpy_Mike:
That is fine, you are not to know that the tutorial you linked to is some what of a maverick in the electronics world. While it will work, it is not what 99% of electronic engineers do.
Have a look here for the full story:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
This is a problem of "noise immunity". The long wires act as antenna and pick up all sorts of interference, most of which is mains causing the input to look like it has a rapidly changing signal on it ( which it has ) this is why your LED looked dim because it was being rapidly turned on and off.
That adds to the signal an un-terminated wire will pick up. The solution is to make your wiring neater and also drop the values of your pull up / pull down resistors. The lower the value the more interference they will withstand, but the more current they will take when the switch is on. Try using a 1K resistor instead of 10K, I would also use it in the pull up mode rather than the pull down mode.

Thats a great resource, i wish i found that before spend hours making up my prototype board! :slight_smile: So from what i can take from that, I should use a 1k resistor, and have it as a pull up instead of a pull down.

TomGeorge:
Hi,
Check the value of your resistor, is it really 10K?

Tom... :slight_smile:

Yep it sure is, it looks like i followed the wrong resources. Such as this

jeffez:
Yep it sure is, it looks like i followed the wrong resources. Such as this

Yes, another "idiot's guide to Arduino" which leaves you in status quo.

Quite agree.
The symbol for a tactile switch is wrong, and the picture for a trim pot includes a hex switch which is something totally different.

10k is a weakish pull-down for an external signal.

Add 10nF between the pin and ground and you may improve things as that will stomp out
most RF interference.

MarkT:
10k is a weakish pull-down for an external signal.

Add 10nF between the pin and ground and you may improve things as that will stomp out
most RF interference.

Interesting. Would it be worth adding the capacitor to my final design or would that be more of a band-aid solution to counter the weak pull-down resistor?

When its installed the sensor relay could be upto say 10 meters away worst case so i should allow for that. Would 1k pull-up suffice or should i go for a even lower resistance? Would the added 10nF still be worth adding for added reliability?

Yes I would try 1K and a capacitor first. If you still get problems then change the resistor to 510R.

Thanks. Changing it to a 1K resistor fixed the issue straight away. I also added the capacitor and will test to see how it runs using a much longer length or wire.

Just on the subject of pull-up vs pull-down. I have been trying to work out why pull-down (active HIGH) is so uncommonly used.

My reasoning to using pull-down was because the relay is on a sensor that will only be tripped briefly a few times a day. Doing it this way meant that the 5ma or so was not being consumed all day. Should i still use a pull-up? Is it just more reliable/stable doing it that way?

jeffez:
Just on the subject of pull-up vs pull-down. I have been trying to work out why pull-down (active HIGH) is so uncommonly used.

One reason, ground is often extended everywhere, as a common. So you can run one wire per input, and just ground it to make it active.

An other reason is that the original TTL logic was difficult to pull down, requiring something smaller than 330R. When left to float it would float high so 10K was normally enough to hold it high.

Also you don't want your supply on a long run or exposed as it is potentially damaging when faults occcour.