Fu tu r e El ec tr on ic (Incremental Encoder) s Shaft Rotation Sensor This rotation sensor or incremental encoder (unlike potentiometer) has no limit for number of counting. It can also detect clockwise and counter clockwise rotation and thatʼs why it has 2 pins (SIA and SIB) for detecting rotation. Basically, it translates the rotary motion into a sequence of pulse signals. By comparing the square wave generated from each of the two pins you can determine the direction of rotation (as shown in Figure below) and by counting the number of pulses you can determine both the rotation angle and the RPM of the rotating shaft. A reset button is provided to reset the counter to zero state when needed to start counting again. w w w . f u t - e l c t r o n i c s . c o m Page 1 s on ic tr ec El Features Fu tu r e Operating Voltage: 3- 5V NOF pulses per Cycle: 15 pulses NOF Cycles: unlimited Reset Button: reset counts to Zero Clockwise and counter clockwise rotation direction detection Dimensions: 32 x 15 mm PIN Definition SIA: Signal A (pulse) SIB: Signal B (pulse) SW: State of reset pin (0 or 1) GND: Ground signal VCC: voltage (3 - 5V) w w w . f u t - e l c t r o n i c s . c o m Page 2 Arduino Connection Arduino s Sensor tr on ic SIA ----------------------------> D2 SIB----------------------------->D3 SW----------------------------->NC GND--------------------------->GND VCC---------------------------> 5V El #define PinA 2 #define PinB 3 ec Arduino Code Fu tu r e unsigned long time = 0; long count = 0; long num = 0; void setup() { Serial.begin(9600); pinMode(PinA,INPUT); pinMode(PinB,INPUT); attachInterrupt(0, blinkA, LOW); attachInterrupt(1, blinkB, LOW); w w w . f u t - e l c t r o n i c s . c o m Page 3 time = millis(); } on ic tr ec El void blinkA() { if ((millis() - time) > 3) count ++; time = millis(); } s void loop() { while (num != count) { num = count; Serial.println(num); } } Fu tu r e void blinkB() { if ((millis() - time) > 3) count --; time = millis(); } w w w . f u t - e l c t r o n i c s . c o m Page 4