I have 75:1 Metal Gearmotor 25Dx54L mm HP with 48 CPR Encoder.
I’d tried to find whether the RPM at motor shaft is 130 rpm by using arduino code. The code as below. However, the result I got is RPM = 2.58 (in average).
Can you help me to find out why is not as spec?
// Define pin locations and delay time between each query
#define EncoderPinA 2
#define EncoderPinB 3
#define DELAY_TIME 1000 // dealy 1 second
// Using 75:1 Metal Gearmotor 25Dx54L mm HP with 48 CPR Encoder
//Key specs at 6 V: 130 RPM and 450 mA free-run, 130 oz-in (9.4 kg-cm) and 6 A stall.
#define Encoder_CPR 48
// Create a variable in memory that the interrupt code can access
// Also create the change value globally
volatile unsigned int EncoderPos = 0;
double dVal = 0;
// Initialize
void setup()
{
// Set input pin state for the line sensors
pinMode(EncoderPinA, INPUT);
pinMode(EncoderPinB, INPUT);
// Register a hardware interupt function for pin 2 (which is indexed by value 0)
// This function sets the EncoderEvent() function to be called whenever a line detector detects a change
attachInterrupt(0, EncoderEvent, CHANGE);
// Start serial communication
Serial.begin (9600);
}
// Program loop
void loop()
{
// Find the before and after value between the delay times
unsigned int OldPos = EncoderPos;
delay(DELAY_TIME);
unsigned int NewPos = EncoderPos;
// If an integer overflow occures, throw out the new value
if(abs(NewPos - OldPos) < 30000)
// number of counts per second
dVal = (double)(NewPos - OldPos) / (double)DELAY_TIME;
// Convert RPM of motor should be 130 RPM for 6V
double RPM= (dVal * 60) / Encoder_CPR;
// Print data
Serial.print("RPM: ");
Serial.println(RPM);
}
// Encoder event for the interrupt call
void EncoderEvent()
{
// Read for data and bit changes
// This is gray-code logic
if (digitalRead(EncoderPinA) == HIGH)
{
if (digitalRead(EncoderPinB) == LOW)
EncoderPos++;
else
EncoderPos--;
}
else
{
if (digitalRead(EncoderPinB) == LOW)
EncoderPos--;
else
EncoderPos++;
}
}