volatile unsigned int temp, counter = 10000; //This variable will increase or decrease depending on the rotation of encoder void setup() { Serial.begin (9600); pinMode(2, INPUT_PULLUP); // internal pullup input pin 2 pinMode(3, INPUT_PULLUP); // internal pullup input pin 3 //Setting up interrupt //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin no 2 on most Arduino. attachInterrupt(0, ai0, RISING); //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin no 3 on most Arduino. attachInterrupt(1, ai1, RISING); } void loop() { // Send the value of counter if changed if( counter != temp ){ Serial.println (counter); temp = counter; } } void ai0() { // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH if(digitalRead(3)==LOW) { counter++; }else{ counter--; } } void ai1() { // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH if(digitalRead(2)==LOW) { counter--; }else{ counter++; } }