element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Rotary Encoders - Part 3: Capturing Input on an Arduino
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 13 Jul 2015 9:29 AM Date Created
  • Views 3132 views
  • Likes 6 likes
  • Comments 2 comments
  • rotary_switch
  • rotary_encoder
  • arduino_uno
  • arduino
Related
Recommended

Rotary Encoders - Part 3: Capturing Input on an Arduino

Jan Cumps
Jan Cumps
13 Jul 2015

I've removed the rotary encoder from the scroll button of a defect mouse. Let's see how we can use that in a microcontroller design.

In post 1, I wired up the electronics.

In part 2, I'm capturing the encoder's info on a Cypress PSoC4.

This time, I'm checking an existing example on an Arduino UNO.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

The Firmware

 

Well, that was easy. I found a number of examples on http://playground.arduino.cc/Main/RotaryEncoders.

I bet the majority of the projects on that page will work. I chose rafbuff's implementation because it was clean code and uses interrupts (several examples on that page do that, but you have to make a choice).

 

It's less than 100 lines of code, provides additional in-software debouncing and doesn't require an external library.

And it works straight away.

 

image

The source is available on http://playground.arduino.cc/Main/RotaryEncoders.

Search for rafbuff.

If you think that I should have tried another implementation, post it in the comments.

 

Wiring the Hardware

 

Look back at my first post to check how to components are wired up.

Then connect the encoder with the board.

Ground to Ground, 5V to 5V,

PINA to Digital 3, PINB to Digital 2 (that's different than the code comments. My setup counted backwards when I wired it up as written in the code, but I used a different encoder).

 

Connect the Arduino, execute the program and open the Serial Monitor.

The count is logged to the monitor on every spin.

 

Content
Part 1: Electronics
Part 2: Capturing Input on Cypress PSoC4
Part 3: Capturing Input on an Arduino
Part 4: Capturing Input on a Texas Instruments Hercules LaunchPad with eQEP
Part 5: Capturing Input on an FPGA
Real World Application: Hercules LaunchPad and GaN FETs: Control Big Power with a Flimsy Mouse Scroll Wheel
  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 6 years ago

    I've fixed the embedded video link

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 10 years ago

    Great Arduino link.

     

    They do a good job of explaining the code and how they detect and use it.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
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