ROTARY ENCODER CODE...

hey, i have a favor to ask... is there anyone of u know how to program rotary encoder to identify the RPM only?? the product that im use is as follow http://www.qrbiz.com/product/1048921/Rotary-Encoder.html

thanx....

Did you try any of the rotary encoder examples in the Arduino playground?

It's easy, use the mills() function and count to 12,100,1024 etc however many counts per rotation the encoder is and save the number of mills() in a long variable. rotate it 360 again and subtract the two millis() and you will get the time it took to complete one rotation.

It's easy, use the mills() function and count to 12,100,1024 etc however many counts per rotation the encoder is and save the number of mills() in a long variable. rotate it 360 again and subtract the two millis() and you will get the time it took to complete one rotation.

im still blur about it, would u mind to share with me the code?? thank you...i really appreciate it..

Did you try any of the rotary encoder examples in the Arduino playground?

yes, i did try on the example, but it seems like all goes to measure position and the rotation whether clockwise/anticlockwise.. i dont know how to relate the code pulses with what i want to obtain which is the "revolution per minute"..

Is this measuring something that spins at a steady rate?

Is this measuring something that spins at a steady rate?

i would like to measure the RPM of a vehicles tire (robot) on the surface....

You will receive multiple pulses per rotation, yes? You know how many pulses that is.
So measure the elapsed time using millis() for 1/10 of those, or 1/4 of those, and do a little math.
Say you had 100 pulses, which is 1/10 of the pulses of the pulses in complete rotation, and they occurred in 25mS.
A little math, and some unit conversions, and you have an answer:
RPM = (100 pulses/25mS) * (1 Revolution/1000 pulses) * (1000mS/S) * (60S/M) = 2640R/M or 2640 RPM

Make sense? Fill in the details for your encoder and how long of a time span you want to measure the pulses over.

You will receive multiple pulses per rotation, yes? You know how many pulses that is.
So measure the elapsed time using millis() for 1/10 of those, or 1/4 of those, and do a little math.
Say you had 100 pulses, which is 1/10 of the pulses of the pulses in complete rotation, and they occurred in 25mS.
A little math, and some unit conversions, and you have an answer:
RPM = (100 pulses/25mS) * (1 Revolution/1000 pulses) * (1000mS/S) * (60S/M) = 2640R/M or 2640 RPM

const int Encoder_Pin = 2; // output of encoder to interrupt #0, pin 2 of arduino

int Encoder_Count = 0;
long Time1 = 0;
long Time2 = 0;
long Time3 = 0;

void setup() 
{
  Serial.begin(9600);
  attachInterrupt(0, Count_Pulses, FALLING); //attach interrupt to encoder pin
}

void Count_Pulses() 

{
  //this is the function that runs every time pin 2 
  //switches from high to low
  Encoder_Count++;
}

 
void loop()

{
  Time1 = millis();
  Time3 = Time1 -= Time2;
 
  if (Time3 >= 500)
  {
   Time2 = millis ();
   int PulsSpeed = Encoder_Count;
   Encoder_Count = 0;
   Serial.println(PulsSpeed);
  }

}

ok, so i jz need to determine the pulses as example above from encoder before proceed to calculation to determine the RPM right??
thanks crossroads...

Tom@Jerry:
i would like to measure the RPM of a vehicles tire (robot) on the surface....

Just out of curiosity, why do you want to measure that? I would have thought that measuring distance traveled would typically be more useful.

Just out of curiosity, why do you want to measure that? I would have thought that measuring distance traveled would typically be more useful.

my project needs to measure the speed of the motor using encoder,so that i can plot the velocity of the robot at any points. or is there any method that i can use to measure motor speed?