Basically I'm trying to make a servo motor out a DC motor that has an encoder. I'm wanting to make something like this: Potentiometer control DC Motor Position (DIY Servo) Using Arduino - YouTube
My parts:
Motor - Pololu - 30:1 Metal Gearmotor 37Dx52L mm 12V with 64 CPR Encoder (No End Cap) (My Project requires me to a DC motor)
Motor Driver - http://www.arduino.cc/en/Main/ArduinoMotorShieldR3
MCU is an UNO
I have not problem making the motor move with the POT. But I'm just not sure how to stop the motor fast at a given position. It runs past the stop point... I would love to be able to start from a source code that worked like the one in the video above.
This is the basic code that I'm using to just try and stop the motor as a test.. When it hits the end position it engages the brake, but still rolls past the stop points
#include <Encoder.h>
Encoder myEnc(2, 4);
int motorDir = 12;
int motorBrake = 9;
int motorSpeed = 3;
int sensorPin = A4;
int positionEnd = 2000;
void setup() {
pinMode(motorDir, OUTPUT);
pinMode(motorBrake, OUTPUT);
Serial.begin(9600);
digitalWrite(motorDir, LOW); //Establishes forward direction
digitalWrite(motorBrake, LOW); //Disengage the Brake
analogWrite(motorSpeed, 100); //Motor speed
}
void loop() {
if (myEnc.read() >= positionEnd ) {
analogWrite(motorSpeed, 0); //Motor speed
digitalWrite(motorBrake, HIGH); //Engage the Brake
Serial.print("Brake ");
Serial.println(myEnc.read()); //Echos current Postion
}
}
Thanks for any help or suggestions!!!