Hello,
I am doing a project in which I am using High torque High precision Encoder DC geared Motor (12V 300RPM). I have to code the DC motor to run at a specific speed using Arduino Mega 2560. This is my first time experience with Arduino and have very little knowledge of coding. I have been able to run my motor at its full speed using the basic example in encoder library.
/* Encoder Library - Basic Example
*
* This example code is in the public domain.
*/
#include <Encoder.h>
// Change these two numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder myEnc(5, 6);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("Basic Encoder Test:");
}
long oldPosition = -999;
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
}
The issue is I am unable to control the speed of the motor. I want my motor to run at a specified speed in either forward or backward direction until I change the speed, direction or stop the motor. I have a RMCS-2301 motor driver but I did not use it while running my motor at full speed. Thus, I am not vey sure whether I am required to use it for this purpose. Eventually I have to control 4 motors but for now I want to get it right for one motor and then proceed further. I would really appreciate any help regarding how to control the speed of my motor.
Motor Driver: https://robokits.download/downloads/RMCS-2301.pdf
Thanks in advance.