I have a NEMA 17 stepper motor and an EasyDriver connected to an arduino uno. I also have a strain meter that outputs the force of a load cell I have in terms of voltage. I want the stepper motor to move certain ways according to the force applied to the load cell. I wanted to filter out some noise of the load cell, so I take an average of 1000 samples from the serial monitor, which is working to perfection. The problem that I am having with, is that the stepper motor does not move at all with the code I have (see below). Before I decided to add in the average voltage value from the serial monitor, my stepper motor commands were working well. It was just moving crazy because of all the noise.
#include <StepperDriver.h>
int sensorPin = 0;
int dirPin = 8;
int stepPin = 9;
const int stepsPerRevolution = 200;
StepperDriver myStepper;
void setup()
{
myStepper.setStep(stepsPerRevolution, dirPin, stepPin);
myStepper.setSpeed(50);
myStepper.step(stepsPerRevolution*8);
Serial.begin(9600);
}
void loop()
{
float sum = 0;
for(int i=0; i< 1000; i++)
{
sum = sum + analogRead(sensorPin);
}
float average = sum / 1000;
float voltage = average * 5.0 / 1023;
Serial.println(voltage, 3);
if (voltage > .86 )
{
// Serial.println(".86-.88");
if (myStepper.update() == 1)
{
myStepper.step(stepsPerRevolution);
delay(1000);
}
}
else if (voltage > .84 && voltage <= .86)
{
// Serial.println(".84-.86");
if (myStepper.update() == 1)
{
myStepper.step(stepsPerRevolution/2);
delay(1000);
}
}
else if (voltage > .82 && voltage <= .84)
{
// Serial.println(".82-.84");
if (myStepper.update() == 1)
{
myStepper.step(1);
delay(1000);
}
}
else if (voltage >= .76 && voltage < .78)
{
// Serial.println(".76-.78");
if (myStepper.update() == 1)
{
myStepper.step(-1);
delay(1000);
}
}
else if (voltage >= .74 && voltage < .76)
{
// Serial.println(".74-.76");
if (myStepper.update() == 1)
{
myStepper.step(-stepsPerRevolution/2);
delay(1000);
}
}
else if (voltage < .74)
{
// Serial.println(".72-.74");
if (myStepper.update() == 1)
{
myStepper.step(-stepsPerRevolution);
delay(1000);
}
}
}
This is the part that is not working inside each if block:
if (myStepper.update() == 1)
{
myStepper.step(-stepsPerRevolution);
delay(1000);
Edit: Actually, my stepper motor does move, but it's so slow and can barely see it move. It seems like it moves how it is supposed to, but once the serial monitor prints another value, it has to stop and then start again.