Electron spurious events on digital pin

While making a project with an electron, with a sensor switch connected to D2 (pulled low by my code), I’ve noticed that when I connect a wire to that pin on a breadboard, with nothing connected to the other end of the wire, it will often cause the pin to briefly go high.

I have the same project in the field, and it has recently given me a series of notifications based on the status of this pin - it performs an interrupt on change. The pin was high due to a closed switch, and it repeatedly sent a notification triggered by the interrupt on D2. However, the data that came with the notification (which reads and transmits the pin state) never showed a change, told me 4 times in a row that the pin status was high - though you’d expect the status to change with each subsequent notification since it only interrupts on change of state.

I’m thinking that the behavior is caused by static electricity, a lightning storm in the vicinity - the project is on a hill in the desert.

My current plan is to implement some sort of debounce code to prevent this in the future.

Has anyone experienced similar behavior, and if so, how did you solve it?

Thanks,
J

If don’t have a pull up or pull down, either physical resistors or using pin mode, then input will float all over the place and just read random values.

2 Likes

Hi @bko,
Sorry, I guess I wasn’t clear enough. The pin is pulled low by code, and when the sensor switch closes, it goes high with 3.3v.
The system has been quite stable for close to a month, then all of a sudden, I got 4 notifications triggered by the interrupt (change). I haven’t seen any odd ones for the last 48 hours now.
J

That’s still not very clear :wink:
How does your code pull the pin low?
Or do you mean you used pinMode(pin, INPUT_PULLDOWN)? If so, just state the fact explicitly :sunglasses:

If you got longish wires you may want to use stronger external pull-down resistors (e.g. 4k7 or even 2k2)

@ScruffR
Yes, I used:

pinMode(sensor, INPUT_PULLDOWN);

The sensor pin is connected to a float switch, about a 10 foot run.
Is that long enough to require an external resistor?

Yup, 10 foot is miles in the world we are living here :wink:
With that kind of “antenna” you may even need to protect your pins against induced overvoltage.

1 Like