Arduino Due fires Interrupt when i get out of my chair or people move in room

Hi.

I have to check a button with a FALLING interrupt. It works great when the button is pressed. The problem is that when i get up from my chair or move around in the room or close the door, the interrupt will fire too. When i attach the oscilloscope to the interrupt input pin, i see very short peaks during those events. I need to get rid of those interferences, can you please help?

The pin is connected via 10 kOhm resistor to 3.3V (pull-up). I also tried various pull-ups from 470 Ohm to 80 kOhm, with no success.

The button pulls the pin to GND when pressed. Pretty standard setup...

My code:

#define SWITCH_1 10
volatile boolean interrupt_occured = false;

void setup() {
	Serial.begin(19200);
	attachInterrupt(SWITCH_1, switchPressed, FALLING);	
}

void loop() {
	if (interrupt_occured)
	{	
		Serial.println("Switch pressed");
	}
}

void switchPressed()
{  
    interrupt_occured = true;
}

I guess you don't use a pull up resistor :wink:

Clearly, that is not all your code.

Have you done this:

pinMode(2,INPUT_PULLUP);

Or are you using an external pullup resistor? If so, what value?

What layout are you using? It sounds like you may be picking up static electricity. Are your wires really long? Is the pullup resistor really high value? Try shorter wires, using twisted pair, and a 1k pullup resistor.

We need more information to help you.

He said he used a 470 ohm pullup, which should be low enough, for sure.

A lesson in just how sensitive floating inputs are to ambient static electricity or
capacitive coupling to mains. And an interrupt pin will detect pulses as short
as a few tens of nanoseconds just to make things worse...

polymorph:
Clearly, that is not all your code.

Have you done this:

pinMode(2,INPUT_PULLUP);

Or are you using an external pullup resistor? If so, what value?

What layout are you using? It sounds like you may be picking up static electricity. Are your wires really long? Is the pullup resistor really high value? Try shorter wires, using twisted pair, and a 1k pullup resistor.

We need more information to help you.

Thanks for the reply, but read my initial post. I am using an external pull-up resistor. I tried varioius values (for example: 470 Ohm, 1 kOhm, 5.6 kOhm, 10 kOhm, 18 kOhm, 33kOhm, 82kOhm). Did not solve the problem.

I attached the button to 2m of wire and on an other experiment just a couple of centimeters of wire directly at the breadboard. Did not solve the problem either.

Btw: That is all of my code. I dont think you need more for an interrupt.

MarkT:
A lesson in just how sensitive floating inputs are to ambient static electricity or
capacitive coupling to mains. And an interrupt pin will detect pulses as short
as a few tens of nanoseconds just to make things worse...

Is there a technical (maybe hardware) solution to filter this ultra-short static pulses? I have some serious equipment and electronic parts here, so i could built some circuits if that helps...

This is what I get for reading 6 threads at the same time... :blush:

I'd be using some form of anti-bounce.

In hardware, this could be just a 0.01uF capacitor from the input pin to ground.

This hardware filter will provide a 10ms fall, 20ms rise filter that will make the D10 interrupt input immune to noise and AC signal pickup.

Time Constant Calculator

Note that alternatively, with some register level programming of the D10 input, the hardware debouncing feature in the SAM3X can be used.

Note that there is a difference as to how a typical debouncer and a filter work:
A debouncer will respond instantaneously to a signal transition then have a time-out interval.
A filter slows the rise and fall time of the signal.
The average response time for a person to react and press a button is around 1/4 second.

See: Interference on my digital input - suggested fixes? - General Electronics - Arduino Forum

dlloyd's solution looks like a good one to try. I also use twisted pair if going any distance.

dlloyd:
This hardware filter will provide a 10ms fall, 20ms rise filter that will make the D10 interrupt input immune to noise and AC signal pickup.

Time Constant Calculator

Note that alternatively, with some register level programming of the D10 input, the hardware debouncing feature in the SAM3X can be used.

Note that there is a difference as to how a typical debouncer and a filter work:
A debouncer will respond instantaneously to a signal transition then have a time-out interval.
A filter slows the rise and fall time of the signal.
The average response time for a person to react and press a button is around 1/4 second.

Hey Thanks!

Your circuit works very good in my firt test. It only triggered one false positive and that was when i touched the door handle nearby and got zapped bystatic electricity ( I did not have physical contact with any part of the circuit at that point, so it mustve transmitted through the air).

I had another circuit used in hardware debouncing of interrupts by Jeremy Blum using an inverted schmitt trigger and an rc circuit. This reduced the bouncing but didnt help with the eletrostatic noise / false positives whatsoever.

That was the circuit i used before (only the lowest of the 3 depictured):

Hey Thanks!

Your circuit works very good in my firt test. It only triggered one false positive and that was when i touched the door handle nearby and got zapped bystatic electricity ( I did not have physical contact with any part of the circuit at that point, so it mustve transmitted through the air).

As per your Thomas Edison quote, an improvement might be to add 1K series resistance in the ground wire to the switch and clhange the capacitor to 2.2µF.

dlloyd:
As per your Thomas Edison quote, an improvement might be to add 1K series resistance in the ground wire to the switch and clhange the capacitor to 2.2µF.

Haha, yeah you got me on that one...can you please explain why the change of the capacitor and the resistor should bring improvement? I am not from an electronics background.

I still havent totally solved the problem with the interrupts, since now i dont get false positives, but when i call

attachInterrupt(PIN_SWITCH_MOTOR, calibrateMotorSide, FALLING);
attachInterrupt(PIN_SWITCH_END, calibrateEndSide, FALLING);

the interrupt fires ONE time, then after that it works like it should. Where does that initial interrupt come from? How can i prevent this? This seems to be a huge flaw in the Arduino provided interrupt functions.

I tried to solve this problem in this Thread, but so far no luck.

I need a clue, tried so many things already, nothing helped. Please help guys!

I'm going to move this to the Due section, as this is a Due problem now.

However on the Uno, an initial interrupt will come because the flag for that interrupt has been set in the processor before you do the attachInterrupt, and thus it immediately fires. There may be a way of clearing that flag on the Due (like there is on the Uno).

Hi,

Have you got this set up on protoboard?

Please can you post a picture of your project?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Can you describe your application, what is it accomplishing?

Thanks.... Tom... :slight_smile:

MaxBlitz:
I still haven't totally solved the problem with the interrupts, since now I don't get false positives, ...

All very well and good for "an academic/ learning exercise", but the bigger question here, is why you would be using an interrupt in the first place, for a totally inappropriate purpose - monitoring a pushbutton?

Haha, yeah you got me on that one...can you please explain why the change of the capacitor and the resistor should bring improvement? I am not from an electronics background.

The series resistor would help reduce transients or spikes on the ground wire to the switch and the capacitor change is probably not required if the original filter on the interrupt input already works. As Paul__B has pointed out, I'm also curious why an interrupt would be required in monitoring a pushbutton.