0% found this document useful (0 votes)
254 views3 pages

ks0013 Rotary Encoder Module

This document provides information about a rotary encoder module including an introduction, specifications, connection diagram, and sample Arduino code. The rotary encoder can count pulses as it rotates in both directions and can be reset to count from zero. It operates on 5V power, has a digital interface, and measures 30x20mm. The sample code shows how to use interrupts to track the encoder's position and change LEDs based on rotation direction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
254 views3 pages

ks0013 Rotary Encoder Module

This document provides information about a rotary encoder module including an introduction, specifications, connection diagram, and sample Arduino code. The rotary encoder can count pulses as it rotates in both directions and can be reset to count from zero. It operates on 5V power, has a digital interface, and measures 30x20mm. The sample code shows how to use interrupts to track the encoder's position and change LEDs based on rotation direction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

keyestudio

Rotary Encoder module

Introduction
The rotary encoder can count the pulse outputting times during the process of its rotation in
positive and reverse direction by rotating. This rotating counting is unlimited, not like potential
counting. It can be restored to initial state to count from 0.
Specification
Power Supply: 5V
Interface: Digital
Size: 30*20mm
Weight: 7g
Connection Diagram

www.keyestudio.cc

keyestudio

Sample Code
const int interruptA = 0;
const int interruptB = 1;
int CLK = 2;
// PIN2
int DAT = 3;
// PIN3
int BUTTON = 4; // PIN4
int LED1 = 5;
// PIN5
int LED2 = 6;
// PIN6
int COUNT = 0;
void setup()
{
attachInterrupt(interruptA, RoteStateChanged, FALLING);
// attachInterrupt(interruptB, buttonState, FALLING);
pinMode(CLK, INPUT);
digitalWrite(2, HIGH); // Pull High Restance
pinMode(DAT, INPUT);
digitalWrite(3, HIGH); // Pull High Restance

www.keyestudio.cc

keyestudio
pinMode(BUTTON, INPUT);
digitalWrite(4, HIGH); // Pull High Restance
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
Serial.begin(9600);
}

void loop()
{
if (!(digitalRead(BUTTON)))
{
COUNT = 0;
Serial.println("STOP COUNT = 0");
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
delay (2000);
}
Serial.println(COUNT);
}
//------------------------------------------void RoteStateChanged() //When CLK FALLING READ DAT
{
if (digitalRead(DAT)) // When DAT = HIGH IS FORWARD
{
COUNT++;
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
delay(20);
}
else
// When DAT = LOW IS BackRote
{
COUNT--;
digitalWrite(LED2, HIGH);
digitalWrite(LED1, LOW);
delay(20);
}
}

www.keyestudio.cc

You might also like