False interrupts and voltage drop when touch with metal

Hello, I've got a problem with random interrupts on Arduino Nano in my project. It's working in a noisy environment. I tried to track down the source of the problem and I came across this:

void blink(){
  digitalWrite(LED_BUILTIN, HIGH);
}

void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(2), blink, FALLING);
}

void loop(){}

I upload this code to Arduino Nano and whenever I touch pin D2, +5V, or GND with something metal (isolated or not, e.g. knife) the interrupt fires. I tried 2k pull-up, 100nF capacitor between +5V and GND as well as on D2 pin itself, but it didn't help. I checked that on a few Nano boards (all Chinese on ch340). On touch, the oscilloscope shows a spike on +5V. It also happens if powered 5V from batteries directly. Could somebody confirm this behavior (upload the code and touch the D2 pin with a knife)? Is that normal or all my boards are faulty somehow? How to prevent that?

Attach a schematic as you have wired it, not a frizzy thing. That would help solve your problem. Include all power and ground connections.

There's no schematic apart from Nano itself. I don't want to talk about my project, it doesn't matter. I just upload the code to Nano (nothing else in the circuit) and touch the D2 pin with a knife and that fires the INT0 interrupt. I guess that's unwanted behavior, right?

Hi,

What will you have D2 connected to?

Can you please post a picture of your project so we can see your component layout.
A circuit diagram is basically essential to help locate your problem.

What other hardware have you got connected to the Nano?

What is your environment?
Carpet, etc...
What will you have pin 2 connected eventually?
What is the application?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

1 Like

No, it is not normal, and yes I had that myself. Even touching the GND or connecting to a computer caused it.

The basic Arduino boards are not for an industrial environment. At least the official Arduino boards are good quality, the clones are often not.
You might have bought the cheapest clone, which has a lot of noise on its own and works just enough.

The human body has a certain capacitance to hold some charge. If your Nano board is connected to a computer or a circuit, it might already have a certain potential or charge and you touching it will send a disturbance throughout the whole board.

The way to solve this, is to imagine what is going on:
On the Nano board, there is probably a lot of noise. The environment might be so noisy that every piece of wire is an antenna and gets that noise. Your body has a charge. Your circuit might be more noisy than the Nano can handle.

Go to a open field and power an official Arduino board from batteries. It should not happen there.
Don't use cheap low quality clones, you get what you paid for. You paid for trouble, so that's what you got.
Isolate your Arduino board from the circuit with opto-couplers. There are also usb-isolators and isolators for the 5V power.
Put the Arduino board in metal box. Be careful with the grounding of the metal box. Someone had a serious noise problem on this forum a few weeks ago, and attaching a metal box to the frame of his project introduced noise instead of preventing it.

Pulse stretching sketch (not tested, put down in a hurry)

unsigned long previousMillis;   // timestamp
bool enable = false;            // enable the millis-timer
volatile bool pulse = false;    // variable to send information to the loop()

void blink()
{
  pulse = true;
}

void setup() 
{
  pinMode(2, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(2), blink, FALLING);
}

void loop()
{
  unsigned long currentMillis = millis();

  if( pulse)
  {
    digitalWrite( LED_BUILTIN, HIGH);
    previousMillis = currentMillis;
    enable = true;
    pulse = false;
  }

  if( enable)
  {
    if( currentMillis - previousMillis >= 200)   // stretch to 200ms
    {
      digitalWrite( LED_BUILTIN, LOW);
      enable = false;
    }
  }
}

[ADDED] I think the sketch works. Tested with Wokwi:

1 Like


That's my circuit :upside_down_face: (optionally additional 2k pull-up resistor on D2 pin, but it doesn't change anything). It's just an example to illustrate the problem. Just the Nano and the code. Nothing else. As for the power source, I tried the PC's USB, voltage regulator, and batteries directly to +5V, same result. Tried that on a breadboard and in the air.

@Koepel
Thank you so much for your answer! That's exactly what I am struggling with. I didn't realize that MCUs are so noise-sensitive. I thought: "Oh, a voltage regulator will do the job". Yes, my 'real-life' project is running in a noisy environment, there are big DC motors and 230V cables around. I'm surprised that the noise can be introduced by touching GND. I've just built a very simple circuit using attiny13a just to check this and it's vulnerable too.

That's interesting. Maybe you know some articles about isolating AVRs from noise sources?
I assume that the problem can be workaround with code but I'm looking for electronic solutions.

What's the difference between cheap clones and official Nano apart from USB-UART chip? Higher quality capacitors?

Hi,

Quality of the components.
PCB track width and path in the PCB pattern.

Some even leave out some bypass components which makes the Nano more susceptible to noise and damage.

Tom... :smiley::+1: :coffee: :australia:

2 Likes

That is a photo from the internet. We would like to know more about what you have.
A detailed photo can show many things, for example: missing components, very cheap USB cable, bad soldering, and so on.

In my workshop my body picks up several volts at 50Hz, enough to cause problems just like this. I don't think it's got much to do with where the Arduino is made, though obviously I may be completely wrong.

Can you show us how it is powered?

Hi,
I think that because @maksz has the Nano physically floating on the end of a cable and not on at least some protoboard.
The insulation of the USB cable is also a good source of static electricity and it could discharge through the PCB and to the screwdriver or metal contact item.

I would suggest you put it in a circuit and see what happens.

I probe pins on many ICs for a job and don't get any processor reaction from hooking up a DMM with the other lead not yet connected. (Unless I short two pins together.. :astonished: :astonished: :astonished:)

Most ICs these days are static sensitive and so are stored in suitable conducting material, but when you put that IC in a circuit, the "suitable conducting material" is not needed.

Tom... :smiley: :+1: :coffee: :australia:

I tried that in many different configurations. I tried a few Nanos, a few USB cables, and batteries. Even if I solder Arduino the problem persists. I'm sure there is no physical connection problem.

One of my Nano boards:


The battery box:

Here it is on a breadboard (video, photo, scheme). In the video, I just touch D2 pin with a knife and then with an isolated cable. The uploaded code is the one I posted above.

Hi,
Thanks for the pics and vid.
What are the colour bands on your pullup resistor?
resistor

Have you tried using the resistor to pull down the input?

Tom... :smiley: :+1: :coffee: :australia:

I can't read that :sweat_smile:. I checked it with a multimeter, it's 2.2 k.

Yes, same behavior.

When you do that you make an antenna that picks up any external noise and injects it into the ground. This causes ground bounce and that can trigger an input or reset a processor.
Your actual nano seems to be coved in some sort fibres, take an old tooth brush and clean them off.

This is not a fault it is how electronics behaves in a noisy environment. However, a real Arduino has been tested and certified, part of the certification involves measuring how much external EM fields ( interference ) it can stands before it starts to malfunction. It is more than likely that the fake nano has not gone through this process.

A man went to the doctors and said "it hurts when I do this", the doctor said "then don't do that". The same is true of your circuit, don't attach an antenna and it picks up a lot less interference. When you touch anything it is you who are the antenna, and being a high percentage of salty water, you are a very good one.

An insulated isolated cable is also a good antenna, the insulation providing no barrier to high frequency signals.

1 Like

There would bo no problem if it only happened when I touch an input. However, the interrupt triggers when I touch +5V and GND which makes the circuit not working properly in a real-life application. Noisy power source randomly triggers the interrupt. How can I filter that?

Touching an input pin with a metal tool you are holding is one way to fry it - don't do this, inputs are only protected(*) against static-discharge though a high resistance (ie human fingertip), not a low impedance source (knife grasped in whole hand).

If your entire circuit is floating and you touch the supply or ground with metal you cause its voltage w.r.t. the environment to change at a massive rate (kV/µs sort of speed), which induces big interference spikes in almost everything.

Ground your circuit and don't touch it with metal tools!

(*) static protection isn't even guaranteed if you handle CMOS chips, even with protection circuitry they are highly vulnerable to voltage spikes.

1 Like

Did you also alter the sketch to match the external pull down resistor? That is disabling the internal pull up resistor and changing the interrupt to rising ?

The name "blink" for your ISR is a bit misleading. When it triggers, the LED is permanently on.

The header pins on that Nano appear to be hand soldered (or that could just be the picture). I'd start by putting a jumper between the two GND pins to see if the situation improves.

What real life applications require you to touch the +5V and the Gnd?

What if powered from batteries? And isn't the case usually connected to GND?

Yes, internal pull-up disabled and interrupt set to rising.

Does it really matter? It just lets me know if the interrupt fires.

I checked that on a few boards, some hand-soldered some soldered by the manufacturer. I doubt there is a physical connection issue.

Doesn't help.

I said it wrong. I mean that noise on +5V/GND triggers interrupts. It's working in a really noisy environment.

Could anyone check if the problem is present on an official Nano?

Turn OFF all the fluorescent lights in your room.
Paul