V2 of Rotary Encoder Using Arduino

by heemanthy in Circuits > Electronics

238 Views, 1 Favorites, 0 Comments

V2 of Rotary Encoder Using Arduino

v2 encoder using arduino.png

this is the continuation of the v1 rotary encoder made using attiny at here v2 arduino is used for better out put

Supplies

materials required

Downloads

Connection to Arduino

v2 encoder using arduino schematic.png

this is the connection for arduino and there is a slide switch which will be use full for changing between 2 sensor and 3 sensor encoder. you can also use this .brd file in tinkercad

Program / Code

this is the code used

// C++ code

//

void setup()

{

 pinMode(12, INPUT);

 pinMode(A0, INPUT);

 pinMode(3, OUTPUT);

 pinMode(4, OUTPUT);

 pinMode(A1, INPUT);

 pinMode(13, INPUT);

 pinMode(5, OUTPUT);


}


void loop()

{

 if (digitalRead(12) == HIGH) {

  if (digitalRead(A0) == HIGH) {

   digitalWrite(3, LOW);

   digitalWrite(4, LOW);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, HIGH);

   digitalWrite(4, LOW);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, HIGH);

   digitalWrite(4, HIGH);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, LOW);

   digitalWrite(4, HIGH);

   delay(500); // Wait for 500 millisecond(s)

  }

  if (digitalRead(A1) == HIGH) {

   digitalWrite(3, HIGH);

   digitalWrite(4, HIGH);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, LOW);

   digitalWrite(4, HIGH);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, LOW);

   digitalWrite(4, LOW);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, HIGH);

   digitalWrite(4, LOW);

   delay(500); // Wait for 500 millisecond(s)

  }

 }

 if (digitalRead(13) == HIGH) {

  if (digitalRead(A0) == HIGH) {

   digitalWrite(3, HIGH);

   digitalWrite(4, LOW);

   digitalWrite(5, LOW);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, HIGH);

   digitalWrite(4, HIGH);

   digitalWrite(5, LOW);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, LOW);

   digitalWrite(4, HIGH);

   digitalWrite(5, HIGH);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, LOW);

   digitalWrite(4, LOW);

   digitalWrite(5, HIGH);

   delay(500); // Wait for 500 millisecond(s)

  }

  if (digitalRead(A1) == HIGH) {

   digitalWrite(3, LOW);

   digitalWrite(4, LOW);

   digitalWrite(5, HIGH);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, LOW);

   digitalWrite(4, HIGH);

   digitalWrite(5, HIGH);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, HIGH);

   digitalWrite(4, HIGH);

   digitalWrite(5, LOW);

   delay(500); // Wait for 500 millisecond(s)

   digitalWrite(3, HIGH);

   digitalWrite(4, LOW);

   digitalWrite(5, LOW);

   delay(500); // Wait for 500 millisecond(s)

  }

 } else {

  digitalWrite(5, LOW);

 }

}

Link to View

https://www.tinkercad.com/things/hYfZBN4Q8vg