This circuit is designed to control a CNC machine using a joystick module. The X and Y axes of the joystick control the X and Y motors of the CNC machine. An LED is used as an indicator, turning on when the spindle direction is active. The circuit includes a power supply, a CNC shield, stepper motors, a joystick module, an LED, resistors, and an Arduino UNO microcontroller.
NEMA23 Stepper Motor
KY-023 Dual Axis Joystick Module
CNC Shield V3 Engraving Machine Expansion Board
Power Supply
Resistor
LED: Two Pin (white)
A988 DRIVER
Arduino UNO
/*
* Arduino CNC Machine with Joystick Control and LED Indicator
* This sketch controls a CNC machine using a joystick module. The X and Y axes
* of the joystick control the X and Y motors of the CNC machine. An LED is used
* as an indicator, turning on when the spindle direction is active.
*/
// Pin definitions
const int xStepPin = 2;
const int xDirPin = 5;
const int yStepPin = 3;
const int yDirPin = 6;
const int ledPin = 13;
const int joyXPin = A0;
const int joyYPin = A1;
void setup() {
// Initialize motor control pins
pinMode(xStepPin, OUTPUT);
pinMode(xDirPin, OUTPUT);
pinMode(yStepPin, OUTPUT);
pinMode(yDirPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// Initialize joystick pins
pinMode(joyXPin, INPUT);
pinMode(joyYPin, INPUT);
}
void loop() {
// Read joystick values
int joyXVal = analogRead(joyXPin);
int joyYVal = analogRead(joyYPin);
// Control X motor
if (joyXVal > 512) {
digitalWrite(xDirPin, HIGH);
digitalWrite(xStepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(xStepPin, LOW);
delayMicroseconds(1000);
} else if (joyXVal < 512) {
digitalWrite(xDirPin, LOW);
digitalWrite(xStepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(xStepPin, LOW);
delayMicroseconds(1000);
}
// Control Y motor
if (joyYVal > 512) {
digitalWrite(yDirPin, HIGH);
digitalWrite(yStepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(yStepPin, LOW);
delayMicroseconds(1000);
} else if (joyYVal < 512) {
digitalWrite(yDirPin, LOW);
digitalWrite(yStepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(yStepPin, LOW);
delayMicroseconds(1000);
}
// Control LED indicator
if (joyXVal != 512 || joyYVal != 512) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
This code initializes the pins for the motors, joystick, and LED. It reads the joystick values and controls the X and Y motors accordingly. The LED is turned on when the joystick is moved in any direction.