- Fri Jun 21, 2013 9:22 am
#160786
Hello, I have a NEMA 17 stepper motor with an EasyDriver hooked up to an Arduino Uno. I have a -15 to 15V power supply with 12V powering the EasyDriver. Here is my code and then after the code I will ask my question.
Code: Select all
I have it set at 200 steps per revolution with a speed of 100 RPM. What I want the motor to do is to read the voltage (which it does), turn 180 degrees depending on the voltage, wait one second, and then repeat. With the code I have, it takes three steps, pauses a second, and then repeats. It doesn't go 180 degrees like I want it to do. What can I do to in my code to make it do that?int sensorPin = 0;
#include <Stepper.h>
const int stepsPerRevolution = 200;
int dirPin = 8;
int stepPin = 9;
Stepper myStepper(stepsPerRevolution, dirPin, stepPin);
void setup()
{
myStepper.setSpeed(100);
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(sensorPin);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
if (voltage > 2.60)
{
myStepper.step(100);
delay(1000);
}
else if (voltage < 2.40)
{
myStepper.step(-100);
delay(1000);
}
}