Rotary Encoder Basics

Similar documents
Appendix A Requirement and Verification Table

Robotics/Electronics Review for the Final Exam

Unit B - Rotary Encoders B.1

Arduino - DigitalReadSerial

EP486 Microcontroller Applications

Arduino Programming Part 4: Flow Control

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

Button Input: On/off state change

Thumb Joystick Retail. Tools and parts you'll need. Things you'll want to know. How does it work? Skill Level: Beginner. by MikeGrusin March 22, 2011

Lesson 8: Digital Input, If Else

Monitor your home remotely using the Arduino

4Serial SIK BINDER //77

Arduino notes 3: Digital input via buttons

Arduino Programming and Interfacing

AUTOMATIC TEA BREWING THERMOS

EECS 373 Midterm 2 Fall 2018

Phi-panel backpack assembly and keypad options Dr. John Liu 12/16/2012

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

Analog Input. Sure sure, but how to make a varying voltage? With a potentiometer. Or just pot.

Serial.begin ( ); Serial.println( ); analogread ( ); map ( );

Quantum Phase Isochromatic Pluckeasy

Robotics and Electronics Unit 5

This is the Arduino Uno: This is the Arduino motor shield: Digital pins (0-13) Ground Rail

Arduino Prof. Dr. Magdy M. Abdelhameed

More Arduino Programming

Arduino Part 2. Introductory Medical Device Prototyping

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

Lecture 7. Processing Development Environment (or PDE)

Experiment 4.A. Speed and Position Control. ECEN 2270 Electronics Design Laboratory 1

Please see the Pin Descriptions section for more information about the 10 available connections.

cs281: Introduction to Computer Systems Lab03 K-Map Simplification for an LED-based Circuit Decimal Input LED Result LED3 LED2 LED1 LED3 LED2 1, 2

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

Overview. Multiplexor. cs281: Introduction to Computer Systems Lab02 Basic Combinational Circuits: The Mux and the Adder

Lab 2 - Powering the Fubarino. Fubarino,, Intro to Serial, Functions and Variables

ArdOS The Arduino Operating System Quick Start Guide and Examples

Imperativ Programming. morning (again) Jens Dalsgaard Nielsen Aalborg University (1/24)

MAKE & COLLABORATE: SECRET KNOCK LOCK

ECE 2010 Laboratory # 2 J.P.O Rourke

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

Arduino Workshop. Overview. What is an Arduino? Why Arduino? Setting up your Arduino Environment. Get an Arduino based board and usb cable

Make It Change: Potentiometers

The Big Idea: Background:

IR Breakbeam Sensors. Created by lady ada. Last updated on :32:59 PM UTC

Make your own secret locking mechanism to keep unwanted guests out of your space!

L298N Dual H-Bridge Motor Driver

Electronic Brick Starter Kit

Software debouncing of buttons

#include "DHT.h" DHT dht(dhtpin, DHTTYPE); // Date and time functions using a DS1307 RTC connected via I2C and Wire lib

Input Shield For Arduino SKU: DFR0008

The DTMF generator comprises 3 main components.

Lab 02 Arduino 數位感測訊號處理, SPI I2C 介面實驗. More Arduino Digital Signal Process

Lab 2 - Powering the Fubarino, Intro to Serial, Functions and Variables

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Lab 5 - Serial Parser, String Manipulation & Libraries

MEDIS Module 2. Microcontroller based systems for controlling industrial processes. Chapter 4: Timer and interrupts. M. Seyfarth, Version 0.

KNOCK LOCK MAKE YOUR OWN SECRET LOCKING MECHANISM TO KEEP UNWANTED GUESTS OUT OF YOUR SPACE! Discover: input with a piezo, writing your own functions

Arduino Lesson 15. DC Motor Reversing

Specification. 1.Power Supply direct from Microcontroller Board. 2.The circuit can be used with Microcontroller Board such as Arduino UNO R3.

Reading ps2 mouse output with an Arduino

ADC to I 2 C. Data Sheet. 10 Channel Analog to Digital Converter. with output via I 2 C

EXPERIMENT2. V3 Robot Navigates Autonomously with Feelers and Infrared Sensors

The Big Idea: Background: About Serial

Using PSpice to Simulate Transmission Lines K. A. Connor Summer 2000 Fields and Waves I

Adafruit DS3231 Precision RTC Breakout

ENCODER SELECTION (THE BASICS)

DS18B20+ Digital Temperature Sensor

Application Note Operation of the Jameco and SD Card Data Storage on the Teensy Ferris Chu

Digital Design through. Arduino

Ryan Everaert Application Note Team - I Application Note for Toshiba Bipolar Stepper, Part Number TB6560AHQ

ZX Distance and Gesture Sensor SMD Hookup Guide

This tutorial will show you how to take temperature readings using the Freetronics temperature sensor and an Arduino Uno.

A 3-SPEED STEPPER MOTOR

Laboratory 1 Introduction to the Arduino boards

IME-100 Interdisciplinary Design and Manufacturing

BASIC ARDUINO WORKSHOP. Mr. Aldwin and Mr. Bernardo

RTC 300/RTC 600 Installation instructions scan

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

Grove - Rotary Angle Sensor

BASIC Arduino. Part I

Project 18 Dual 8-Bit Binary Counters

Grove - Thumb Joystick

SERIE 59. Rear clamp. Frontal clamp HIGH RESOLUTION HOLLOW SHAFT INCREMENTAL ENCODER FOR INDUSTRIAL APPLICATIONS

CTEC 1802 Embedded Programming Labs

Introduction to Arduino

Microcontrollers and Interfacing week 8 exercises

Chapter 6. Having fun with programming. Section 6.1 Random teacher jokes

Counter & LED (LED Blink)

General Description. Figure 1. FIPSD2M Driver Board

DEV-1 HamStack Development Board

Arduino C++ Introduction to programming Antony Watts M0IFA

ROBOTLINKING THE POWER SUPPLY LEARNING KIT TUTORIAL

Building your own special-purpose embedded system gadget.

ISL RGB Sensor Tutorial By: Sabrina Jones

AT42QT1010 Capacitive Touch Breakout Hookup Guide

<Table of content> <Parts and description> <Circuit board Guide> <Pins> <Basics of Coding> <Intro to Arduino> <Intro> <Downloading Arduino IDO>

Temperature Sensor. Overview. Features

Schedule. Sanford Bernhardt, Sangster, Kumfer, Michalaka. 3:10-5:00 Workshop: Build a speedometer 5:15-7:30 Dinner and Symposium: Group 2

MigaOne-Arduino Tutorial: Position/Limit Sensing and Cycling with the Arduino Platform

Grove - 3 Axis Digital Accelerometer±16g Ultra-low Power (BMA400)

18-heater Arduino code

Transcription:

Rotary Encoder Basics A rotary encoder has a fixed number of positions per revolution. These positions are easily felt as small clicks you turn the encoder. The Keyes module that I have has thirty of these positions. On one side of the switch there are three pins. They are normally referred to as A, B and C. In the case of the KY-040, they are oriented as shown. Inside the encoder there are two switches. Once switch connects pin A to pin C and the other switch connects pin B to C. In each encoder position, both switches are either opened or closed. Each click causes these switches to change states as follows: If both switches are closed, turning the encoder either clockwise or counterclockwise one position will cause both switches to open If both switches are open, turning the encoder either clockwise or counterclockwise one position will cause both switches to close.

The illustration below is representative of how the switch is constructed. As you can see, the angular position of the A terminal and the B terminal is such that: Rotating the switch clockwise will cause the switch connecting A and C to change states first. Rotating the switch counterclockwise will cause the switch connecting B and C to change states first. If we were to represent the opening an closing of the switches as wave forms, it would look something like this.

Essentially, determining which switch changed states first is how the direction of rotation is determined. If A changed states first, the switch is rotating in a clockwise direction. If B changed states first, the switch is rotating in a counter clockwise direction. KY-040 Pin Outs The pin outs for this rotary encoder are identified in the illustration below. output when the switches are closed and a high when the switches are open. The module is designed so that a low is The low is generated by placing a ground at Pin C and passing it to the CLK and DT pins when switches are closed. The high is generated with a 5V supply input and pullup resistors, such that CLK and DT are both high when switches are open. Not previously mentioned is the existence of of push button switch that is integral to the encoder. If you push on the shaft, a normally open switch will close. The feature is useful if you want to change switch function. For example, you may wish to have the ability to between coarse and fine adjustments.

Keyes Rotary Encoder Schematic A schematic for this module is provided below. R2 and R3 in the schematic are pull up resistors. Keyes KY-040 Evaluation Circuit Successfully implementing the Rotary Encoder into any project requires a clear understanding of everything that has been discussed thus far. If you re still a little fuzzy, you may wish to throw together the evaluation circuit illustrated below: VERY SLOWLY rotate then encoder shaft both clockwise and counterclockwise. Notice which LEDs change state first with rotation.

Module Connection to the Arduino Pretty straight forward All you need to do is connect four wires to the module. The Arduino Sketch This is a simple sketch that shows how to count the encoder position and how to determine direction of rotation. It has no switch debounce, nor does it use interrupts. A fully developed application might need to incorporate these in order to make it robust. int pina = 3; // Connected to CLK on KY-040 int pinb = 4; // Connected to DT on KY-040 int encoderposcount = 0; int pinalast; int aval; boolean bcw; void setup() { pinmode (pina,input);

pinmode (pinb,input); /* Read Pin A Whatever state it's in will reflect the last position */ pinalast = digitalread(pina); Serial.begin (9600); void loop() { aval = digitalread(pina); if (aval!= pinalast){ // Means the knob is rotating // if the knob is rotating, we need to determine direction // We do that by reading pin B. if (digitalread(pinb)!= aval) { // Means pin A Changed first - We're Rotating Clockwise encoderposcount ++; bcw = true; else {// Otherwise B changed first and we're moving CCW bcw = false;

encoderposcount--; Serial.print ("Rotated: "); if (bcw){ Serial.println ("clockwise"); else{ Serial.println("counterclockwise"); Serial.print("Encoder Position: "); Serial.println(encoderPosCount); pinalast = aval;