Any risk in directly connecting digital pin to ground in INPUT mode?

I use a simple push button to trigger an action on my Arduino Uno. Since I want to listen to the interrupt event, I'm using pin 2 with ground. The pin mode is set to input with pinMode(2, INPUT); That all works well with the code and the callback function is called when I press the button.

My question is now if there is any risk in creating a short-circuit between the pin and ground when pressing the button? Should I use a resistor to reduce the current? Or is all safe, as long as I use the "input" mode?

Welcome to the forum

Start by using a pinMode() of INPUT_PULLUP to turn on the built in pullup resistor on the pin. It is common practice to do this and have the pin taken to GND by a switch or button

There is no danger in doing this as long as you wire it correctly

However, I would question whether you need to use an interrupt at all to detect a button press

1 Like

It's safe and since input pins have resistance around 100 megohms, essentially no current flows.

But with a switch/button you need a pull-up resistor (you can enable the internal pull-up) so the input doesn't float to an unknown voltage/state when the button is not pushed. Then when you turn-on the switch, grounding it, current does flow.

1 Like

The interrupt is necessary (I think) because the device is busy reading different sensors in the loop.

Thanks a lot to both of you for the fast and helpful replies! :slightly_smiling_face:

How long does it take to read the sensors and what type of sensors are they ?

Please post your sketch, using code tags when you do

I cannot imagine any reason why a well written sketch needs an interrupt to read a button.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.