Things used in this project

Hardware components:
Pmod enc  05798.1456866459.1280.1280
Digilent Pmod ENC
A000066 iso both
Arduino UNO & Genuino UNO
Software apps and online services:
Ide web
Arduino IDE


Pmod ENC and Arduino Uno Fritzing file
Fritzing file displaying the connection of the Pmod ENC to the Arduino Uno.
Pmod ENC and Arduino Uno Fritzing Image
Fritzing image displaying the connection between the Pmod ENC and Arduino Uno.
Pmodenc arduinouno bb sk00fs681e


Pmod ENC and Arduino Uno CodeArduino
Using this code will display the direction of rotation of the encoder axis as well as using the pushbutton to memorize the state of a counter in a variable.
* Test of the Pmod 
* Description: Pmod_ENC
* The direction of rotation of the encoder axis is displayed in the serial monitor.
* Pressing the push button memorizes the state of a counter in a variable
* Material
* 1. Arduino Uno
* 2. Pmod ENC 

// Affectation of pins
#define A 2 // output A of the encoder
#define B 3 // output B of the encoder
#define BTN 4 // button of the encoder

volatile boolean rotation;
volatile boolean sens;
int compteur = 0;
int validation = 0;

// Programme d'interruption
void Interruption ()
 if (digitalRead(A)==HIGH)
  sens = digitalRead(B); // Clockwise
  sens = !digitalRead(B); // anticlockwise
 rotation = HIGH;
void setup()
 attachInterrupt (0,Interruption,FALLING); // interruption on falling edge of output A
 Serial.begin(9600); // initialization of the serial monitor
 pinMode(A,INPUT); // configuration of pin 2 in input
 pinMode(B,INPUT); // configuration of pin 3 in input
 pinMode(BTN,INPUT); // configuration of pin 4 in input

void loop()
 if (rotation==HIGH) // If detection of rotation
  if (sens==HIGH) // if clockwise
   compteur++; // increase counter 
   compteur--; // decrease counter
  rotation = LOW;
  Serial.print ("Compteur="); // write counter variable
  Serial.println (compteur);
  if (digitalRead(BTN)==HIGH) // if the button have been activate
  delay(200); // debounce
  Serial.print ("Validation="); // write validation variable
  Serial.println (validation);


Martha Migliacio
46 projects • 2 followers
Thanks to Lextronics.


Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Add projectSign up / Login