21, Feb, 2019

ARDUINO with 1000 P/R OMRON ROTARY ENCODER

arduino omron encoder connection

How to set up arduino with rotary encoder

Please refer our previous articles for the basics and connection details (install arduino, add libraries etc)

OMRON Encoders connection diagram (PIN Details)

You need to download and install encoder library (Encoder.h), this library can be downloaded from: https://drive.google.com/file/d/0B-H_CXR7-MD9WG5GS3dHWExVRDQ/view?usp=sharing

Connect Encoder outputs to PIN 2, 3

ARDUINO PROGRAM

#include <Encoder.h>
int linearlength = 500;
int count = 5;
int i = 0;
int red = 7;
long relaypoint;
Encoder myEnc(2, 3);  // Encoder Connection PINs
void setup()

{
  Serial.begin(9600);
  pinMode(red, OUTPUT);  // Pin 7 for OUTPUT
}
long oldPos  =0;


void loop()

{
   digitalWrite(red,LOW);
   long newPos = myEnc.read()/10; // adjust the encoder sensitivity (pulses/10)

 while (newPos > oldPos) 

{                      //for clock wise rotation sensing
    oldPos = newPos;
    relaypoint = oldPos;
    Serial.println(relaypoint);
     if (relaypoint % linearlength == 0)
    {
    // linear distance reached
    digitalWrite(red,HIGH);
    delay(3000);
    digitalWrite(red,LOW);
     i = i+1;
    if (i >= count){
   // Serial.println(“Completed for given quanity”);
    }
}

}
}

When you add the wheel  (normally 60mm dia), you need to include the perimeter value (2*3.14*r) to calculate the linear travel

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>