I'm trying to understand what might be wrong here. I'm trying to hook up a push button to my ESP32 WROOM dev kit.
When I test this my Arduino Uno R4 using pin 12, the serial monitor reads 1, until I press the button (connect a wire from gnd to pin 12) and then it shows 0. This is what I expect.
However, when I do this same test with the ESP32 on D4 With this code
It's always 1. Either connecting these wires (gnd to d4) or a button (should be the same thing).
I've tried more than D4, I can't get the "button" to ever show 0. Maybe the internal resistors on the ESP32 are too weak and so the 5v is always flowing and it never goes through the pin to ground? I can't think of why it wouldn't flow through my pin-ground(button) wire when it does just fine on the R4.
My apologies for the multiple threads. Sometimes you just want to figure something out and you end up working too long. For reasons I can't explain, last night this wasn't working at all. And now this morning, all but D2 seem to be working.
I suspect there is more going on here that I don't yet understand. I have a project running right now on an identical board with D2 connected to a button which works fine. But that board has a ton of other things connected, whereas my tests here are just the board with nothing else.
I did not understand what INPUT_PULLUP was doing before, but I get it now. INPUT_PULLUP is setting the pin to HIGH=3.3v. When the button is not pressed, current flows from the 3.3v pulled-up pin to the internal resistor and back to 3.3v. But when the button is pressed, current will take the path of least resistance which is through the button to ground, meaning that the pin now reads 0v instead of 3.3v. So pressed down we get LOW, unpressed we get HIGH.
Why it wasn't working last night, I can't say. But it's working now, except for D2, which is always LOW even if I tell it to INPUT_PULLUP. Even though I have D2 working in that other project. I suspect something else is adding noise or resistance to that circuit causing it to function.
Anyway, thanks again, and I'll try not to dup topics in the future. Learning can be hard, and sometimes walking away and coming back fixes everything.