Finally, for the debouncing switch, we can press the button of the shaft to give a LOW signal, which will make the counter 0 and again return to the HIGH state simultaneously. When the direction is counterclockwise IN2 and IN4 will be set HIGH, while IN1 and IN3 will be set LOW. In terms of direction, when we rotate clockwise, IN1 and IN3 are set HIGH, while IN2 and IN4 will be set LOW. When we rotate the knob, the enA and enB pins will take the value of the counter variable and speed up accordingly. Under void setup(), input and output mode is set for each defined pin, and the lastStateCLK variable stores the current value of the CLK pin. To check the current direction of rotation, the string currentDir is used, and to debounce a switch lastButtonPress variable is used. Secondly, the currentStateCLK and lastStateCLK variables hold the CLK output state and are used to determine the direction of rotation. Firstly, the counter variable which is varying and changes each time the knob of the rotary Encoder is rotated one click. Then the pins connected to IN1, IN2, IN3, IN4, enA, and enB of L298N are also defined. At first, the Arduino pins that are connected to CLK, DT, and SW pins of the Encoder are defined. We will first define the pins of the rotary Encoder and L298N motor driver in Arduino IDE according to the connection. How to control rpm of 12V motor with Encoder and L298N? To prevent that from happening, remove the jumper near the 12V pin, which will then lower the high voltage to 5V by the onboard regulator. Remember that we must be very cautious while giving power supply in the 12V pin any input voltage greater than 12V will damage the board. There are also two enable pins, ENA and ENB, used to control the rpm of each of the two motors.įinally, the module has a 12V pin and a ground pin, GND to power up the module, and once turned ON, it can also power up any device from its 5V pin and GND. It also has four input pins, IN 1, IN 2, IN 3, and IN 4, that take input signals from the microcontroller and direct the motor as programmed. The four output pins, OUT 1, OUT 2, OUT 3, and OUT 4, are used to control the direction of the motors. It has two output terminals on either side to control two motors. L298N motor driver is a simple module used to control the rpm and direction of the motor. Therefore we can program the Arduino Uno by reading the position and rotation direction of the Encoder. If the Encoder were rotating anticlockwise, the value would be the same for output A and B at any particular step. In that case, the output value will be 0 in the output B signal, which means the Encoder is rotating clockwise. Suppose the output value is 1 at a certain step in the output A signal. Any of the two output pins, A and B, can determine the rotation position. Two square wave signals will get generated as output which will be 90 degrees out of phase from each other. When the disk starts rotating, the two output contact pins A & B will begin making contact with the common pin C. The Encoder has a disk with evenly spaced contact zones connected to the common pin C and two separate contact pins, A and B, as shown in the figure. Now let's look at how the square wave pulses are generated. An incremental encoder sends a fixed number of pulses every turn of the Encoder, usually a square wave.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |