I have connected a CIM motor to a Jaguar speed controller, powered by 12V battery. The jaguar is connected to an Arduino UNO via the signal and ground. Also, I have two switches connected to the Arduino, for forward and reverse of the motor.
In the code, for speed of the motor, I have set 90 as the mid point and 100 for forward and 80 for reverse. When I push the reverse button, the motor runs smoothly in the reverse direction at the set speed. However, the problem is, when I press the forward button, the motor runs seemingly
slower in the forward direction than the set speed. My logic here was, if I have set speeds in forward and reverse at +/- 10 from the mid-point, the motor should run at the same speed in the forward and reverse direction, but this is not happening.
I am pasting my code below. Any help would be much appreciated. Thank you!
Code:
#include <Servo.h>
int forwardPin = 2;
int reversePin = 4;
int motorPin = 10;
int fwdReading = 0;
int revReading = 0;
Servo myservo;
void setup()
{
TCCR1B = TCCR1B & 0b11111000 | 0x04; // PWM Freq. at 122Hz
pinMode (forwardPin, INPUT);
pinMode (reversePin, INPUT);
myservo.attach(motorPin);
myservo.write(90); // set servo to mid-point
}
void loop()
{
fwdReading = digitalRead(forwardPin);
revReading = digitalRead(reversePin);
if (fwdReading == HIGH)
{
myservo.write(100); // forward
}
else if (revReading == HIGH)
{
myservo.write(80); // reverse
}
else
myservo.write(90); // neutral
}