int state = 1; int previousstate = 1; unsigned long lastInterrupt; void setup() { Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(2),buttonPressed,CHANGE); } void loop() { //to prevent printing to the serial output 3 times if (previousstate != state){ Serial.println(state); previousstate = state; } } void buttonPressed() { //The millis is to solve the button glitching. if(millis() - lastInterrupt > 20) // we set a 10ms no-interrupts window { state = !state; lastInterrupt = millis(); //if you call a serial.println overhere the output on the second change will output 3 times } }