Encoder with Arduino: Rotary Encoder, Absolute Encoder, Incremental Optical Encoder Encoder with Arduino

Содержание

An encoder is an electromechanical feedback device that is used in many industries to provide information about position, count, speed and direction. In the most basic terms, an encoder regardless of the type senses position, direction, speed or counts. Encoder will use motion over variety of technologies and translated into electrical signals. That signal is sent back to a controlling device such as plc or Arduino, or any other controller board, and is interrupted meaning scaled, to represent a value that will then be used in the program.

In this article, we will talk about the encoder in detail. I will explain different types of the encoder. In the end, I will share with your some project ideas with connection diagrams and Arduino codes explained.

Amazon Purchase Links:

Other Tools and Components:

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Encoder technologies:

Some of the technologies involved in encoders are:

  • Magnetic
  • Mechanical
  • Resistive
  • Optical

Optical is most widely used encoder motion translating technology.

Types of encoders:

There are different types of encoders

Incremental optical encoder:

This type of encoder use a beam of light that passes through a disk that has opaque lines in a specific pattern somewhat like a spokes of wheel on the other side of the disk is a photo sensing device that will interpret the light based on the pattern on the disk, picture a shatter blocking and unblocking the light. The pulses of light are then converted to an electrical signal to send back to the processor, through the encoder output. Incremental encoders provide steady stream of high and low pulses that indicate the movement from one position to the next. The encoder does not indicate any specific position only the position is changed.

Absolute encoders:

Absolute encoder on the other hand indicates both the position and location of that position relative to the shaft rotation. The encoder provides a unique word or bit for each incremental rotation. Absolute encoders are the best choice for applications where exact positions to be known. It can be used in flood gate control, telescopes, cranes or valve positioning. It used magnetic or optical sensing technology. In optical encoders uses beam of light to produce a signal. While in magnetic encoders relies on alternating positive and negative magnetic pole.

Encoder

Basic element of optical increment encoder is a beam of light produced by led passes through transparent disk with radial opaque lines. When the light passes through opaque lines the sensor responds to the light by producing sinusoidal optical wave which is converted in square wave which is series of high and low pulses. This signal is then transfer to the controllers.

In absolute encoder can be used in pitch control of the wind turbine blade angle to be adjusted according to the speed. Absolute encoders are of two types:

  • Single turn absolute encoder provides information for any increment within one shaft rotation.
  • Multi turn absolute encoders are provides information for multiple shaft rotation as many as half billion shaft rotation. Thus exact shaft rotation is known even after power interruption

Close loop applications of Encoder:

  • Servo or VFD control
  • Measuring
  • Counts

VFD control:

For VFD control we are running a pump on a VFD, to fill a tank full of a liquid. You are requesting a certain speed and want to verify that the pump VFD is at the requested speed. An encoder on the VFD may be used for feedback of the speed.

Measuring Process:

In this application you will need to cut some aluminium product to a particular size. We will pass a long roll, measuring hundreds of feet, of the aluminium sheet through a cutting mechanism. We need to determine the amount of aluminium fed, so that you cut the sheet to the proper size that will be used a manufacturing process. An encoder attached to the conveyor and reading the material that is feeding through your cutting assembly will indicate the length of the material that has been fed since the last cut. That feedback can be used to adjust the cutting blade to sever the length required.

Counts:

We have conveyor line that has bottles running on a conveyor that are counted by a photo eye sensor when entering the assembly. They have cap with an aluminium tamper proof foil on top that need to adhere to the bottle. Once the foil is sealed, the bottle will then move down the conveyor line and verified that it exited the cap sealing assembly via an exit photo sensor. Some of the requirements for the station are:

The same number of bottles entering the assembly must be exit in a “predetermined time frame”.

The bottle must not remain in front of an “entrance” or “exit” sensor.

The bottle must not be exposed to the inductive sealer longer then a predetermined amount of time.

We will make this assembly flexible enough to handle many types of bottles and entrance and exit sensor placement.

Rotary encoders:

Encoder is a communication device that controls the motion of the operating device. Encoders are used to translate rotatory and linear motion into a digital signal helping to determining the speed and position of the motor or other moving equipment. Basically an encoder accesses a measuring system for moving parts. There are two types of encoders:

A rotary encoder is a type of position sensor which is used to that measures rotation on a shaft for determining the angular position of a rotating shaft. It transfers this rotation in series of pulses. These pulses control the controller attached to the encoder depending upon the shaft movement and in what direction it move. According to the rotational movement it generates an electrical signal, either analog or digital. Rotary encoder measure the angular movement. It can measure both degree of movement and direction. Rotary encoder can be used as control and it is much more versatile than potentiometer. Rotary encoder can also be used as rotation sensors for motors and other devices. A rotary encoder collects data and provides feedback based on the rotation of the object or in other words a rotating device. Rotary encoders are sometimes called shaft encoders. This encoder type can convert an object position or motion based on the rotation of the shaft, depending on the measurement type used. There are several methods of encoding output some of output can be incremental or absolute. It can use magnetic or optical sensors. Some devices even use lasers.

Absolute rotary encoders:

Absolute rotary encoders can measures angular positions.

Common type of rotary encoder is incremental which is also called quadrature or relative encoder. It can use two pulsed output signals to indicate both direction and degree of rotation.

Advantages of encoders:

  • Non-contact for high reliability
  • Very high precision
  • Robust design for application in harsh environment
  • Long service life and reduced service times
  • Compact design for many application

Difference between Rotary encoder and potentiometer:

Although rotary encoder looks a lot similar to the potentiometer but it works completely different. We used the potentiometer as a variable resistor. So we have one plus pin, one minus pin and resistor value pin. But the rotary encoders for example is used for directions so we can turn left, we can turn right and there is also a little switch so when we press the rotary encoder we will hear a little click. Because there is small switch on the bottom we can rotate infinitely to the right and infinitely to the left when we rotate it we will feel little clicks and every time we feel a click we can read movement to the left or right. In potentiometer we can rotate to the left until it stuck and to the left until is stuck. So we cannot infinitely rotate the knob of the potentiometer.

Working of Rotary encoder:

We get two waves while working on the rotary encoder. We get square wave A when we turn the rotary encoder clockwise and when we turn the rotary encoder anticlockwise we get square wave B.

They are used for all sorts of things in modern cars it is used for navigation system.

Rotary encoder testing:

Now to test the rotary encoder we will connect the encoder in bread board. Then connect the ground pin of the rotary encoder with the ground pin of the Arduino. The second pin of the rotary encoder with the 5V. The third pin is the switch which is activated when we press on the top we will connect this pin with the Arduino pin number 12. Now the fourth pin of the rotary encoder is the trigger which is connected with the pin number 3 of the Arduino. The clock pin of the rotary encoder is connected with the Arduino pin number 4.

We define the switch pin for when we press the rotary encoder which is connected with the pin number 12. The switch state is high and this look a little bit weird. The rotary encoder inverts this so the default state is high. When we press the rotary encoder it becomes low then we have a pin A and pin B which is connected with the 4 and 3 respectively. The current state of the pin A is low. In the setup we initialize the monitor 9600 baud rate and the pin mode of switch pin we have defined at pin 12. The pull up resistor is already inside the Arduino so we don’t need an extra one we just tell the Arduino that our switch pin 12, uses the internal pull up resistor saves us a resistor. In the loop we have separated two portion one is button portion and other is direction rotation. In the button part we it is a pretty straightforward we read the switch state whether the button is pressed with digitalRead() and we read this off with the switch pin If the state is low we press the button and if it is high it is in default state which is what we do here is when the switch state is low then the switch is pressed and we print that in our terminal. For the rotation direction we are going to read pin A and pin B. we read the pin A and store it as a current state of pin a in this variable. Then we want to know if there was any movement and we want to know for sure that it makes one step movement at least because otherwise we get a lot of false positives. So what we are doing over here we check if the last “A” state is low. So we check if that one was low and if the current state is high then we check the second state which is pin B if it is high then we rotate to the left. If we turn to the opposite direction then pin B is low and the current state of A is high so then we print right. In last we store the current state of the pin A. once we have read and process this data of the digital pin the digital read on pin A. we can see the output on serial monitor.


Источник: www.electroniclinic.com