Internal Pull-up in Arduino
When I first heard about pull down and Pull-up resistance this is what i imagined “a person doing workout 😆”
If you set the digital pin of your Arduino board to be an input, and no external device or sensor is connected to it, then the input to the Microcontroller cannot be determined with certainty. It is either HIGH (1) or LOW (0) input.
In pull-up the Resistor is connected to VCC which is either of 5 or 3.3 volts . While the pull-down resistor is connected to GND.
There are two different cases here,
1) WHEN THE BUTTON IS PRESSED
The input pin becomes Low, a path is created for the flow of electricity, and a 5-volt is passed to the R1 Resistor, Button, and eventually to the Ground, resulting in a zero reading.
2) WHEN IS BUTTON IS NOT PRESSED
As the input pin becomes high, it produces a reading of one.
When the button is pressed, the current flows seamlessly through the ground without any issues, resulting in a zero reading regardless of the value of VCC.
In the absence of the button press, it’s important to note that there is an internal resistance present in the circuit. When the 5 volts from VCC passes through both R1 and R2 (the Internal Resistance in MCU), a voltage divider circuit is formed, which may not provide enough voltage to make the input pin high.
To address this, a resistor of 10K to 100KΩ for R1 could be used, which would help avoid most issues and ensure that the pin goes high when needed.
In this code, the built-in pull-up of Pin 5 is enabled without the use of a push button.
void setup() {
Serial.begin(9600);
pinMode(5, INPUT_PULLUP);
pinMode(5, INPUT );
}
In the setup() function, values are executed only once, and during this phase, Pin 5 is set as an input to the Arduino board.
pinMode(5, INPUT_PULLUP);
pinMode(5, INPUT );
Enabling Pin 5 as an input in Arduino UNO and activating its built-in pull-up resistor.
void loop() {
Serial.println(digitalRead(5));
}
The digital value obtained from Pin 5 is printed in the serial output.The Whole code goes below.
void loop() {
Serial.println(digitalRead(5));
}
Here is the output from the Serial monitor,
Happy Day!