Introduction: Arduino Pushbutton Without Resistor

About: I love hardware, and working on electronics. And I just can't pass up the opportunity to try to fix something. I also have a growing interest in programming and coding, and I love to expand my skills. I have b…

Do you hate having to add that pesky 10K resistor or extra 3rd wire to your Arduino project, when all you want is a simple way to use a simple pushbutton? Well, there is a much easier way to do exactly this, without the 3rd wire or resistor!

Supplies

  • A pushbutton
  • An LED
  • 220 - 1K ohm resistor
  • An Arduino UNO (or any other Arduino)
  • Some wires

Step 1: How It Works

A pushbutton is basically two contacts that are shorted together when pressed upon. The two contacts conduct current, which allows them to complete a circuit. In most circuits, the 10K resistor for the pushbutton is unnecessary, and only used if the pushbutton has very long leads or wires connected to it. The 10K resistor just prevents the voltages from floating, and keeps them grounded.


In our case, we just need 2 wires for the pushbutton to operate.

Step 2: Wire It All Up

The wiring is pretty simple. You can just follow the wiring scheme shown in the images.

Step 3: The Code

If you have ever used a pushbutton before, with a resistor, you may know that in the code, you read the value of the pushbutton's pin, and see if it has gone HIGH. This would mean that the pushbutton has been pressed. If it is LOW, it would mean that the button is not pressed.

This all makes sense, but in our new example, things are opposite.


Here is the code:


void setup()

{

pinMode(2, INPUT_PULLUP);//Declare the pushbutton pin to use its internal pullup resistor

pinMode(13, OUTPUT);//13 a an output (LED)

}


void loop()

{

if (digitalRead(2) == LOW) { //low, in this case means that the button has been pressed!

digitalWrite(13, HIGH); //turns onboard led on.

} else {

digitalWrite(13, LOW); //turns onboard led off if button isn't pressed.

}

}

Copy and paste it into the Arduino IDE, as shown above, and press select your board and port in the 'Tools' tab. (Images for reference) and then press the upload button (Images for reference)

Step 4: Testing It All Out

Once the code has uploaded, just try pressing the button, and the little LED should light up! So it is possible to use a pushbutton without a resistor! Wow, that sure did save me an extra resistor and wire!


Thank you for reading! Please follow me on instructables, or you can find me on YouTube, at Sky-Wired



Step 5: Video Demo/Tutorial:

Watch the above video for a tutorial and demo on how to build this!

Step 6: EXTRA:

Don't want to use any ground pins? Or, do you want to have your button just plug right into your Arduino project with NO external hardware?

Try this:

  • Wire up the button (or just plug it in) as shown above
  • Change a couple lines in the code
  • Its done! (again)



New Modified Code:

int fakeGND = 4; //Change this to the pin you want to make "GND" or keep it the same if you are following the tutorial.

void setup()

{

pinMode(4, OUTPUT);//Declare the fake GND pin as an output

digitalWrite(4, LOW);//Make the fake GND pin work as a GND pin.

pinMode(2, INPUT_PULLUP);//Declare the pushbutton pin to use its internal pullup resistor

pinMode(13, OUTPUT);//13 a an output (LED)

}


void loop()

{

if (digitalRead(2) == LOW) { //low, in this case means that the button has been pressed!

digitalWrite(13, HIGH); //turns onboard led on.

} else {

digitalWrite(13, LOW); //turns onboard led off if button isn't pressed.

}

}