Back to basics with buttons (floating pin problems)

I'm coming back to arduinos after years of using esp32s of various types. With those, I'm used to just connecting one leg of a button to ground and the other to a digital pin. Works fine. Sometimes I use the built in pull up resistor or sometimes I add an external pull up or pull down one.

WIth Arduino, when I've tried doing this, I've ended up with a floating pin. Looking at diagrams, it seems with arduinos they almost always show one leg of the button connected to 5v as well...

Can it be that it's more complicated to wire up a button to an arduino and not have it float?! (I WAS using an external 10K pull down resistor, I had one leg of my button connected to ground but via a 10K resistor. The other leg was just pulled straight into a digital read pin. The only time the read was stable was when the button was being pushed otherwise it was just floating 010101010101010100111000101010101

But am I going mad?? Why would this be very doable on an ESP32 but not on an Arduino?

Am I missing something? Should I take a nap? Get back to my bath chair?

So there is no confusion, show us a schematic of how the inputs are wired.

See pinMode() - Arduino Reference

Use INPUT_PULLUP so the pin isn't floating. The default is INPUT which floats.

Huh? That’s confusing. You read that I’m using an external pull up?

Will do :+1:t3:

It's just the same with Arduino.

You must have made some other mistake.

That's because most of those diagrams were drawn by beginners who can't get their heads around a pin reading LOW instead of HIGH when the button is pressed, or don't know about internal pull-ups.

Sounds like you didn't enable the internal pull-up. The 10K was doing nothing useful.

Maybe an unnecessary question...

A button has 4 pins. Are you aware that it really is 2 sets of pins interconnected inside the button? Always connect them diagonally.

1 Like

yeah the pcb micro push buttons do have four pins, most (all?) of the ones I'm using have two pins.

But yes I'm aware they're interconnected along the direction of the 'straight' pins - but really appreciate you mentioning it! :smiley:

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