pull up resistor question

I understand that for digital inputs I should use a pull up resistor going from the pin to 5v, in order to drain any noise power that may find itself on it, that way if I don't apply voltage it's 0 and when I do apply some voltage it will be 1, otherwise noise voltage may cause it to go to 1 when I don't want to. I'm just wondering, should that resistor be close to the board, or can it be remote? Ex: say I have 100 feet of cable going to a remote sensor of some sort somewhere, can I put the resistor at that sensor?

You can put it at the remote end, yes, but it is simpler to just turn on the internal pull-up resistor inside the chip.

Oh right, may as well do that. Saves me from trying to find 10k resistors on random old electronics. :grin:

Note that 100ft of cable is going to be a problem.
What sort of proble, depends on what sort of sensor.
The internal pull up is only 35K or so, it might need to be bigger if it is a long way off like you have.

I have not actually measured so 100ft may be generous, but basically my goal is to rig up the smoke detectors and other devices around the house to send a +5v to the arduino if they are set off (either by completing a circuit, or sending it's own power) to activate the digital circuit.

So if I do end up adding a bigger resistor could it still be at the far end or does it have to be at the board? And would I want to go higher ohm or lower? My gut feeling tells me I want to go lower so it draws more current, thus draining any power that comes from noise, as a longer cable means more noise. I would be using twisted pair cat6. Power and ground on one pair and data on another wire.

Most 120v smoke detectors have a third red wire that triggers the rest @ I believe 9v so make sure you lower that first with a voltage divider or zener diode/resistor
also make sure the grounds are all connected or in the smoke detectors case the neutral wire, just be very careful with the mains power, it can kill very easily (and hurt even easier)

RedSquirrel:
I understand that for digital inputs I should use a pull up resistor going from the pin to 5v, in order to drain any noise power that may find itself on it, that way if I don't apply voltage it's 0 and when I do apply some voltage it will be 1, otherwise noise voltage may cause it to go to 1 when I don't want to.

You might want to check your understanding of pullups. If you have it 'pulled up' to 5V, then it will be logic HIGH, unless something happens to pull the voltage down, e.g. closing a switch to connect it to ground. Assuming you're using 0 and 1 to refer to boolean states, then whether HIGH = TRUE depends on what you're trying to indicate. If the condition is 'switch is closed', then logic LOW = TRUE. When you write, 'when I do apply some voltage ...', are you referring to connecting the pin to an external voltage source, while it's in INPUT_PULLUP mode, or while you have it pulled up using an external pullup resistor? Either way, you're applying voltage, so there isn't any 'if I don't apply voltage' condition.

Or maybe I'm missing something.

I'm new to this, so that just confused me more. I thought the main reason for using one was to drain any "noise" power that may find itself on the line causing the digital state to switch to 1. For a digital input, any voltage = 1, 0 voltage = 0, right? So if I have it set to off (sensor not triggering, etc) then I want it to be 0, but with a very long cable I may capture noise and it may be enough to flip it to 1. So to prevent that I add a resistor between the channel line and ground line, it acts as a load, which will drain any noise voltage and make it stay at 0. When I apply a higher voltage like 5v, then the resistor wont be enough to fully drain it so I will get say, 4.9 volts at the other end which will result in 1.

Am I understanding this right?

For a digital input, any voltage = 1, 0 voltage = 0, right?

No, not right.

There are three "zones" within a signal. Anything below a certain voltage "Vil" (voltage input low) is considered a logic 0. Anything above a certain voltage "Vih" (voltage input high) is considered logic 1. Anything in-between those two voltages is invalid and discarded. This middle area is called the "noise margin". These combine to form the Static Discipline of the system. All logic chips and devices in the system must conform to this same discipline in order to function properly.

For the '328p chip the voltages are 0.3Vcc (at 5v supply that's 1.5V) for Vil, and 0.6Vcc (at 5v supply that's 3V) for Vih.

The purpose of a pull-up or pull-down resistor is to place the input into one of these two voltage zones when you aren't actively driving it (by linking it to Vcc or GND) into the opposite state.

Try reading The care and feeding of arduino inputs, by Grumpy_Mike.

What you just descibed, 'So if I have it set to off (sensor not triggering, etc) then I want it to be 0 ...I add a resistor between the channel line and ground line ' would be a pull-down, not a pull-up.

Also, when you write 'set it to off', this implies you're doing a digital write, which I don't think you want to do. You want to set it to mode INPUT, or INPUT_PULLUP, and then do a digital read to check whether your sensor is causing the pin to go HIGH or LOW.

Just curious what sort of sensor you're using here too.

I will be using all sorts of sensors, basically anything that can go on or off. One thing I want to monitor is AC power availability, so my intention is to plug a 5v adapter straight into the wall then feed an input with it, so when the power goes out it should switch from 1 to 0. Basically I'm building a data acquisition device. I may rig up smoke detectors as well to set a relay on/off when they beep so I can monitor for fire/smoke. Maybe CO etc...

I also have a hydrogen sensor I ordered, though I think that one will be used with an analog input as it can provide ppm readings and not just on/off. I'm still really new to this so I'm hoping this will work.

My intention is to write some code that will simply feed the values of the inputs to the serial and wait for return to feed it again, that way an external piece of software that I write can keep polling the device for the values which will update in my monitoring software which will send me email if anything goes out of threshold range.

edit: After reading that link, can't I just use this and not worry about pullup/pulldown?

Or is that just omitting it?

So basically I have a long cat6 cable from the ardiuno to a remote location with a device, let's say a light switch just to keep things simple. When the switch is on, it activates a 2 way relay, when the switch is off, that relay goes in it's closed position. So I would just connect the relay like shown in that circuit. 5v on the "on" side and ground on the "off" side and then input in the middle. The voltage would be supplied by an external source or perhaps the arduino itself and the switch just closes a circuit to activate the relay.

I'm new to this, so that just confused me more. I thought the main reason for using one was to drain any "noise" power that may find itself on the line causing the digital state to switch to 1.

Another way to say this is, if the input is "floating", ie not tied to ground or 5V, then
noise can enter the microprocessor and drive the line between logical 0 and 1.
Supposedly this can adversely affect proper operation, since the input is not a
hard 0 or 1 voltage, and can hold the input logic gates in the region between
logic levels, ie half-on, half-off.

A non-terminated 100' long cable is really just a big antenna for picking up noise.
That's MUCH longer than is normally recommended for 0-5V signals. Probably under
20', and maybe under 10', is more reasonable.

I almost always use 4.7-10K pull "down" Rs on my digital input lines, wired where
it's most convenient, right at the input pin.

Pull down is really what I was thinking, it did not occur to me there was both pull up and and pull down. Pull down seems like the most desirable for my situation as it leaves me with a single "switch" to turn the value to 0 or 1. Now can this pull down be 100 feet away from the arduino or should it be closer? I'm just using 100 feet as an arbitrary number in this case, I just mean to say "far". Chances are most of my runs will be shorter than that.

RedSquirrel:
edit: After reading that link, can't I just use this and not worry about pullup/pulldown?

Or is that just omitting it?

You might want to read it again, because right there at that diagram, Mike writes:

There are two major problems with a circuit of this type. ...

and goes on to explain that. Realize, also, that the use of a SPST switch in those examples using a pull-up or pull-down could be a proxy for a device that acts like a mechanical switch, but isn't.

When the switch is on, it activates a 2 way relay, when the switch is off, that relay goes in it's closed position. So I would just connect the relay like shown in that circuit. 5v on the "on" side and ground on the "off" side and then input in the middle. The voltage would be supplied by an external source or perhaps the arduino itself and the switch just closes a circuit to activate the relay.

I won't say that that won't work for your purposes, as you described it for that one situation. But you'll still have a cleaner implementation if you just use a pull-up/down. It's less complex than what you just described. And what you just described will not work in all cases. It would be better to understand how to use pull-up/down resistors.

There is a simple rule and that is that the pull up or down must decrease in resistance as the wire increases in length. This occurs because the antenna or noise sensor (wire) picks up more noise as it lengthens a 470R resistor would draw 10mA at 5V which is appropriate for an Arduino output port. I will also add that there are available smoke alarms and other types of sensors designed for home safety and protection. Most of these devices use a common supply bus that can go from 12 to 24V AC or DC and have a separate 'Alarm' output which can be wired back to a sensor/control panel for burglar, fire, intruder or water damage reporting or simple connected together so any alarm condition is reported as one type of alarm condition or wired separately for a condition report.

Doc

Logically most normal people will think in terms of pull down , instead of pull-up, because we want everything to be OFF to be normal. and usually OFF means disconnected, which is why you would require a pull down, to ensure it is still off, but also connected.

BUT

The arduino is equipped with internal pull ups, not pull downs... Why is this? It is because It is more reliable to work with inverse logic for a lot of reasons, One important one in your case would be that the sensor needs to supply 5 volts to you to indicate everything is OK, and 0 volts when there is an alarm, because if the sensor fails (or a thief cuts the green wire, disconnecting your sensor :slight_smile: ), it will indicate an alarm. if you use normal logic where OFF is no alarm, you wil never get an alarm if your sensor is dead.