HELP! Pololu Magnetic Encoder + Micro metal gear motor + DRV8388

Hello! Will someone help me how to start wiring and coding these components properly using Arduino? I've been struggling for hours now.

My goal is to simply turn the motor into a certain degree after meeting a certain condition. Just like how servo motor works.

This my first time using these components.

Can someone help me?? thanks.

You need to let us know what you have done so far.

Tell us about the project you are trying to create.

Post links to the datasheets for your motor driver and encoder

Make a pencil drawing showing how you have things connected and post a photo of the drawing. See this Simple Image Guide

Post the program you have been trying.

And please post your code between [code] [/code] tags so your code looks like thisand is easy to copy to a text editor

...R

Hello sir thank you for your reply. @Robin2

The photo attached is how I connected the 3 components involved. I hope you understand the sketch.

The code below works but it only runs the motor.
I have no idea how to insert the outputA and outputB of the encoder to set a certain degree.

int enablePin = 10;
int phasePin = 12;
int OutputA = 5;
int OutputB = 6;

void setup()
{
  pinMode(enablePin, INPUT);
  pinMode(phasePin, OUTPUT);
}
void loop()
{ 
  
  digitalWrite(enablePin, HIGH);
  digitalWrite(phasePin, HIGH);
  delay(100);
  digitalWrite(enablePin, LOW);
  digitalWrite(phasePin, LOW);
  delay(500);
  digitalWrite(enablePin, HIGH);
  digitalWrite(phasePin, LOW);
  delay(100);
  digitalWrite(enablePin, LOW);
  digitalWrite(phasePin, LOW);
  delay(500);
}

Robin2:
You need to let us know what you have done so far.

Tell us about the project you are trying to create.

Post links to the datasheets for your motor driver and encoder

Make a pencil drawing showing how you have things connected and post a photo of the drawing. See this Simple Image Guide

Post the program you have been trying.

And please post your code between tags so

your code looks like this

and is easy to copy to a text editor

...R

Hello sir thank you for your reply. @Robin2

The photo attached is how I connected the 3 components involved. I hope you understand the sketch.

The code below works but it only runs the motor.
I have no idea how to insert the outputA and outputB of the encoder to set a certain degree.

int enablePin = 10;
int phasePin = 12;
int OutputA = 5;
int OutputB = 6;

void setup()
{
  pinMode(enablePin, INPUT);
  pinMode(phasePin, OUTPUT);
}
void loop()
{ 
  
  digitalWrite(enablePin, HIGH);
  digitalWrite(phasePin, HIGH);
  delay(100);
  digitalWrite(enablePin, LOW);
  digitalWrite(phasePin, LOW);
  delay(500);
  digitalWrite(enablePin, HIGH);
  digitalWrite(phasePin, LOW);
  delay(100);
  digitalWrite(enablePin, LOW);
  digitalWrite(phasePin, LOW);
  delay(500);
}

Image from Reply #3 so we don't have to download it. See this Simple Image Guide

...R

You have not described what you are trying to create. It is much easier to give useful advice when we know what the project is.

You have not provided links to the datasheets

...R

Robin2:
You have not described what you are trying to create. It is much easier to give useful advice when we know what the project is.

You have not provided links to the datasheets

...R

Encoder

Motor

Driver

My project is to create a robotic hand.
I will send a signal to the robotic hand. After the robotic hand received the signal, based on the position set on the code, the motor will rotate at that certain position.

sorry if it's not clear...
thanks for the help

Why have you set the enable pin to pinmode INPUT? Don't you think that should be an OUTPUT since you are constantly writing to that pin?
Also, what do you expect this configuration to do once the motor has achieved the desired position? What is going to maintain that position? The motor driver brake function only provides a limited ability to slow the motor down, it does not lock the motor. Once the motor has stopped the brake function is useless. So what will keep your hand at its new position once you have cut power to the motor?
IMHO a stepper motor would be a better solution since it has positional control and can easily hold a position.

ettexx:
My project is to create a robotic hand.
I will send a signal to the robotic hand. After the robotic hand received the signal, based on the position set on the code, the motor will rotate at that certain position.

It would be useful to see a diagram of how the motor links to the hand.

Also, hands usually have several moving parts. Are you planning to have other motors? If so what kind? Reading an encoder without missing pulses is a lot of work for an Arduino and I doubt if it could successfully read several encoders.

On top of all that there is what @Due_unto has said about holding position. Stepper motors would probably be better than a simple DC motor. And whether using a DC motor or a stepper motor you will need some means (such as a limit switch) to determine the HOME or ZERO position.

With all that in mind a servo might be best of all because they have absolute position control and all their electronics in a neat package.

The usual way to read the encoder is by connecting its pulse outputs to two Arduino interrupt pins. When an interrupt is triggered if you read the state of the other pin you can tell which direction the shaft is rotating, You could probably get away with just using one interrupt as your program should already know which direction the motor is moving. I reckon you will get lots of examples if you Google arduino motor encoder.

...R

I am facing a similar problem for controlling my robotic hand. Did u find any solution?