Use an Encoder

1. Get started with the 28BYJ-48 stepper motor
A stepper motor, also known as step motor or stepping motor, is a brushless DC electric motor that divides a full rotation into a number of equal steps. The motor's position can then be commanded to move and hold at one of these steps without any position sensor for feedback (an open-loop controller), as long as the motor is carefully sized to the application in respect to torque and speed.

An introduction to the 28BYJ-48 Stepper Motor can be found in this webpage. (if the webpage is not active anymore, find the printed PDF version here).

Make the hardware connection as follows. Use the Elegoo DC-DC module to power up your system.





Load the this script to your Arduino board to repeat the work in the demonstration video below.



2. Encoders

The Encoders were ordered from here:

https://www.amazon.com/gp/product/B06XQTHDRR/ref=ppx_yo_dt_b_asin_title_o03_s04?ie=UTF8&psc=1

Key parameters of this encoder:

One round number of pulse: 20 Working voltage: 5V The rotary encoder can count the number of pulse output during rotation in the positive direction and reverse direction through the rotation and this rotation counts are not limited. With the key on the rotary encoder, you can reset to the initial state, that is, counting from 0. The Material of Knob Cap: aluminium alloy The Specification of Knob Cap: diameter: 15mm/ 0.59in; height: 16.5mm/ 0.65in.



Before start working with the encoder and the Arduino board, read this tutorial first.

https://howtomechatronics.com/tutorials/arduino/rotary-encoder-works-use-arduino/



When the detectors A or B are on the top of the block, it outputs logic HIGH pulses, otherwise it outputs LOW. If the rotor moves clock-wise, then before A changes its state (from low to high or from high to low), A and B are in the same state. If it rotates counter clock-wise, right before A changes its state, A and B are in different states. We can use this simple algorithm to code up a scirpt in Arduino to tell the direction the rotor rotates.



Rotary Encoder Arduino Example:

Make the following hardware connections:

Output A - Pin 6 (Arduino)
Output B - Pin 7 (Arduino)
Button Pin - Null (Keep it float for the first example)
VCC - 5V (Arduino)
GND - GND (Arduino)



Load the code to your Arduino board. Open the Serial Monitor to check the positions of the encoder.





Now, let's add the stepper motor back to the breadboard and use the encoder to control the movement of the stepper motor precisely.

The code is not provided here but you should be able to make your own based on the code provided in the first two examples.



-----------------------------------

Task 1: Repeat section 1. (50 points)
Task 2: Repeat section 2. (50 points)