Pull up resistors not behaving as expected

Hi particle community,

I have been trying to get my photon to read the state of a very simple latching switch. One side of the switch is connected to ground the other to D1. I have applied a pull up resistor to D1 as shown below.

pinMode(switchPin, INPUT_PULLUP);

when the latching switch is closed I consistently read LOW using the digital read function as expected. However when the switch is open, rather than going to a consistent HIGH I just read noise (flipping between LOW and HIGH). This is not a de-bounce issue as it persists indefinitely. Any ideas as to what could cause this?

@MilkDoctrine, typically I’d recommend external discrete resistors are used for switch pullups, especially when noise is a concern as internal pullup is quite weak. Having said this, what you’ve described should work I think. Perhaps try pulling D1 up to 3V3 via an external resistor to verify the correct output. How are you reading the pin result? Tinker?

Also might pay to just swap the latching switch out for a basic temporary one to make sure there isn’t a loose connection inside the latching switch

I have had the same problem with two different switches (both latching). I am reading via my own sketch using digitalRead(switchPin). I will try using a 6k8 pull up and see if it behaves differently, I expect it will but the internal pull up should be good enough even at 40k.

What are you reading on that pin when you don’t connect anything at all?
Can you try another pin for testing?
Could there be something in your code interfering (e.g. I2C/Wire)?

I’ve used pinMode(pin, INPUT_PULLUP); (and PULLDOWN) successfully no end of times, so there must be something else involved.

1 Like