// Test for Driver, Stepper Motors, and ESP32
// This version is optimized for a conveyor belt that rotates in one direction.
#define x_paso 15 // Defines the STEP pin for the X-axis motor
#define x_dire 2 // Defines the DIR (Direction) pin for the X-axis motor
#define x_habi 4 // Defines the ENABLE pin for the X-axis motor
// Global Variables
int retardo = 3000; // Delay in microseconds; a lower number makes the rotation faster
int pasos_por_vuelta = 200; // Standard for 1.8-degree motors (360° / 1.8° = 200 steps)
// Setup runs once when the board is powered on
void setup() {
// Configures the pins as OUTPUT to send control signals to the motor driver
pinMode(x_paso, OUTPUT);
pinMode(x_dire, OUTPUT);
pinMode(x_habi, OUTPUT);
// The Enable pin is set to LOW once to keep the driver always active
// This prevents the motor from losing its position or "letting go" between turns
digitalWrite(x_habi, LOW);
// The direction is fixed to HIGH at the start because the motor moves continuously in one direction
// You can change HIGH to LOW here if you need to reverse the fixed rotation sense
digitalWrite(x_dire, HIGH);
}
void loop() {
// This 'for' loop executes exactly 200 steps to complete one full rotation
// 'int i = 0' starts the counter, 'i < pasos_por_vuelta' sets the limit,
// and 'i++' adds one step per cycle until the turn is complete
for(int i = 0; i < pasos_por_vuelta; i++){
// Creating a Step Pulse:
digitalWrite(x_paso, HIGH); // Switches the step pin to HIGH to initiate a physical step
delayMicroseconds(retardo); // Maintains the HIGH state for a specific duration (defines speed)
digitalWrite(x_paso, LOW); // Switches the step pin to LOW to complete the pulse cycle
delayMicroseconds(retardo); // Wait time before the next pulse begins
}
// After completing a full turn (200 steps), the motor stops for 5000 milliseconds
// This 5-second pause represents the time needed to carry out the corresponding process
delay(5000);
}
/* * NOTE ON CODE EVOLUTION:
* The original 'giro' function and LED control (pin 33) were removed
* because the conveyor belt now follows a simpler, one-direction continuous path.
* All logic is integrated into the loop to ensure predictable movement and timing.
*/