Close

Step 1 - Encoder

A project log for DC Motor Speed Control with PID

In this project it is aimed to speed control a standard Pololu DC motor with encoder using software based PID controller.

ozan-enginogluOzan Enginoglu 05/23/2016 at 12:430 Comments

In this step, it is aimed to connect the encoder (just encoder not the dc motor) to the Arduino and check if it is functioning properly. We know that the encoder output for the gearbox shaft's only one turn should return 1920 so we will be checking that manually by rotating the shaft of the motor by hand.

Encoder

Luckily, pin diagram of the encoder is given on the pololu web site as shown in the table below.

ColorFunction
Redmotor power (connects to one motor terminal)
Blackmotor power (connects to the other motor terminal)
Greenencoder GND
Blueencoder Vcc (3.5 - 20 V)
Yellowencoder A output
Whiteencoder B output

Motor power pins won't be used in this step but the other four pins are necessary for the encoder to function properly. Encoder GND and Vcc pins are used to power encoder circuit and encoder A and B pins are used to get feedback from the encoder. Green encoder GND will be connected to Arduino's ground pin and Vcc pin will be connected to Arduino's +5V regulated voltage output which is within the range (3.5 V - 20 V).

While connecting Encoder Pins A and B, it is important to select the pins that can be used for interrups. The reason for using interrupt pins is that Arduino should be able to get the feedback data from the encoder as soon as it changes. If the interrups are used Arduino will be able to stop whatever it's doing at that moment and get the encoder feedback first and continue. After a short search, i was able to find the table shown below.

BoardDigital Pins Usable For Interrups
Uno, Nano, Mini, other 328-based2, 3
Mega, Mega2560, MegaADK2, 3, 18, 19, 20, 21
Micro, Leonardo, other 32u4-based0, 1, 2, 3, 7
Zeroall digital pins, except 4
MKR1000 Rev.10, 1, 4, 5, 6, 7, 8, 9, A1, A2
Dueall digital pins

In this project I'm using Arduino Mega2560 so the pins i can use are 2, 3, 18, 19, 20, 21. Among these I preferred 18 and 19. So I connected encoder output A to digital pin 18 and output B to digital pin 19.

Pin connections of the encoder are shown in the Figure given below. As can be seen in the figure, motor terminal connections are intentionally left blank.

Encoder Connections

Discussions