Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Amal ShajiNuhman Jaseel
Published © Apache-2.0

Reading the encoder value of N20 motor using ESP32

Reading the encoder value of a N20 motor having magnetic encoder using ESP32.

BeginnerProtip4,668
Reading the encoder value of N20 motor using ESP32

Things used in this project

Hardware components

ESP32
Espressif ESP32
×1
N20 motor with encoder
×1
L298N Based Motor Driver Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Pin connections

Code

Encoder_reader

C/C++
#define EncoderPinA 18
#define EncoderPinB 21
#define ForwardPin 27
#define BackwardPin 26
#define EnablePin 25
volatile long Encodervalue=0;
void setup() {
  pinMode(ForwardPin,OUTPUT);
  pinMode(BackwardPin,OUTPUT);
  pinMode(EnablePin,OUTPUT);
  pinMode(EncoderPinA, INPUT);
  pinMode(EncoderPinB, INPUT);
  attachInterrupt(digitalPinToInterrupt(EncoderPinA), updateEncoder, RISING);
  Serial.begin(9600);
}

void loop() {
    digitalWrite(ForwardPin,HIGH);
    digitalWrite(BackwardPin,LOW);
    analogWrite(EnablePin,255);
    
    Serial.println(Encodervalue);
    delay(100);
    
}

void updateEncoder()
{
  if (digitalRead(EncoderPinA)> digitalRead(EncoderPinB))
    Encodervalue++;
  else
    Encodervalue--;
}

Credits

Amal Shaji
3 projects • 5 followers
I'm undergraduate student fascinated towards technology. Trying to build useful projects.
Contact
Nuhman Jaseel
3 projects • 5 followers
Contact

Comments

Please log in or sign up to comment.