Thanks for the Reply.
Basically I want the program to run purely off the arduino, I have built a housing for the arduino, LCD display, and enough space for as many buttons as I would need.
For step 6, The key-way being cut calls for the machine to be adjusted on the x-axis (this I have fitted a DRO so operator can adjust accordingly), for this adjustment to happen the z-axis needs to be moved up (with the UP button obviously) so that it clears the material. X is adjusted and then I need the machine to follow the same increment movements so until it reaches the same position (bottom/dept of the key-way aka new zero)
LikeI said I have very limited coding experience so the code I came up with is a bit rough, see code posted below:
// THIS IS THE DEVOLOPING CODE FOR THE CNC PROJECT
#include <Stepper.h> //Includes the stepper library
#include <LiquidCrystal.h> //Includes the LCD library
//This is a button representing the magnetic pickup that would be used to minitor the movement of the machine
int passesButton = ; //The pin that the pushbutton is attached to (will be assigned to a DI on MEGA R3)
//passesButton counting parameters needed for the program to keep track of the current and next state of the button
int buttonPushCounter = 0; //Counter for the number of button presses
int buttonState = 0; //Current state of the button
int lastButtonState = 0; //Previous state of the button
//UP and DOWN buttons to move the Z-axis and get the machine to zero
int upButton = 2; //Sets the up buton to pin 2 on arduino
int RELAY = 3; //CHANGED downButton to RELAY //Sets the down buton to pin 2 on arduino
int UP = 0; //Up Variable
int DOWN = 0; //Down Variable
//Motor Pins
int motorPin1 = 10; //IN1 on the ULN2003 Board, BLUE end of the Blue/Yellow motor coil
int motorPin2 = 11; //IN2 on the ULN2003 Board, PINK end of the Pink/Orange motor coil
int motorPin3 = 12; //IN3 on the ULN2003 Board, YELLOW end of the Blue/Yellow motor coil
int motorPin4 = 13; //IN4 on the ULN2003 Board, ORANGE end of the Pink/Orange motor coil
//Motor Parameters
const int stepsPerRevolution =64; //Here set the stepper motor rotation step how much is a circle
int dim=stepsPerRevolution; //Set the step motor number and pin
int motorSpeed; //Sets the int motorSpeed
//int motor_Step; //Sets the int motorStep
//LCD Parameters and Pin allocation
LiquidCrystal LCD(9,8,7,6,5,4); //Sets the LCD pins up
void setup() {
Serial.begin(9600); //Begin serial for debugging process
pinMode(passesButton, INPUT); //Initialize the button pin as a input:
LCD.begin(16,2); //Begins the LCD display and tells the LCD how big it is
LCD.setCursor(0,0); //Setsthe LCD Cursor
LCD.print("Set Speed: "); //Prints the quoted text
LCD.setCursor(0,1); //Setsthe LCD Cursor
LCD.print("Passes: "); //Prints the quoted text
//pinMode(upButton, INPUT); //Sets up button as an input
pinMode(RELAY, OUTPUT); //Sets down button as an input
pinMode(motorPin1, OUTPUT); //Sets motorPin 1 to be an output
pinMode(motorPin2, OUTPUT); //Sets motorPin 2 to be an output
pinMode(motorPin3, OUTPUT); //Sets motorPin 3 to be an output
pinMode(motorPin4, OUTPUT); //Sets motorPin 4 to be an output
digitalWrite(RELAY,LOW);
}
void loop() {
//passes Button counter
buttonState = digitalRead(passesButton); //Read the pushbutton input pin
if (buttonState != lastButtonState) { //Compare the buttonState to its previous state
if (buttonState == HIGH) { //If the state has changed, increment the counter
buttonPushCounter++; //If the current state is HIGH then the button went from off to on
}
delay(50); //Delay a little bit to avoid bouncing
}
lastButtonState = buttonState; //Save the current state as the last state, for next time through the loop
//RELAY to act as switch in order to tell Stepper when to move down 1 increment
if (buttonPushCounter % 6 == 3) { //Turns on the LED every four button pushes by checking the modulo of the button push counter.
digitalWrite(RELAY, HIGH);
delay (50);
}
else { //The modulo function gives you the remainder of the division of two numbers:
digitalWrite(RELAY, LOW);
}
int sensor_Reading = analogRead(A0); //Read the sensor value
int motorSpeed = map(sensor_Reading, 0, 1023, 0, 64); //Map it to a range according to steps per revolution
LCD.setCursor(11,0); //Just a calculation test need to modify for distance traveled per revolution and keep track of the revolutions etc.
LCD.print(float(float(motorSpeed)/float(64))); //Values are mixed up, slow is fast and fast is slow
UP = digitalRead(upButton);
if (UP == HIGH)
{
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, HIGH);
digitalWrite(motoPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(motorSpeed);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(motorSpeed);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, HIGH);
delay(motorSpeed);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(motorSpeed);
}
DOWN = digitalRead(downButton);
if (DOWN == HIGH)
{
digitalWrite(motorPin4, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin1, LOW);
delay(motorSpeed);
digitalWrite(motorPin4, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin1, LOW);
delay(motorSpeed);
digitalWrite(motorPin4, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin1, HIGH);
delay(motorSpeed);
digitalWrite(motorPin4, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin1, HIGH);
delay(motorSpeed);
}
LCD.setCursor(8, 1);
LCD.print(buttonPushCounter);
}
Currently the "passes" push button works as I need it to (Relay turns on when I want it to, will use this as a signal to tell stepper motor when to move 1 increment)
The up and downs buttons work as I need them to.
The problem comes in with the following:
I need to write a loop that tells the motor that every time the relay sends a signal (same as a button) the stepper motor has to turn X amount of steps, and then stop when it reaches a total of Y amount of steps no matter the condition of the relay signal.(this would be the dept of the key-way being cut)
And all of this has to only start once the "zero" button is pressed.