Connect Arduino digital pin to input pin and work as button

181 Views Asked by At

In my project I need a push button to perform certain actions using Arduino. But unluckily I cannot buy a push button and I am in a bit of a hurry. Can I use the Arduino's 3.3v output pin and input pin to create a switch? I want to add two jumper wires and then connect them together. If both are connected then switch should be on. Can I do this? If yes then how?

1

There are 1 best solutions below

2
On BEST ANSWER

You don't need the ouput AND input pins for that, use the VCC, GND and the input pins.

When you connect the digital input pin to VCC, it will register 1. When you connect to GND, it will register 0. If you leave the pin floating, you will get an undetermined result.

If you have a resistor handy (500R, 1K, 10K, does not matter much), you can do something like that:

Arduino GND <---->[resistor]<--+-------> Arduino input pin
                               |     
                               |      
                               +-= -]--> Arduino VCC

You connect the VCC wire to register true, and disconnect to register false. The resistor in series with GND will avoid the pin being left floating.