Why does external interrupts gets triggered automatically in Arduino UNO

Hii everyone,

i have written a code for Borewell controller, i am using pushbutton (Arduino UNO PIN 3) as external interrupt to Turn ON the motor. The Interrupt pin get fired even a small dupont patch lead to trigger my ISR , any idea on this?.
i have gone through all the limitations and reveiwing forum post for refrence, it was not working for me still it is triggering .

const byte interruptPin = 3;
volatile byte State = LOW;
static int  overrideAddress_flag = 0;

void setup() {
  Serial.begin(9600);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), override ,RISING);
}

void loop() {
  manualOverride();
}

void override()
{
  static unsigned long last_millis = 0;
  unsigned long m = millis();
  if (m - last_millis < 300) // 0.3 sec
   { // ignore interrupt: probably a bounce problem
   }
   else
   {
     if (State == 0)
      {
        overrideAddress_flag = 1;
      }
     if (State == 1)
     {
       overrideAddress_flag = 0;
     }
  }
}

void manualOverride()
{
   if (motorState == 0)
     {
       if (overrideAddress_flag == 1)
         {
           overrideAddress_flag = 0;
           motorOn();
         }
      }

    if (motorState == 1)
     {
       overrideAddress_flag = 0;
       motorOff();
     }
}

Please post a diagram of your switch wiring.

That is incorrect. The blue wire should go to the junction of the switch and resistor.

*Did you just delete your post??

this is the circuit of pushbutton

Screenshot from 2021-03-16 19-01-22.png

Screenshot from 2021-03-16 19-01-22.png

Your schematic is fine. The Fritzing diagram that you randomly deleted, is incorrect.

aarg:
Your schematic is fine. The Fritzing diagram that you randomly deleted, is incorrect.

sorry for the inconvenience

You seem to have an external pull-down resistor fighting the internal pull-up resistor. If you are going to use an external pull-down, change the pin mode from INPUT_PULLUP to INPUT.

johnwasser:
You seem to have an external pull-down resistor fighting the internal pull-up resistor. If you are going to use an external pull-down, change the pin mode from INPUT_PULLUP to INPUT.

Hello sir ,
i have tried it now, The interrupt pin get fired continously, even a small dupont patch lead to trigger my ISR.

jeevangg408:
i have tried it now, The interrupt pin get fired continously, even a small dupont patch lead to trigger my ISR.[/b]

Could it be that your external 10k pull-down resistor is not properly connected?

You need to declare overrideAddress_flag as volatile.
You never change the value of lastMillis.

A much better circuit would be to use:

pinMode(interruptPin, INPUT_PULLUP);

Then have the switch pull the pin to ground and trigger interrupt on FALLING.

david_2018:
You need to declare overrideAddress_flag as volatile.
You never change the value of lastMillis.

Hello Sir,
i have tried this but its not working, same problem faced.

johnwasser:
Could it be that your external 10k pull-down resistor is not properly connected.

Hello Sir
i have connected properly and checked twice thats not an issue .

gfvalvo:
A much better circuit would be to use:

pinMode(interruptPin, INPUT_PULLUP);

Then have the switch pull the pin to ground and trigger interrupt on FALLING.

i have tried different circuits and changing to different mode that also not working for me

jeevangg408:
this is the circuit of pushbutton

Screenshot from 2021-03-16 19-01-22.png

1. The following diagram (Fig-1) says that ACTIVE HIGH (AH) for Trigger Level of the interrupting signal is not permissible for Arduino UNO. The available options are: FALLING (Falling Edge, FE), LOW (Active Low), and RISING (Rising Edge, RE).


Figure-1:

2. Carry out this tutorial to verify the functioning of the INT1 interrupt and then correct/tune your sketch.
intzrx.png
Figure-2:

(1) Install the interrupting device K2 at DPin-3 of Arduino as per Fig-2. If you don’t have switch, then use a jumper.
(2) Install R1-LED1 network on the breadboard as per Fig-2.
(3) L is already on the UNO Board.
(4) Create and upload the following sketch. Save the sketch as int1.

volatile bool flag = false;

void setup()
{
    pinMode(3, INPUT_PULLUP);  //internal pull-up resistor is engaged.
    pinMode(8, OUTPUT);
    pinMode(13, OUTPUT);
    //------------------------------
    attachInterrupt(digitalPinToInterrupt(2), ISRINT0, LOW); //interrupt logic auto enabled; LOW trigger level
}

void loop() 
{
    if(flag == true) //ISR blinks LED1 for 3 times at 2-sec interval
    { 
       for(int i = 0; i < 5; i++)
       {
              digitalWrite(8, HIGH);
              delay(2000);
              digitalWrite(8, LOW):
              delay(2000);
       }
       flag = false;
    }
    else  //MLP continuously blinks L at 1-sec interval
    {
              digitalWrite(13, HIGH);
              delay(1000);
              digitalWrite(13, LOW):
              delay(1000);
     }
}

void ISRINT1()  //Side job; it blinks LED1 for 5 times at 2-sec interval
//because delay() function does not work in ISR; so, we cannot blink LED1 here; 
//blinking must be done in the loop()function based on value of flag.
{
   flag = true;
} //Interrupt structure becomes enabled

(5) Press the RESET button of UNO. Check that L is continuously blinking at 1-sec interval.
(6) Press K2 and hold it. Check that L is not blinking; but, LED1 is continuously blinking at 2-sec interval.
(7) Release K2. Wait for a while and observe that L is blinking again at 1-sec interval.

** **(8)** **
Press K2 and hold just for a while until LED1 just makes a blink and then release K2. Check that LED1 has made 4 more blinks at 2-sec interval. Now, we have 5 blinks including first short one.
(9) Check that L has started blinking at 1-sec interval.
(10) Repeat the process from Step-5.
(11) This is the end of INT1 tutorial.

intzrx.png

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.