Please tell me why is it necessary to access pull-up resistors and how can we access them in arduino?
closed as too broad by Ignacio Vazquez-Abrams, Dave X, rebatoma, Madivad, RSM Jun 20 '16 at 8:06
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Pull-up resistors are used to define the state of an otherwise "floating" input by pulling the voltage at the pin to a set voltage.
The most typical example is a switch - let's say you have some signal, which is connected to your input through a switch. If the switch is open, the state of your input is "floating". If you try to digitalRead or analogRead that input, the value will be pretty much just noise.
But, if you have a resistor connected from your input to ground (pull-down) or VCC (pull-up) your reading will be consistent (HIGH or LOW, depending on where the resistor goes) while the switch is open.
When the switch is closed, the voltage at the pin will be pulled to the voltage at the other end of the switch. Because of the lower resistance of the switch relative to your pull-up resistor, this is the input level that will be read by the microcontroller. Pull-up resistors are usually pretty big value (5k-100k) in order to be much higher resistance than the switch and to decrease the current that is used by the switch to produce a signal.
If, for example, you have a pull-up resistor and a switch that connects your input to the ground, when the switch is open you will read HIGH and when it is closed you will read low. Note that many components act similar to switches, for example transistors, open-drain / open-collector devices and many more, so the switch was just an example.
You can use external pull resistors (just add a resistor from your pin to ground or VCC) or use the internal pull resistors of your MCU.
The Arduino only has internal pull-up resistors (no internal pull-downs) - their value depends on the model, but usually is between 20K-150K.
To activate the internal pull-up resistor for a given pin on Arduino, use the following code:
pinMode(N, INPUT); digitalWrite(N, HIGH):
where "N" is your pin number or with recent IDEs:
A short answer from Arduino Playground:
Pull-up resistors are used in electronic logic circuits to ensure that inputs to the arduino settle at expected logic levels if external devices are disconnected or high-impedance. 'Just because you have nothing at all connected to an input pin doesn't mean it is a logical zero.'