Need help with a Stepper Motor Coil winder

Hi everyone,

I'm having great difficulty in wrapping my head around how to set up "my" (bits and pieces stolen from other projects) code (pasted below).

I am wanting to have several buttons that turn the stepper motor a set number of turns.
e.g. Button 1 turns the motor 120 (24000 steps) times. Button 2 turns the motor 240 times (48000 steps.

I am wanting the coil winder to behave like this:

  1. Do nothing until button press.
  2. On Button (x) do number of turns.
  3. Wait until further button press.

Currently I only one button seems to work.

#include <AccelStepper.h>
#include <MultiStepper.h>

#include <Stepper.h>

/* Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board, AccelStepper and Arduino UNO: number of steps/revolutions. More info: https://www.makerguides.com */
// Include the AccelStepper library:
// Motor pin definitions:
#define motorPin1  8      // IN1 on the ULN2003 driver
#define motorPin2  9      // IN2 on the ULN2003 driver
#define motorPin3  10     // IN3 on the ULN2003 driver
#define motorPin4  11     // IN4 on the ULN2003 driver
// Define the AccelStepper interface type; 4 wire motor in half step mode:
#define MotorInterfaceType 4
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library with 28BYJ-48 stepper motor:
AccelStepper stepper = AccelStepper(MotorInterfaceType, 8, 9, 10, 11);

int Button = 12; 
int ButtonA = 13;
int Motor = (8,9,10,11);
int Val = 0;
void setup() {
  // Set the maximum steps per second:
  stepper.setMaxSpeed(2400);
  pinMode (Button, INPUT_PULLUP);
  pinMode (ButtonA, INPUT_PULLUP);
  pinMode (Motor, OUTPUT);
}
void loop() {
  Val = digitalRead(Button);      // Setting the Val variable to the output of the
            // button, which can be either HIGH or LOW
  if (Val == LOW) {       // Statement to determine the state of the button
    digitalWrite(Motor, HIGH);     // If the button is pressed, the buzzer will sound
  } else {
    digitalWrite(Motor, LOW);  
 
   // Set the current position to 0:
  stepper.setCurrentPosition(0);
  // Run the motor forward at 500 steps/second until the motor reaches 2400 steps (12 revolutions):
  while (stepper.currentPosition() != 2400) {
    stepper.setSpeed(200);
    stepper.runSpeed();
  }
  delay(1000);
  // Reset the position to 0:
  stepper.setCurrentPosition(0);
}
   
   Val = digitalRead(ButtonA);      // Setting the Val variable to the output of the
            // button, which can be either HIGH or LOW
  if (Val == LOW) {       // Statement to determine the state of the button
    digitalWrite(Motor, HIGH);     // If the button is pressed, the buzzer will sound
  } else {
    digitalWrite(Motor, LOW);  
  
   // Set the current position to 0:
  stepper.setCurrentPosition(0);
  // Run the motor forward at 500 steps/second until the motor reaches 48000 steps (240 revolutions):
  while (stepper.currentPosition() != 48000) {
    stepper.setSpeed(200);
    stepper.runSpeed();
  }
  delay(1000);
  // Reset the position to 0:
  stepper.setCurrentPosition(0);
}
delay(1000);
}

Any help would be greatly appreciated

I'm having great difficulty... No information in those words. What happens and what is wanted?

You ought to use debugging test prints from inside the code. Activate Serial monitor in the IDE and use Serial.print in side the code to get knowing what the not functioning code is doing. Believe me, it works fantastically well! I have used that trick during a very long time.

Hi, @dtzimotzyegh
Welcome to the forum.

Have you seem this project?

Tom... :grinning: :+1: :coffee: :australia:

This is the coil winder I built several years ago. Keypad input for turns and perhaps speed, don't remember. Has a foot switch to start and to pause while winding. Display to show entry values and current turn count.
winder
We sold it when the company assets were auctioned.
Paul

What is this?

A hesitant, poetic way to write int Motor = 11; ? :grinning:

I thought maybe there were 4-dimensional ints that I just did not know about. :upside_down_face:

Just tested it on https://gcc.godbolt.org/ and yes, it does simplify to Motor=11

But in a very visually approaching, almost hesitating way.
A good method to make a sketch less obvious. :upside_down_face:

Hi,
Can you please post a circuit diagram including power supplies?
Please do not use Friitzy images, a hand drawn circuit will be fine.

Thanks... Tom... :grinning: :+1: :coffee: :australia:

Did you mean

  int Motor[4] = { 8, 9, 10, 11 } ;

i.e. an array of integer?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.