0% found this document useful (0 votes)
11 views

Understanding The Pull Up Resistor With Arduino

Uploaded by

Agung Dewandaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Understanding The Pull Up Resistor With Arduino

Uploaded by

Agung Dewandaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

instructables

Understanding the Pull-up/Pull-down Resistors With Arduino

by PanosA6

With this little test I hope you'll understand why the pull- int Led = 10;
up (and pull-down) resistors are needed in digital circuits
like in Arduino. void setup() {
pinMode(buttonPin,INPUT);
With a pull-up resistor and with the button unpressed pinMode(Led,OUTPUT);
you make a logic state ON and with the button pressed Serial.begin(9600);
you make a logic OFF. }

With a pull - down resistor and a pressed button you void loop() {
make an ON logic state and OFF logic state when its int buttonState = digitalRead(buttonPin); //read the
unpressed. state of the button input
if (buttonState == LOW) { // if the button is pressed it is
Make the above pull-up circuit and try the code. You'll low state
see the LED ickering or less bright. digitalWrite(Led,HIGH); //see ickering led or less bright
Pressing the button and you see now the LED turned } else {
normaly on (fully bright). Turning o the button and the digitalWrite(Led,LOW);
LED its ickering again. Serial.println(buttonState);
}
/*Pull-up resistor test*/ }

int buttonPin = 3;

Step 1: With Out the Pull-up Resistor


Understanding the Pull-up/Pull-down Resistors With Arduino: Page 1
So why was the LED ickering? Simply the logic static of the open switch is oating so it could be either a '0' or a '1". When
the button is pressed this produces a clear logic state of LOW since its grounded.
Check in the Serial monitor to see this as well The will be a serial of unstable '0' and '1' caused by the oating open
situation of the switch.

Step 2: With the Pull-up Resistor

To prevent the unknown state a pull-up resistor will pinMode(Led,OUTPUT);


ensure the state on the pin is low. Serial.begin(9600);
Add a resistor of 4.7k* (check in step 4 the calculation of }
the resistor) to the circuit, and try the below code
See the led working properly with the two states LOW void loop() {
and HIGH. int buttonState = digitalRead(buttonPin); //read the
state of the button input
Check in the serial monitor, when you press the button if (buttonState == LOW) { //pressing the button will
you'll get a logic LOW produce a LOW state 0V
and without pressing a logic HIGH digitalWrite(Led,HIGH); //the led with turn on
/* with the pull-up resistor*/ Serial.println(buttonState);
} else{
int buttonPin = 3; digitalWrite(Led,LOW); //the led with turn o
int Led = 10; } Serial.println(buttonState); //check in the serial monitor
}
void setup() {
pinMode(buttonPin,INPUT);

Understanding the Pull-up/Pull-down Resistors With Arduino: Page 2


Step 3: A Schematic Explaining the LOW - HIGH State With and Without the Pull-up
Resistor

On the left you see the button the moment its beeing pressed. This gives a digital signal of the LOW state.

On the right the voltage across the pull-up resistor with the button unpressed is 5Vdc providing the digital signal of the
HIGH state.

Step 4: What Should Be the Value of the Resistor?

So lets assume you want to limit the current to 1mA.


Since Vcc = 5V, using Ohms law: R=U/I => R = 5000mV/1mA => R= 5000Ω = 5k
so a resistor of 4.7k will be ne
Mostly known to be used is a 10kΩ resistor, this will need only 0.5mΑ.

Understanding the Pull-up/Pull-down Resistors With Arduino: Page 3


Step 5: Using the Pull - Down Resistor

/*simular and the pull - down resistor */ void loop() {


buttonState = digitalRead(button);
int button = 2; if (buttonState == HIGH) {
int led = 10; digitalWrite(led, HIGH);
int buttonState = 0; } else {
digitalWrite(led, LOW);
void setup() { }
pinMode(led,OUTPUT); Serial.println(buttonState);
pinMode(button,INPUT); }
Serial.begin(9600);
}

Step 6: Working With Out a Pull-up or Pull Down Resistor

Check for this in another post I made here

https://www.instructables.com/id/Working-Without-a-Pull-up-Pull-down-Resistor-With-/

This can be a very misleading tutorial, as one would expect you to talk about the integrated pull-
up and pull-down resistors in the arduino. And how to use them with the code
Yes you are probably right!

Hi
I did this but the led doesn't flicker. I have connected it the way you show in the diagram. Any
ideas?
Yes the LED is less bright. Pressing it gets a HIGH state. Try the second step with the Serial
Monitor on you can see it
I meant to say, It stays on even without pressing the button.

Understanding the Pull-up/Pull-down Resistors With Arduino: Page 4

You might also like