Encoder normally is used for PID algorithm.  In this tutorial, we will use Arduino MEGA2560 to read the Position of 520 DC motor using the encoder.

Connection:

Right Encoder OSOYOO Basic Board for Arduino
White wire(GND) GND
Yellow wire(C1) D52
Green wire(C2) D53
Blue wire(VCC) 5V
Left Encoder OSOYOO Basic Board for Arduino
White wire(GND) GND
Yellow wire(C1) D50
Green wire(C2) D51
Blue wire(VCC) 5V

Some module might have reversed V Power/G-GND line. If following code does not work, please switch Yellow line to 5V and White Line to Arduino GND.

Software Download:
https://osoyoo.com/driver/v5car/encoder.zip

Once you load the code into Arduino IDE, open the serial monitor in the upper-right corner.

Now install a wheel onto the DC gear motor and make it can be rotated by hand. Then rotate the wheel for 360 degree and stop. You will see the serial monitor screen will show:

Position: 1
Position: 2
….
Position: 148
Position: 149
Position: 150

The last line shows Position 151 . This means when you rotate the motor to 360 degree, the hall sensor has generated 151 pulses. so my motor has about 150 pulses per rotation.