// https://forum.arduino.cc/t/an-arduino-to-control-and-count-to-200-rev-for-a-coil-winder/1323683
/*
- The wire is attached to one side of the bobbin.
- The bobbin is attached to the stepper motor spindle.
- A pulley is suspended on a rod above the bobbin.
- The motor rotates, turning the bobbin, taking up the wire.
- The servo arm pulls and pushes the pulley along the rod.
- The stepper motor has 200 steps per revolution
- Stepping every 0.5 ms makes about 2000 steps (10 revolutions) per second
*/
#include <Servo.h>
Servo servo;
const int servoPin = 4,
servoHome = 90,
servoSweep = 10, // off center limit
servoLeft = servoHome - servoSweep,
servoRight = servoHome + servoSweep;
int servoDir = 1, // - (left) or + (right)
servoAngle = servoLeft,
winderSpeed = 14; // analog A0
bool stepState = 0;
int steps, stepsPerRevolution = 200;
const byte dirPin = 2,
stepPin = 3;
unsigned long timer, timeout = 1000; // microseconds
void setup() {
Serial.begin(11520);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, HIGH);
servo.attach(servoPin);
servo.write(servoLeft);
}
void loop() {
if (micros() - timer > timeout) { // wait for next step
timer = micros(); // reset timer
step(); // move motor
if (steps++ > stepsPerRevolution) { // count to one revolution
steps = 0;
sweep(); // move servo every revolution
}
}
}
void sweep() {
if (servoAngle < servoLeft || servoAngle > servoRight) // check servo boundaries
servoDir = -servoDir; // change servo direction
servoAngle += servoDir; // change angle
servo.write(servoAngle); // move servo
}
void step() {
int usDelay = map(analogRead(winderSpeed), 0, 1023, 2000, 1000); // adjust spool speed
digitalWrite(stepPin, HIGH); // one step
delayMicroseconds(usDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(usDelay);
}WINDER SPEED
BOBBIN WINDER
THREAD GUIDE