element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum read encoder (motor axis speed)
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 5 replies
  • Subscribers 403 subscribers
  • Views 2296 views
  • Users 0 members are here
Related

read encoder (motor axis speed)

Former Member
Former Member over 13 years ago

hello,

 

I have an DC motor which is provided with an encoder, this encoder should give a number of pulses per rotation, the encoder provides four pulses per rotation. The maximum motor speed is 1500rpm so this is 25 Hz. The encoder gives 100 pulses a second on this speed.

 

My question is, does anyone have a simple program to read these pulses on the arduino uno? Do I need to read those pulses with a interrupt? How do I do it? I don't have to know the position and the direction of the axis, I only need te speed of it.

 

When I have the speed of the axis in pulses/second I use the speed for a PID regulator on the arduino controller.

 

thx

  • Sign in to reply
  • Cancel

Top Replies

  • Catwell
    Catwell over 13 years ago +1
    Jeroen, This is easy, start here: http://arduino.cc/playground/Main/RotaryEncoders What is the current draw on the motor? Cabe http://twitter.com/Cabe_e14
Parents
  • DAB
    0 DAB over 13 years ago

    Hi Jeroen,

     

    Most encoders use a byphase Quadrature encoding so you get both position increments and direction of rotation.  You can use a simple circuit to convert it to pulse and direction inputs.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 13 years ago in reply to DAB

    Is the encoder an electrically separate part of the motor assembly?  I assume it requires 4 wires: Vcc, Ground, S1, and S2.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 13 years ago in reply to billabott

    thx for the reply!

     

    the encoder is a 4 wire encoder, Vcc, GND, A-,B- chanal.

    I think that this program wil count the pulses every half a second.

     

    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);

     

      }

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 13 years ago in reply to billabott

    thx for the reply!

     

    the encoder is a 4 wire encoder, Vcc, GND, A-,B- chanal.

    I think that this program wil count the pulses every half a second.

     

    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);

     

      }

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube