I am currently able to make the motor go on and off with a small cheat.
I used the Steps Per Revolution sketch and modified it.
Sometimes the motor makes a few steps after the switch shut off.
Is there a better way to just make the motor run a specific speed until told to turn off?
Here is the potion of my code.
#include <Stepper.h>
const int steps = 4; // change this to fit the number of steps per revolution
// for your motor
const int pinInput1 = 2;
const int pinInput2 = 4;
const int pinOutput = 13;
#define analogPin A0
int sensorPin = A0;
int sensorValue; // variable to store the value coming from the sensor
float alarmValue; // a variable to know when to light LED - alarm value
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(steps, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(45);
// initialize the serial port:
Serial.begin(9600);
// set input and output pin mode
pinMode (pinInput1, INPUT);
pinMode (pinInput2, INPUT);
pinMode (pinOutput, OUTPUT);
digitalWrite (pinOutput, HIGH);
alarmValue = 200; // initialize alarm value in Celsius
}
void loop() {
// check if input 2 is on
if (digitalRead (pinInput2) == HIGH)
{
//if input 2 is on turn on output
//digitalWrite (pinOutput, HIGH);
//if input 2 on step in one direction:
Serial.println("counterclockwise");
myStepper.step(steps);
}