# Is a pullup resistor always required for a switch?

I have a water tank and I have three of these float switches mounted at various depths:

When the float is raised in the horizontal position, the circuit is complete and current can pass through. When the float is in the vertical position, the circuit is totally disconnected.

From reading around:

https://electronics.stackexchange.com/questions/67007/whats-the-difference-between-input-and-input-pullup

"If the pin is totally disconnected, it will randomly read HIGH and LOW."

So if the float switch is totally disconnected (float is in the vertical position) and connected to a digital pin that doesn't have an internal pullup resistor, the pin will still just randomly read HIGH or LOW due to environmental electromagnetic interference? Is that it? Basically, if the pin's not connected, it will still have random continually-changing voltages running through it, and some of those voltages will hit levels that cross the threshold for "HIGH" while some of them won't at different times.

Hmmmm... how would having random voltages ever be useful? Why don't all the pins have built-in pullup resistors to "quiet down" the voltage when there is no signal present? It seems like the internal pullup resistor can be enabled or disabled on command anyway since you have the explicitly set INPUT_PULLUP in pinMode for that pin.

The IO pins do have internal pullups, as you say just use INPUT_PULLUP when setting up the input. Then the input won't float when the switch is open.

However, with long wires or an electrically noisy environment, a lower resistance pullup resistor added externally can help make it more resistant to picking up noise when the switch is open.

Sometimes you might want a pull up , sometimes a pull down , or you might connect other components requiring a certain setup

If you are using a float type switch you really need to use something to protect the Arduino - at least use a lowish value pull up or down ( 1k ?) plus protection diodes to prevent input voltages due to noise etc being negative or exceeding 5v . Ideally for such " real world apps", where you might have long leads etc , think about opto isolating the input

It seems like the internal pullup resistor can be enabled or disabled on command anyway since you have the explicitly set INPUT_PULLUP in pinMode for that pin.

Right! I've never used an external pull-up with the Arduino. (There may be cases where you need a different value resistor, or you may need a pull-down.)

So if the float switch is totally disconnected (float is in the vertical position) and connected to a digital pin that doesn't have an internal pullup resistor, the pin will still just randomly read HIGH or LOW due to environmental electromagnetic interference? Is that it? Basically, if the pin's not connected, it will still have random voltages running through it.

Two things - First it's the nature of the CMOS electronics. The old-original (bi-polar transistor) TTL logic circuits were high when open, although it was still standard practice to use a pull-up.

Secondly, the CMOS inputs are very-high impedance. You can drive the input high or low with with almost no current/energy. But, that makes it very sensitive to noise-pickup from any ambient electromagnetic energy.

...If you've ever touched the input of an audio amp and heard a hum or buzz, that's AC power line hum being picked-up by your body. If you lower the impedance (i.e. put a resistor in parallel with the audio input) the noise (voltage) will drop because there's not enough current from your body to get the higher-voltage at the lowered impedance. Guitar amps don't have a whole lot of gain, but they are very sensitive to noise pickup.

Hmmmm... how would having random voltages ever be useful? Why don't all the pins have built-in pullup resistors to "quiet down" the voltage when there is no signal present?

The high impedance can be useful in some applications. And, if you drive the input high or low, say by driving the input from another Arduino, you don't need a pull-up or pull down.

And in some circuits, it's advantageous (or required) to use a pull-down resistor.

polymorph: The IO pins do have internal pullups, as you say just use INPUT_PULLUP when setting up the input. Then the input won't float when the switch is open.

However, with long wires or an electrically noisy environment, a lower resistance pullup resistor added externally can help make it more resistant to picking up noise when the switch is open.

Ah, I see. My error was I was looking at a pinout of the Wemos D1 where only the D3 and D4 pins have a 10K Pull-Up and assuming that the Arduino was similar, in that only certain pins have built-in pullups.

https://wiki.wemos.cc/products:d1:d1_mini

So in the case of the Arduino, every IO pin has a built-in pullup and can utilize INPUT_PULLUP in pinmode. The Wemos, however, does not and only D3 and D4 are capable of this.

Hi, What you have to realise is that the I/O pins are just that, they can be assigned to be input or output, analog, digital, I2C, UART, PWM, Comparitor, Reset, Vref, and other functions.

Having a permanent pull-up or pull-down may inhibit the performance of some of those functions.

Some devices that would be connected to the controller ICs input, may not like being loaded with pull-up or down resistors.

Good to see you did some research before making your queries.

Thanks.. Tom.. :)

Ack, so I'm sitting here and another thought came up.

Do you need to worry about using pullup or pulldowns on outputs?

I have digital pins controlling a relay. Is it possible for random environmental fluctuations to cause a digital pin to output a high voltage and cause the relay to inadvertently actuate? Would it be necessary to add a resistor to make sure the voltage is always at 0V unless commanded to output?

Hi,

fuzzybabybunny: Ack, so I'm sitting here and another thought came up.

Do you need to worry about using pullup or pulldowns on outputs?

I have digital pins controlling a relay. Is it possible for random environmental fluctuations to cause a digital pin to output a high voltage and cause the relay to inadvertently actuate? Would it be necessary to add a resistor to make sure the voltage is always at 0V unless commanded to output?

No, the outputs are driven HIGH to 5V and driven LOW to 0V, so no need for them. Tom.. :)

TomGeorge: Hi,No, the outputs are driven HIGH to 5V and driven LOW to 0V, so no need for them. Tom.. :)

Ahhhh... gotcha. So digital outputs on the Arduino (or, more accurately, in the case of a relay's receiving inputs) don't use a voltage cutoff somewhere in the middle like "anything below 2.5V is LOW and anything above or equal to 2.5V is HIGH" as in the case of inputs, then, huh?

So this is interesting. A digital input on the Arduino should have a pull-up resistor to combat random environmental fluctuations. Does that mean that digital inputs, like in the case of those on a relay, have built-in (always on) pull-up resistors as well to combat fluctuations experienced by the relay?

Don’t know what you mean, digital inputs on a relay.

.

fuzzybabybunny: So this is interesting. A digital input on the Arduino should have a pull-up resistor to combat random environmental fluctuations. Does that mean that digital inputs, like in the case of those on a relay, have built-in (always on) pull-up resistors as well to combat fluctuations experienced by the relay?

No, that's a completely different issue. The relay has a set of contacts that are going to energize a coil. You can't energize a coil and set off a relay with random noise. That's a very different thing from a CMOS gate in the input pin.

Besides, you'll always have HIGH or LOW on the relay if you hook it to an output. There is no other options. Output pins are always either LOW or HIGH.

Delta_G: No, that's a completely different issue. The relay has a set of contacts that are going to energize a coil. You can't energize a coil and set off a relay with random noise. That's a very different thing from a CMOS gate in the input pin.

Besides, you'll always have HIGH or LOW on the relay if you hook it to an output. There is no other options. Output pins are always either LOW or HIGH.

Sorry, I'm talking about multi-channel relays. The relay takes, say, a separate 12V power source that drives the coils and then waits for a certain voltage on IN1, IN2, IN3, IN4, etc to come from the connected Arduino digital pins.

Those IN-pins: are they only looking for inputs of ~0V or ~5V? If yes, then it seems to me that they're being pulled in a certain direction whenever there is an absence of input.

This shows an input to a relay card.
You need to sink a few milliamps to GND at a Arduino side to energize a relay.
An open cct. on a IN input will not turn on a relay by accident.

.

fuzzybabybunny: Sorry, I'm talking about multi-channel relays. The relay takes, say, a separate 12V power source that drives the coils and then waits for a certain voltage on IN1, IN2, IN3, IN4, etc to come from the connected Arduino digital pins.

Those IN-pins: are they only looking for inputs of ~0V or ~5V? If yes, then it seems to me that they're being pulled in a certain direction whenever there is an absence of input.

Those relay boards like you are describing will most likely have whatever pullup is needed on the transistor already built on the board.

@fuzzybabybunny You lack basic understanding how electronics work. I am not saying this to put you down in any way. If you want to understand this area, you need to invest some personal time on the basics before asking advanced questions.

.

This link might help you :- http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

fuzzybabybunny: if the pin's not connected, it will still have random continually-changing voltages running through it,

Voltages do not run, nor are they through. Voltage is across, current is through.

fuzzybabybunny: So if the float switch is totally disconnected (float is in the vertical position) and connected to a digital pin that doesn't have an internal pullup resistor, the pin will still just randomly read HIGH or LOW due to environmental electromagnetic interference? Is that it? Basically, if the pin's not connected, it will still have random continually-changing voltages running through it, and some of those voltages will hit levels that cross the threshold for "HIGH" while some of them won't at different times.

Yes, a floating input floats - the clue is in the name. CMOS inputs are completely insulated by the MOSFET gate oxide layer, which is why they float. The to the question is you always need a pull-up or pull-down to define the pin state.

Hmmmm... how would having random voltages ever be useful? Why don't all the pins have built-in pullup resistors to "quiet down" the voltage when there is no signal present? It seems like the internal pullup resistor can be enabled or disabled on command anyway since you have the explicitly set INPUT_PULLUP in pinMode for that pin.

On the Uno all the inputs have pull-ups. And normally you've never leave any input unconnected in CMOS, that's bad news for a low power circuit as floating inputs can draw significant current in the input stage due to being half-on and half-off (that current isn't through the pin, note).

The internal pull up would be disabled for micro-power applications when the pin is normally LOW, as a massive 150uA might flow through the pull-up then, and micro-power budget might be 5uA or less in some cases.

A floating input can lead to its input section pulling several mA, note, an even worse problem for micropower (CMOS circuits pull no current if all inputs are defined and the circuit isn't being clocked)

Hmmmm... how would having random voltages ever be useful?

RNG. Other than that niche use probably never.

Why don't all the pins have built-in pullup resistors to "quiet down" the voltage when there is no signal present?

Cost? Die space? Didn't feel like it? Who knows?

Some micros have built in pull ups and pull downs. I think the nRF52 series has these. It all depends on what the designer wants to put in.

Right! I've never used an external pull-up with the Arduino. (There may be cases where you need a different value resistor, or you may need a pull-down.)

You've just never needed to. Some projects do need it.

I have digital pins controlling a relay. Is it possible for random environmental fluctuations to cause a digital pin to output a high voltage and cause the relay to inadvertently actuate? Would it be necessary to add a resistor to make sure the voltage is always at 0V unless commanded to output?

It depends on the characteristics of the input.

It is high impedance inputs that are sensitive to noise. A pullup resistor doesn't just offer a connection to a defined voltage, it also lowers the impedance of the input by putting the resistance in parallel. CMOS digital inputs have very high input impedance (hundreds of megaohms or more, usually), and are very sensitive to noise. Lowering the impedance means that you need stronger noise to affect the input.

For many things, the roughly 60k pullup resistor built into the AVRs is adequate, but there are times when it's not. If you are in a high noise environment (such are near mains cables, an engine or motor, or running really long cables to the switch), you need lower impedance.

Most cheap relay modules will probably just have a BJT or optocoupler input. These are basically diodes, which are current driven and very low impedance. There's not much danger of any kind of noise tripping up one of those. Any noise strong enough to activate an optocoupler is probably strong enough to cause you many more serious problems.

If the module has a CMOS input buffer, you might need to be careful about that.