I'm not great at programming as my main hobby is Model Railways but I need to make 150 small current transformer for part of a Block Detection design, this would be wound on a 3D printed bobbin about 25mm diameter with a core of 12 mm for Ferrite core ...
I can easily make up a jig with a Nema 17 motor with an Easydriver, but I'm not sure how I would go about a sketch to run it, so I would use a Nema 17 which has a 1.8 deg step and an SG90 for controlling the 38AWG wire across the bobbin, so for 200 turns would be 200 x 200 steps and a rocking motion for the SG90 ... I would be grateful for any help ...
Perhaps a description of a stepper motor coil winder I built years ago to wind a similar bobbin, but much fewer turns.
I used a foot switch to start and to pause the winding of the coil. The pause held the stepper in position so the operator could make any needed adjustments. The stepper was disabled to turn free at the end of the turn count.
The wire spool was held in a fixture that also straightened the wire before it was wound on the bobbin.
There was no attempt to automatically spread the coils across the bobbin. Operator controlled that by moving the wire straightener.
In my case the beginning of the coil and the end of the coil were both soldered to ears on the bobbin. How are you attaching the ends of your coil?
The stepper motor shaft was mated to a drill chuck which held a bolt with nuts to secure the bobbin.
Perhaps taking a look at the MobaTools stepper motor examples might help with exploring some possibilities:
Example 3 might be closest to your goal-- you could change the steps for one of the buttons to myStepper.doSteps(STEPS_REVOLUTION*200UL);
to get 200 revolutions.
Synchronizing the winding with the servo could possibly be done by computing the angle the servo should be at based on myStepper.currentPosition()
or myStepperdistanceToGo()
.
The width is 0.1007mm.
What is the width of the bobbin? (how many wire-widths wide?)
What is the depth of the bobbin? (how many wire-layers tall?)
Without a smooth layer of material between wire layers, you will find it impossible to get the same number of turns for each layer of wire. It will always try to fit into the groove between the turns of the previous layer.
If you add a 5th button to the Mobatools Example #3, something like this snippet could do the steps and compute a servo angle in step:
// 200 turns CW
if (button.pressed(Button5) ) {
myStepper.doSteps(STEPS_REVOLUTION*200UL);
startMotion = myStepper.currentPosition();
winding = true;
}
if(winding){
static long intermediate = startMotion;
long currentPos = myStepper.currentPosition();
long dtg = myStepper.distanceToGo();
if(dtg == 0 ){
winding = false;
}
if(currentPos - intermediate >= 100){
intermediate += 100;
Serial.print("Steps:");
Serial.print(currentPos - startMotion);
Serial.print(" Servo:");
Serial.print(90+90*cos(PI*(currentPos - startMotion)/1600.0));
Serial.println();
}
}
I would suppose you'd want some triangular motion rather than a sinusoidal motion.
+/- one wire width is acceptable.
[edit] After coding a stepper motor with a servo and realizing my sewing machine has all the right stuff to load a bobbin... I would borrow your wife's sewing machine (you could borrow mine) and ask her how to load a bobbin. You will load 100 bobbins before dinner.
[edit+edit] A friend had a summer job at an electronics factory where he was to thread two nuts onto each of 10,000 machine screws. He made a battery powered DC motor with a button. He finished in less than a month, received two months' pay for his work, and was released along with the others, none of whom made their quota.
sketch.ino
// 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 1000 steps (5 revolutions) per second
*/
#include <Stepper.h>
#include <Servo.h>
const byte stepsPerRevolution = 200;
const byte dirPin = 2, stepPin = 3;
bool stepState = 0;
Servo servo;
const byte servoPin = 4;
const int servoHome = 90, servoSweep = 10;
const int servoLeft = servoHome - servoSweep, servoRight = servoHome + servoSweep;
int servoDir = 1; // - (left) or + (right)
int servoAngle = servoLeft;
int steps;
unsigned long timer, timeout = 500; // microseconds
void setup() {
Serial.begin(11520);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, HIGH);
servo.attach(servoPin);
servo.write(servoAngle);
}
void loop() {
if (micros() - timer > timeout) { // wait for next step
timer = micros(); // reset timer
step(); // move motor
if (steps++ > stepsPerRevolution) { // move servo every revolution
steps = 0;
sweep(); // move servo
}
}
}
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() {
digitalWrite(stepPin, stepState);
delay(1);
digitalWrite(stepPin, !stepState);
}
diagram.json
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": -4.8, "left": -0.5, "attrs": {} },
{
"type": "wokwi-stepper-motor",
"id": "stepper1",
"top": -192.01,
"left": 214.62,
"attrs": { "size": "8" }
},
{ "type": "wokwi-a4988", "id": "drv1", "top": -110.4, "left": 129.6, "attrs": {} },
{ "type": "wokwi-vcc", "id": "vcc1", "top": -191.24, "left": 192, "attrs": {} },
{ "type": "wokwi-gnd", "id": "gnd1", "top": -9.6, "left": 181.8, "attrs": {} },
{
"type": "wokwi-servo",
"id": "servo1",
"top": -183.4,
"left": 1.8,
"rotate": 270,
"attrs": {}
}
],
"connections": [
[ "vcc1:VCC", "drv1:VMOT", "red", [ "v0" ] ],
[ "vcc1:VCC", "drv1:VDD", "red", [ "v0" ] ],
[ "gnd1:GND", "drv1:GND.1", "black", [ "v0" ] ],
[ "gnd1:GND", "drv1:GND.2", "black", [ "v0" ] ],
[ "drv1:2B", "stepper1:A+", "green", [ "h0" ] ],
[ "drv1:2A", "stepper1:A-", "green", [ "h0" ] ],
[ "drv1:1A", "stepper1:B-", "green", [ "h0" ] ],
[ "drv1:1B", "stepper1:B+", "green", [ "h0" ] ],
[ "drv1:RESET", "drv1:SLEEP", "green", [ "h-19.2", "v0" ] ],
[ "nano:2", "drv1:DIR", "green", [ "v0" ] ],
[ "nano:3", "drv1:STEP", "green", [ "v0" ] ],
[ "nano:4", "servo1:PWM", "green", [ "v0" ] ],
[ "vcc1:VCC", "servo1:V+", "red", [ "v134.4", "h-115.2" ] ],
[ "gnd1:GND", "servo1:GND", "black", [ "v-9.6", "h-115.2" ] ]
],
"dependencies": {}
}
Hi Paul, Thanks for response, Can I give you a bit more background into the reason and how it works ... So most Model Railways run on DCC power of about 15 volts AC which is a square wave at about 25khz and this is a NMRA standard, I am using a DCCEX setup via an Arduino Mega and Motor Shield ... So I want to make a Block detection using current Transformers, to buy commertial is very expensive for my layout you are looking at £2000 just for boards, so my idea which is used by other people is a primary connected to the Track on one side is just 1 turn through the transformer core, the secondary is 200 turns which I take via some passive components and a 1N5819 to a BC547 transistor the Collector then feeds to a CD4049 inverting Buffer so I get Logic output ... this then feeds to a series of MCP23017 chips back via I2C to the DCCEX Arduino Mega ...
The way I want to try and this is work in progress is to 3D print a bobbin about 25mm Dia with a centre hole of 10mm for the Ferrite Core to fit, the core is 10mm x 6mm (Hole) x 5mm wide so the bobbin will have a centre for winding of about 12mm and about 7mm wide again for winding, this bobbin will then fit onto a vertical part " L " shaped with 2 1.5mm holes to connect ends of the 38AWG wire and then secure to a PCB, how the windings are layed is not important so long as I can get a rough layering the current through the coil is nothing its just a secondary output then via a 10kohm resistor to the rest of the circuit ... So the MERG design Block detection which is £20.00 use Murata 56200C transformers, these are about £1.40 from Farnells or RS I need 150 so not cheap, to buy the boards from MERG I would need 15 so as they are £20.00 each thats £300.00, the board I designed cost £40.00 inc components from Aliexpress and JLCPCB for boards, so if I can make my own coils that would be a big saving ...
Sorry for the long reply
John
Thanks Dave I did a full explanation of the idea to Paul so your sketch will help ... the other thing I would need as well as the Nema 17 Stepper is an SG90 and I think I would need to more over an angle of 20 deg to layer the wire so as I use SG90 for points and in the DCCEX Installer sketch I use 150 and 350 for the movement of about 45 deg ...
John
Then how pretty the windings look is a don't care. The number of turns is critical. BUT! The material mix of the ferrite is critical and is based on the frequency of your AC. Wrong mix of the material in the ferrite might be the same as using air. Research is required. Already pary of the cost for the commercial units.
No winding dont matter so long as they look uniform, and they are not critical I did actually order a few transformers from Aliexpress but they are 1000:1 to see what they are like, the input to the transistor is about 0.6v to turn it on so may get higher output from coil but I can increase the input resistors, I ordered a few Ferrite core from ebay to see if they work or not ..Pardon our interruption... ... thanks for the sketch I didnt notice at first but I will build a jig up shortly and try ...
John