Problem with encoder readings. Using Arduino Uno and Motor Shield v2.3


I have this sensor attached to my mobile robot and using Arduino Uno along with Motor Shield v2.3.

The problem is that if one of the wheels is not turning and the other is, I get some values from the encoder attached to the wheel that is not turning due to the motion of the other wheel that is turning.

I have tried also to connect the Motor shield to the Arduino using 4 pins (+5V, GND, A5, A4) instead of putting it on top of the Arduino, but this gives the same result

However I disconnected the Motor Shield from the Uno and directly supplied voltage to the motors and
then I was getting good readings from the encoders, i.e one wheel turning did not affect the values given by the encoder from the other wheel (no coupling).

What do you think might be causing this?

Here is the code that I am using:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

Adafruit_DCMotor *M1 = AFMS.getMotor(1);
Adafruit_DCMotor *M2 = AFMS.getMotor(2);
// Loop time for calculating velocity
#define DELAY_TIME 10 // In ms
// Define physical constants of the wheel for wheel encoding
#define WHEEL_TICKS 20          // The number of 'ticks' for a full wheel cycle
// Variables for storing the calculated velocity
double RangVel;
double LangVel;

// Variables for storing position info
long OldLPos;
long NewLPos;
long OldRPos;
long NewRPos;
// Volatile variables that can be changed inside of interrupt functions
volatile unsigned int RightEncoderPos = 0;
volatile unsigned int LeftEncoderPos = 0;
double LdVal = 0;
double RdVal = 0;
void setup()
  attachInterrupt(0, LeftEncoderEvent, CHANGE);  //INT0, pin 2
  attachInterrupt(1, RightEncoderEvent, CHANGE); //INT1, pin 3
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);

void loop()
    Serial.print("Left Velocity: ");
    Serial.print("Right Velocity: ");

void GetSpeeds()
	OldLPos = LeftEncoderPos;
        OldRPos = RightEncoderPos;
	NewLPos = LeftEncoderPos;
        NewRPos = RightEncoderPos;
	LdVal = ((double)(NewLPos - OldLPos) / (double)DELAY_TIME) * 1000.0;
	RdVal = ((double)(NewRPos - OldRPos) / (double)DELAY_TIME) * 1000.0;
	LangVel = LdVal*2*3.14 / (double)WHEEL_TICKS;
        RangVel = RdVal*2*3.14 / (double)WHEEL_TICKS;
void RightEncoderEvent()


void LeftEncoderEvent()

Thanks in advance

I would suggest you to double check the wiring and make sure no interference is affecting the sensors.
Have you tried switching the working motor with the 'not-working' motor?

The interference, if it is interference, will be from the motors and motor drivers,
so make sure to run encoder cables well away from the motors/drivers.

Add 2k2 pull up resistors to each encoder pin (the internal pullups are too weak
for a noisy environment like a robot).