Control Posición angular de motor a pasos con un potenciometro
Control Posición angular de motor a pasos con un potenciometro
Objetivos:
- Con un potenciometro escoger la posición deseada.
- Con un botón iniciar el giro del motor a la posición deseada.
Código Arduino
// desarrollador por
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 48 //numero de pasos para logra una revolución completa
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it’s
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);
int n=0; // numero de pasos
int theta=0; // angulo deseado
int ld=0; // lectura digital
float paso=7.5; // tamaño del paso
void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(1);
pinMode(5,INPUT);
}
void loop()
{
ld=analogRead(A0); //lectura digital
theta=map(ld,0,1024,0,360); //calcula el angulo deseado
n=floor(theta/paso); //numero de pasos
if(digitalRead(5)==HIGH){ // inicia el numero de pasos al oprimir un boton
stepper.step(n);
}
}
Diagrama de Proteus

