In the context of Arduino/ESP32, we usually add a resistor to the push button to complete the setup. Instead of using a resister, we can define the resister in code. In general, pull-up resistors are the more common simply because that is a thing we need most of the time due to the nature of logic inputs. In this article, we will explain how pull-up resistors work. Pull-down resistors will work in quite a similar way.
A pull-down resistor, or a pull-up resistor, is a resistor in an electronic circuit, located between the line and the power source (pull resistor) or the ground (return resistor), and which deliberately brings this same line either to the low state (0 in digital electronics) for a recall resistor, or in the high state (1 logic) for a pull resistor. It is important to clarify that this is not a specific type of resistance: it is a common resistance. Its place in the circuit gives it this name because of the function it fulfils.
How a Pull-Up Resistor Works in Arduino?
A pull-up resistor is used to ensure that an input terminal is at a high state. A pull-up resistor is a normally fixed-value resistor connected between a supply voltage and the input pin of the microcontroller board. This is used in circuits to ensure a known state and is usually used in combination with transistors, and switches to ensure the voltage between ground and Vcc is controlled when the switch is open/on.
---
In easy words, a pull-up resistor is a combination of a resistor on the microcontroller board and a microcontroller/transistor. When a simple mechanical switch is used as input to a logic circuit, a draft resistor is required so as not to leave the circuit input floating. The draft resistor is used in this case to impose the high level while the switch can still impose a low level. Without pull resistance, the input would be floating and thus at an indefinite logical level which could cause erratic operation of the circuit.
Reference in Arduino documentation :
1 | https://www.arduino.cc/en/Tutorial/DigitalInputPullup |
The above web page and below code give you a demonstration in real life of how it works. This is a normal code for a push button:
1 2 3 4 5 6 7 8 9 | void setup() { pinMode(13, OUTPUT); // LED pinMode(12, INPUT); // Pushbutton } void loop() { bool buttonState = digitalRead(12); // store current state of pin 12 digitalWrite(13, buttonState); } |
And this code used an internal pullup resistor :
1 2 3 4 5 6 7 8 9 | void setup() { pinMode(13, OUTPUT); // LED pinMode(12, INPUT_PULLUP); // pushbutton } void loop() { bool buttonState = digitalRead(12); digitalWrite(13, buttonState); } |
Should We Fearlessly Omit Adding the Resistor to Pushbutton in Arduino/ESP32?
This is a fix, and can be used for production PCB to solve odd problems, i.e. when the switch acts in a completely random manner or just by moving your finger closer to the circuit changing the state! This does ensure a smooth operation but that needs calculation of resistance. The other uses are not commonly used in DIY works.
Tagged With https://thecustomizewindows com/2023/01/how-internal-pull-up-down-resistor-works-arduino-esp32/