Surilli
Published © LGPL

Interfacing Rotary Encoder with Surilli GSM

Monitor movement and position of an application when rotating the knob of the rotary encoder.

BeginnerFull instructions provided30 minutes282
Interfacing Rotary Encoder with Surilli GSM

Things used in this project

Hardware components

Surilli GSM
Surilli GSM
×1
Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Interfacing Rotary Encoder with Surilli GSM

Code

Rotary_Encoder

C/C++
# define encoder0PinA 9
# define encoder0PinB 6
# define encoder0Btn 5
int encoder0Pos = 0;
void setup() {
 Serial.begin(9600);
 pinMode(encoder0PinA, INPUT_PULLUP);
 pinMode(encoder0PinB, INPUT_PULLUP);
 pinMode(encoder0Btn, INPUT_PULLUP);
 attachInterrupt(0, doEncoder, CHANGE);
}
int valRotary,lastValRotary;
void loop() {
 int btn = digitalRead(encoder0Btn);
 Serial.print(btn);
 Serial.print(" ");
 Serial.print(valRotary);
 if(valRotary>lastValRotary)
 {
 Serial.print("  CW");
 }
 if(valRotary)  {
 Serial.print("  CCW");
 }
 lastValRotary = valRotary;
 Serial.println(" ");
 delay(250);
}
void doEncoder()
{
 if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB))
 {
 encoder0Pos++;
 }
 else
 {
 encoder0Pos--;
 }
 valRotary = encoder0Pos/2.5;
} 

Credits

Surilli

Surilli

196 projects • 47 followers
Surilli is a premiere Internet of Things centric Technology Company aimed at providing cutting edge innovative solutions.

Comments