Working Without a Pull-up/ Pull-down Resistor With Arduino

3,308

10

2

Published

Introduction: Working Without a Pull-up/ Pull-down Resistor With Arduino

About: An Electrical Engineering Teacher in Athens Greece. Most of these small projects here, are constructed for enhancing the learning of the use of Arduino as well as basic electricity and electronics for studen...

We can avoid using an external pull-up or pull-down resistors, simply by using the internal existing pull-up resistor within Arduino. This may make life easier when we use pushbuttons.

In void setup() {} add digitalWrite(buttonPin1,HIGH);
Internally you set a pull up resistor to the pin. The state is HIGH when the button in not pressed, and LOW when it is pressed..
Try the circuit, I liked it alot for its simplicity.
In a previous instructable, I examend the pull-up and pull down resistors so we can have a better understanding whats going on even with simple things.
You can find here: https://www.instructables.com/id/Understanding-the-Pull-up-Resistor-With-Arduino/

Step 1: The Circuit and the Code

/*
Working without the external pull-up or pull-down resistors,
and using the internal pull-up resistor in Arduino
This example demontrates the OR gate
*/
int buttonPin1 = 2;
int buttonPin2 = 3;
int ledPin = 8;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin1, INPUT);
digitalWrite(buttonPin1,HIGH); //Here you set internally a pull up resistor to the pin.
//The state is HIGH when the button in not pressed, and LOW when it is pressed.
pinMode(buttonPin2, INPUT);
digitalWrite(buttonPin2,HIGH);// the same as previous button
}
void loop(){
// so if the state of the buttons are LOW when pressed, to reverse this and make them HIGH we can use the Boolean Operator ! (not)
if ((!digitalRead(buttonPin1) == HIGH) || (!digitalRead(buttonPin2) == HIGH )) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Clocks Contest

      Clocks Contest
    • Woodworking Contest

      Woodworking Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    2 Comments

    Hi. I wanted to comment on your previous post about the internal pull-ups. Glad to see somebody else using it as well.

    Instead of this:

    pinMode(buttonPin1, INPUT);
    digitalWrite(buttonPin1,HIGH);

    Use:

    pinMode(buttonPin1, INPUT_PULLUP);

    This will do the same, but in a single command.

    1 reply

    Thanks! even better!