I have written a very simple code to test the interrupt functionality of my Arduino Uno expansion board:

const byte buttonPin3 = 3; 

void setup() {
  pinMode(buttonPin3, INPUT); 
  attachInterrupt(digitalPinToInterrupt(buttonPin3), trigger, CHANGE);


void loop() {

void trigger(){

However, the Serial.println("trigger"); is activated as soon as I insert a jumper wire into pins 2 or 3. It seems like I have broken the microcontroller. I would appreciate if you could help me know if there is something wrong with my code or I need to change the microcontroller? if I have to replace the MCU can I just use any identical AVR and just place it on the DIP IC socket adaptor?

P.S. Filip Franik asked me to draw the schematics:


simulate this circuit – Schematic created using CircuitLab

P.S. I used the official Button's tutorial and now everything works just fine. I can't reproduce the issue anymore for no obvious reason!.

  • In the circuit that you posted there is not button or jumper wire to somewhere else. In the current state, both pins will only show 0 as their state. Please explain what jumper cable you actually mean, where you are connecting it and where it goes from there. – chrisl Sep 23 '19 at 8:21

Connect both Pin2 and Pin3 with two 1K resistors to ground.

When a pin that's set as INPUT is "floating" (it's not connected to anything) the value on it is "undetermined" and interrupt can trigger when a neighboring pin status changes, or even just magically by itself. The 1K resistors (called pulldown resistors) will make sure that pin is set to LOW when it's not connected using the jumper.

This circuit should put a stable 0V on Pin3 when switch is unpressed and 5V when it's pressed. You should be able to verify that using any voltage meter.

modified design from the question

If the issue persists then swapping the microcontroller on the Arduino is just one of the steps you need to perform. You would also need to burn a bootloader on the chip. It's not a hard procedure but it requires a second Arduino.

| improve this answer | |
  • Doing this there are no continuous interrupts. However, as soon as I remove the wire to connect it to another place where it should be it starts triggering again! – Foad Sep 23 '19 at 7:49
  • Can you draw your connections? I have problems picturing your design. Also use a voltage meter and check if there is a 5V after you put the jumper and resistor on the pin. – Filip Franik Sep 23 '19 at 7:50
  • added to the post – Foad Sep 23 '19 at 7:58
  • "...as soon as I remove the wire to connect it to another place where it should be it starts triggering again!" That makes sense. When the pin is not connected to anything, it begins floating again. – Duncan C Sep 24 '19 at 13:38

CMOS inputs "float" when not connected to anything, and will give semi-random values. You can either connect the pin to ground via a medium value resistor (1kΩ-10kΩ), or set the pin to INPUT_PULLUP mode.

You shouldn't move the interrupt pin connections around while the Arduino is running. As soon as you disconnect the wire from the input, it begins floating again, and can detect semi-random HIGH/LOW values.

If you use an external pull-down resistor, put a connector after the ground connection and move that connection, so the pull-down resistor is always connected to the pin.

If you use INPUT_PULLUP mode, you should not use a pull down or pull up resistor. This mode connects the pin weakly to +5V, which will hold it at a HIGH value when not connected to anything. You would then ground it to trigger an interrupt. In INPUT_PULLUP mode you can probably disconnect the wire from the interrupt pin without triggering interrupts.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.