Hi,
In my project, I’m using Arduino UNO and Adafruit motor shield (pololu.com/product/1103/specs). I was trying to do a position control of my DC motor without using encoder which is already attached to the motor, but controlling it via Arduino code as it appears in the attached code. however, I couldn’t achieve the required motion of the DC motor which is (Raising from 0 to 90 degrees, holding , and lowering back from 90 to 0 degrees, for 5 seconds for each stage).
The question, should I use the encoder with PID control to achieve this exact motion? or can I do that with just the arduino code?
In case I need to include the encoder, What do I need to integrate PID control into my project?
Finally, how can I hook up the encoder/PID to my DC motor? Do I need to include an other hardware other than my Arduino and motor shield?
My goal is to drive the DC motor at low speed without loosing torque and in the specific motion as mentioned above.
Thanks
[code]#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include “utility/Adafruit_PWMServoDriver.h”
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which ‘port’ M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
void setup() {
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
void loop() {
myMotor->run(FORWARD);
myMotor->setSpeed(20);
delay(1000);
myMotor->run(BACKWARD);
myMotor->setSpeed(20);
delay(1000);
myMotor->run(RELEASE);
delay(5000);
}][/code]