How to use an Arduino rotary encoder
This guide will show you the basics of rotary encoders. A rotary encoder is a type of position sensor that converts the angular position (rotation) of a knob into an output signal that is used to determine what direction the knob is being rotated. Due to their robustness and fine digital control; they are used in many applications including robotics, CNC machines, and printers. The document provides a step by step guide as well which demonstrates how you can use the rotary encoder on your computer with Ozeki 10. So, let's start right now.
What is an rotary encoder?
A rotary encoder is a type of position sensor which is used for determining the angular position of a rotating shaft. It generates an electrical signal, either analog or digital, according to the rotational movement.
How does a rotary encoder work?
Let's see, how the square wave pulses are generated: The encoder has a disk with evenly spaced contact zones that are connected to the common pin C and two other separate contact pins A and B. When the disk will start rotating step by step, the pins A and B will start making contact with the common pin and the two square wave output signals will be generated accordingly.
Any of the two outputs can be used for determining the rotated position if we just count the pulses of the signal. However, if we want to determine the rotation direction as well, we need to consider both signals at the same time. We can notice that the two output signals are displaced at 90 degrees out of phase from each other. If the encoder is rotating clockwise the output A will be ahead of output B.
Arduino rotary encoder wiring diagram
How to use an Arduino rotary encoder in Ozeki
A rotary encoder, also called a shaft encoder, is an electro-mechanical device that converts the angular position or motion of a shaft or axle to an analog or digital signal. Rotary Encoder connections forward every event generated by rotary changes. These events are forwarded to a selected Ozeki connection. Events can either represent clockwise or counter-clockwise turns or they can also represent the button pressed on the Rotary Encoder, since you can also press the spinning mechanism. To use the Rotary Encoder in Ozeki, you first need to download Ozeki Robot Developer. Ozeki Robot Developer will install the Arduino libraries needed to use this sensor efficiently.
Download Ozeki Robot Developer
After Ozeki Robot developer is installed, you need to upload the Rotary Encoder control code to your Arduino. You can find the code and download instructions on the following pages. The upload process includes two steps: first you need to format the EEPROM of the arduino, then you need to upload the control code. The procedure is very simple, it only takes a few seconds.
Upload the Rotary Encoder code to Arduino Uno
Upload the Rotary Encoder code to Arduino Mega 2560
Upload the Rotary Encoder code to Arduino Nano
Upload the Rotary Encoder code to Raspberry Pi
The arduino sensors and Ozeki will communicate over the USB port using the Ozeki Rotary Encoder protocol. This protocol makes it possible for you to use the sensor directly on your PC. You will be able to control this sensor through the web based user interface or you will be able to communicate with it using Ozeki Chat. You can read more about chat control on the following page.
How to communicate with the Rotary Encoder using chat
It is important to understand chat control, because when you build a robot, the way you wish to control this sensor is by sending and receiving messages. If you open the Ozeki Robot Developer app, you will see, who you can write a C#.Net program to work with this sensor.
Connection steps
- Connect the Rotary encoder to your Arduino by following the wiring diagram
- Plug the Arduino board into your computer
- Check the COM ports to see if your Arduino is connected properly
- Open the Arduino application on your computer
- Upload example code to the Arduino
- Type https://localhost:9515 in your browser to open Ozeki 10
- Select the connection of the Rotary encoder
- Rotate the Rotary encoder to test it
System overview
The system we suggest consists of a rotary encoder, that is wired to the analog port of your Arduino. The Arduino will be responsible for reading data from this device in real-time. The brain of the system will be running on a PC (Figure 2). On the PC, Ozeki 10 will be able to manage the communication. You can easily run Ozeki 10 using a webbrowser
Prerequisites
- Rotary encoder
- 3x1kΩ resistor
- Ozeki 10 installed on your computer
- Programmable board (Arduino Mega/Nano/Uno or Raspberry Pi)
- USB cable is needed between Arduino Mega/Nano/Uno and your computer
Step 1 - Wire the rotary encoder to your Arduino
You can see how to wire the rotary encoder to any of the following boards:
- Arduino Uno
- Raspberry Pi
(If you use Raspberry Pi please jump to 'Step 3')
After wiring, please plug the board to your computer!
Step 2 - Upload code to the microcontroller
Step 3 - Start Ozeki 10 to try the rotary encoder
Step 4 - Configure your rotary encoder in Ozeki 10
To configure your rotary encoder (attached to your Arduino) in Ozeki 10, that is installed on your computer, you need to open the graphical user interface (GUI) of Ozeki 10. You can open the GUI by entering the URL of the computer into your webbrowser. For example, if our PC has an IP address of 192.168.1.5, we would enter http://192.168.1.5:9513 into our webbrowser.
Step 5 - Understand the rotary encoder protocol
The Rotary Encoder can communicate with Ozeki through the following protocol.
References:
https://lastminuteengineers.com
https://howtomechatronics.com
More information
- Arduino sensors and actuators
- How to use an analog sensor in arduino
- How to use a button controller in arduino
- How to use a buzzer in arduino
- How to use dc motors in arduino
- How to use a dht sensor in arduino
- How to use an EEPROM Manager in arduino
- How to use a gyroscope sensor in arduino
- How to use id manager in arduino
- How to use IR transceiver in arduino
- How to use an analog joystick in arduino
- How to use a keyboard in arduino
- How to use an LCD display in arduino
- How to use an NFC Reader in arduino
- How to use an optical gate in arduino
- How to use a register in arduino
- How to use an RF 433 MHz transceiver
- How to use an RF 2.4 GHz transceiver
- How to use an RGB LED in arduino
- How to use an RGB sensor in arduino
- How to use a rotary encoder in arduino
- How to use a servo motor in arduino
- How to use a stepper motor in arduino
- How to use a switch in arduino
- How to use a temperature sensor in arduino
- How to use a timer in arduino
- How to use an ultrasonic sensor in arduino