Interrupt attached to PIN 2 triggers unexpectedly, caused by 12v motor

Please refer to the attached image. I simplified my project to a bare minimum in order to show the problem.

Every time I press the switch (please see the attached image) the interrupt at pin 2 trips unexpectedly

I share a single power supply with Arduino UNO, the relay and the motor.

Even if I exclude the relay completely, any powering of the motor triggers unwanted interrupts at pin 2.

I even connected the pin 2 to ground.

My Code is simple and includes:

...
attachInterrupt(0, myfunction, FALLING);

...

I would ask you please if you know something and help me a bit because I am becoming crazy.

Thank you.

Try a diode across the motor, cathode/ring to motor+.
Leo..

Wawa:
Try a diode across the motor, cathode/ring to motor+.
Leo..

Thank you. I tried it but nothing changed. It looks like there is a spike when I switch the motor on or off. The problem is less when I use 2 power supplies, one for arduino and one for motor. But I prefer a single supply.

Any ideas?

In addition to the flyback diode, try a 0.1uF (or bigger) across the motor.

I tried everything. Of course with the Capacitor and diode across the motor things get a bit better but the problem is still there.

I read other posts about adding and grounding an aluminum case around the Arduino, using shielded cables, decoupling capacitors everywhere, or a ferride bead (which I don't have at the moment).

The mystery is that arduino's pins are affected even with dual power supplies and when only one cable is touching the relay.

Even if nothing is touching the arduino, if I don't include the capacitor and diode across the motor, the interference is passed, even through the air!

I attempted to measure on my oscilloscope the triggered motor alone with the Power Supply (set on 5A limit which is the maximum) with no capacitors and just a single switch. I captured the screen and the parameters at the moment I pressed the switch.

From what you see in the screen, even if oscilloscope probes are directly connected to the 12V power supply (5A max), as soon as I press the switch, it measures spikes high as 29.8V and low as -4.30V. This is unbelievable !

**SOFTWARE: **

I simply attach PIN 2 to interrupt:

 attachInterrupt(0, fired, FALLING);

HARDWARE:

PROBLEM:

Every time motor starts, the interrupt on PIN 2 fires unexpectedly, probably due to noise.

Surely the thread title should be

As expected, Electric Noise fires Interrupt on digital pin.

Athanassios:
Every time motor starts, the interrupt on PIN 2 fires expectedly due to noise.

Your answer

UKHeliBob:
As expected, Electric Noise fires Interrupt on digital pin.

Ok thanks for your point.
But what is the single secret to eliminate this particular nasty noise that makes arduino spit like an ugly tart when using a single power supply?

Ferrite rings, shielded cables, smaller capacitor as that one is WAAAAY too big, feedback / flyback diode, twisted pair cables.

Any or all the above.

Google "reduce emi interference"

EDIT
Also think one of the caps on your voltage regulator may be wrong size too. Normally one is a larger value and one is a much smaller value.

And not sure why you have that switch wired the way you have it either.

Most look like simple fixes

@Athanassios

MERGED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

ballscrewbob:
... smaller capacitor as that one is WAAAAY too big....

I must admit you really hit a point with that statement. I googled it and I got the following:

"Its not the larger capacitance value which would cause trouble, its the likelihood of your larger capacity cap also having larger ESR (resistance) or ESL(inductance). Excessive resistance and/or inductance in the cap itself will prevent it from being effective at decoupling."

ballscrewbob:
... And not sure why you have that switch wired the way you have it either. ....

That was just for the demo. Doesn't make sense indeed.

ballscrewbob:
@Athanassios
...
Continued cross posting could result in a time out from the forum.
....

Ok. I have made a mistake, not a crime.

Nevertheless, thanks for your wonderful reply. I' m about to order some of those ferrite rings and test my luck with some shielded cables and smaller decoupling ceramic capacitors.

If the pin is triggering when connected to ground you must be picking up strong magnetic interference
that's inducing voltages directly on the wire - this may be due to poor layout, making big loops with
you signal wires will act as magnetic loop antennas.