Updated Code utilizing an H bridge. I appreciate your time spent looking at my project! From what I gather I could use some more experience understanding voltage, "stepping", and terminology involving this type of sketch.
** Update as of 3:43 Server time-
const int motor1Pin = 2; // H-bridge leg 1 (pin 7, 1A)
const int motor2Pin = 6; // H-bridge leg 2 (pin 8, 2A)
const int enablePin = 10; // H-bridge enable pin to power motor
const int SensorOpen = 0; //Proximity Sensor for Magnet near motor Analog 0
const int SensorClose = 1; //Proximity Sensor for Magnet at end of track Analog 1
int counter = -1;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 9, 5, 4, 3, 12);
void setup() {
// make sure all pins do not start or "coast"
digitalWrite(enablePin, LOW);
// set all the other pins you're using as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(SensorOpen, INPUT);
pinMode(SensorClose, INPUT);
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD. (Will stay)
lcd.print("Number of Cycles");
delay(2000);
}
void loop() {
//Read the Proximity Sensor Values
int Open = analogRead(SensorOpen);
int Close = analogRead(SensorClose);
Serial.println(Open);
Serial.println(Close);
delay(500);
if (Close > 1000) {
//Will Stop the Motor upon trigger of sensor
//Delay and reverse direction (Open the Cover)
digitalWrite(enablePin, LOW);
delay(6000); // time for motor to cool down. (Change to 1 minute)
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, HIGH);
analogWrite(enablePin, 255);
delay(5000); // time to clear the sensor
}
if (Open > 1000) {
//Will Stop the Motor upon trigger of sensor
//Delay for 5 seconds and reverse direction (Close the Cover)
digitalWrite(enablePin, LOW);
delay(6000); // time for motor to cool
digitalWrite(motor2Pin, LOW);
digitalWrite(motor1Pin, HIGH);
analogWrite(enablePin, 255);
delay(5000); // time to clear the proximity sensor
counter++;
// delay(23000); // test using time instead of sensors
delay(4000);
// delay(15000);
}
Serial.println(counter);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of cycles since reset:
lcd.print(counter);
}