Reading from the Encoder

The connections

  • Encoder A output → DO pin 4

  • Encoder B output → DO pin 5

#define ENCA 4 // Yellow
#define ENCB 5 // White

void setup() {
  Serial.begin(9600);
  pinMode(ENCA,INPUT);
  pinMode(ENCB,INPUT);
}

void loop() {
  int a = digitalRead(ENCA);
  int b = digitalRead(ENCB);
  Serial.print(a*5); 
  Serial.print(" ");
  Serial.print(b*5);
  Serial.println();
}

output of this will be like

With Classes

Control the motor

To construct the feedback control loop, you must:

  1. Define a target position

  2. Compute the error e(t) as the difference between the measured position and the target

  3. Compute a control signal u(t)

The code below shows the implementation I used for the Arduino.

Last updated