title: How to Calculate RPM 12V DC Motor 100rpm w/Encoder
body: <p>I have tried to find pulse this way in arduino uno. You can see the coding I have tried and this is also a sample image of the motor encoder.</p>
  
  <p><a href="https://i.stack.imgur.com/bvdPQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bvdPQ.png" alt="enter image description here"></a></p>
  
  <pre><code>//The sample code for driving one way motor encoder
  const byte encoder0pinA = 2;//A pin -&gt; the interrupt pin 0
  
  const byte encoder0pinB = 4;//B pin -&gt; the digital pin 4
  
  byte encoder0PinALast;
  
  int duration;//the number of the pulses
  
  boolean Direction;//the rotation direction 
  
  
  void setup()
  
  {  
    Serial.begin(57600);//Initialize the serial port
  
    EncoderInit();//Initialize the module
  }
  
  void loop()
  
  {
  
    Serial.print("Pulse:");
  
    Serial.println(duration);
  
    duration = 0;
  
    delay(100);
  
  }
  
  void EncoderInit()
  
  {
  
    Direction = true;//default -&gt; Forward  
  
    pinMode(encoder0pinB,INPUT);  
  
    attachInterrupt(0, wheelSpeed, CHANGE);
  
  }
  
  void wheelSpeed()
  
  {
  
    int Lstate = digitalRead(encoder0pinA);
  
    if((encoder0PinALast == LOW) &amp;&amp; Lstate==HIGH)
  
    {
  
      int val = digitalRead(encoder0pinB);
  
      if(val == LOW &amp;&amp; Direction)
  
      {
  
        Direction = false; //Reverse
  
      }
  
      else if(val == HIGH &amp;&amp; !Direction)
  
      {
  
        Direction = true;  //Forward
  
      }
  
    }
  
    encoder0PinALast = Lstate;
  
    if(!Direction)  duration++;
  
    else  duration--;
  }
  </code></pre>
  
  <p>I already know pulse, but i don't know how to calculate the rpm of this motor. 
      How to calculate rpm already known pulse?
      Can anyone help me find this way out, I would be very grateful if anyone wants to help me.</p>