Arduino Projects

Interface Rotary Encoder With Arduino, How It Works, Codes

This reader explains how to use a rotary encoder with Arduino. It includes information on how the rotary encoder works, the code needed to use it, and the schematic for wiring it up. You can watch the following video or read the written tutorial below.

Overview

Rotary encoder modul

A rotary encoder is an input device that detects the amount of rotation of a shaft or dome. It is commonly used in robotics and machine control. The encoder can be connected to a microcontroller using an I2C or SPI interface, allowing it to be used to control motors and other devices.

There are two types of rotary encoders 

  1. Absolute: Absolute encoders have a unique code for each position of the shaft, so they can keep track of the absolute position
  2. Incremental: Incremental encoders only keep track of changes in position, not the absolute position.

The absolute encoder provides us with the actual position of the knob in degrees while the incremental encoder declares how many increments the shaft has moved.

The rotary encoder used in this tutorial is of an incremental class.

Rotary encoder Vs Potentiometer Which one is better

Rotary encoders and potentiometers are two common ways to measure position or angle. So, which one is better?

There are pros and cons to each method. Rotary encoders are typically more accurate than potentiometers, but they can be more expensive. Potentiometers are less expensive, but they are not as accurate. Here are some things to consider when deciding between rotary encoders and potentiometers:

  1. Accuracy: If you need high accuracy, go with a rotary encoder. If you don’t need high accuracy, a potentiometer will suffice.
  2. Cost: Rotary encoders are more expensive than potentiometers.
  3. Easy of use: Rotary encoders can be more difficult to use than potentiometers.
  4. Environment: If your application will be in a difficult environment, go with a rotary encoder. Potentiometers can be more susceptible to dust and dirt.

In the end, it’s up to you to decide which method is best for your application. Consider the factors above and make the best decision for your needs. How Rotary Encoders Work

Rotary Encoder Pinout

The pinouts of the rotary encoder are as follows:

Rotary-Encoder-With-Arduino
IMG Source – lastminuteengineers.com

Description:

Pin Name Description
GND Connected to GROUND
+ Connected to +5V
SW The output of the internal button of the rotary encoder when pressed
DT Contact A output or DATA
CLK Contact B output or CLOCK

Note: One of the DT or CLK pins must be connected to the interrupt of Arduino Uno, or both of the DT and CLK are attached to the interrupt pin.

Rotary Encoder Features and Specifications

  • 360º free rotation.
  • 20 steps or cycles per revolution
  • Incremental type encoder
  • Work on low voltages
  • Maximum operating temperature: 0°C to + 80°C
  • Easy interface
  • Long life.

Applications

  • Security systems.
  • Motors
  • CNC
  • 3D Printer
  • Robotic arms
  • Vending machines.
  • Industrial machines.
  • Engineering systems.
  • Measuring instruments.
  • Hobby projects.

Wiring Diagram Rotary Encoder With Arduino

Interface Rotary Encoder With Arduino, How It Works, Codes

Source Code

Code for Reading Rotary Encoder With Arduino

Code for Understanding Rotary Encoder Position

Here’s a complete Arduino code where the encoder value is printed out of the serial port in IDE

Using Interrupts

Rotary encoders can be used with interrupts to provide more accurate speed and position measurements. Interrupts are signals that tell the processor to stop what it is doing and attend to something else. Hardware interrupts are typically used for time-critical tasks like handling keyboard input or playing sound. Software interrupts are typically used for less time-critical tasks like updating the screen or checking for new data.

Rotary encoders can use either type of interrupt. Hardware interrupts are more accurate but take longer to process. Interrupts can be used to measure the time between pulses

Here’s the sketch that documents the use of the interrupts while reading a rotary encoder.

Did this writing help you understand rotary encoders? If it did, kindly leave a comment down!

Related Articles

Leave a Reply

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

Ad
Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker