Wheel Encoders for DFRobot 3PA and 4WD Rovers SKU:SEN0038


This encoders are designed for DFRobot 3PA and AWD Rovers. It can give you the rotation degree of the wheels. Encoder uses non-contact method to convert the angular displacement signals. Best fit with Micro DC Geared Motor. It includes encoders, plastic tube, paper-mediated gasket etc.


Sample Code

// #
// # Editor     : Lauren from DFRobot
// # Date       : 17.01.2012

// # Product name: Wheel Encoders for DFRobot 3PA and 4WD Rovers
// # Product SKU : SEN0038

// # Description:
// # The sketch for using the encoder on the DFRobot Mobile platform

// # Connection for Uno or other 328-based:
// #        left wheel encoder  -> Digital pin 2
// #        right wheel encoder -> Digital pin 3
// # Note: If your controller is not 328-based, please check https://www.arduino.cc/en/Reference/AttachInterrupt for proper digital pins.

#define LEFT 0
#define RIGHT 1

long coder[2] = {
int lastSpeed[2] = {

void setup(){

  Serial.begin(9600);                            //init the Serial port to print the data
  attachInterrupt(LEFT, LwheelSpeed, CHANGE);    //init the interrupt mode for the digital pin 2
  attachInterrupt(RIGHT, RwheelSpeed, CHANGE);   //init the interrupt mode for the digital pin 3


void loop(){

  static unsigned long timer = 0;                //print manager timer

  if(millis() - timer > 100){
    Serial.print("Coder value: ");
    Serial.print("[Left Wheel] ");
    Serial.println("[Right Wheel]");

    lastSpeed[LEFT] = coder[LEFT];   //record the latest speed value
    lastSpeed[RIGHT] = coder[RIGHT];
    coder[LEFT] = 0;                 //clear the data buffer
    coder[RIGHT] = 0;
    timer = millis();


void LwheelSpeed()
  coder[LEFT] ++;  //count the left wheel encoder interrupts

void RwheelSpeed()
  coder[RIGHT] ++; //count the right wheel encoder interrupts

Assembly Guide

Step1: FIT0029_AS_01.jpg

Step2: FIT0029_AS_02.jpg

Step3: FIT0029_AS_03.jpg



Serial monitor

Q&A Some general Arduino Problems/FAQ/Tips
Q The feedback value is full that the Serial monitor is always printing value around 25903 and 25344, no matter of the motor running or not.
A The first parameter in the interrupt function ' attachInterrupt ' means the interrupt number that is just number 0 and 1, not the interrupt pin number. read more
A For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get Wheel Encoders for DFRobot 3PA and 4WD Rovers (SKU:SEN0038) from DFRobot Store or DFRobot Distributor.

Category: DFRobot > Sensors & Modules > Sensors > Motion Sensors

category: Product Manual category: SEN Series category: Motors-Servos category: source

Turn to the Top