#include // Define the number of steps per revolution for the 28BYJ-48 motor const int stepsPerRevolution = 160000; // Adjusted for 28BYJ-48 motor // Define pins using #define #define STEP_PIN D1 #define DIR_PIN D0 #define ENABLE_PIN D5 // Replace with actual pin #define HALL_SENSOR_PIN D10 // GPIO 10 for Hall Effect sensor // Create an instance of the AccelStepper class AccelStepper myStepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN); void setup() { // Set motor pins as outputs pinMode(ENABLE_PIN, OUTPUT); // Set enable pin as output // Set the initial motor state (disabled) digitalWrite(ENABLE_PIN, LOW); // Enable pin is usually LOW for active // Set the maximum speed of the motor (in steps per second) myStepper.setMaxSpeed(8000); // Adjust this value for desired speed // Set the acceleration of the motor (in steps per second squared) myStepper.setAcceleration(6000); // Adjust this value for desired smoothness // Setup Hall Effect sensor pin as input with internal pull-up resistor pinMode(HALL_SENSOR_PIN, INPUT_PULLUP); // Initialize serial communication Serial.begin(9600); // Enable the motor initially digitalWrite(ENABLE_PIN, LOW); // Start rotating the motor myStepper.move(-stepsPerRevolution); // Move the motor one revolution in reverse direction } void loop() { // Read the Hall Effect sensor value int hallValue = digitalRead(HALL_SENSOR_PIN); Serial.print("Hall Effect Sensor Value: "); Serial.println(hallValue); // Check if the Hall Effect sensor value is 0 if (hallValue == 0) { // Stop the motor myStepper.stop(); // Disable the motor digitalWrite(ENABLE_PIN, HIGH); } // Run the stepper motor myStepper.run(); }