So that I could wind 6 identical coils, I needed some way of counting the turns. So I made a simple addon to my milling machine. This consisted of a few 3D printed parts. Firstly a cam that could be bolted onto the milling machine spindle. And also a bracket that allowed a large "micro" switch to be added.
The microswitch was connected to a Seeeduino XIAO, a simple Arduino compatible microcontroller which was in turn connected to a MAX7219 based 7 segment display module.
The code that does the counting uses an interrupt to record the state change of the switch and a time based debouncing logic.
#include "LedControl.h" // MAX7219 Led display driver LedControl lc=LedControl(9,8,7,1); volatile int i = 0; int counter = 0; // the following variables are unsigned longs because the time, measured in // milliseconds, will quickly become a bigger number than can be stored in an int. unsigned long lastDebounceTime = 0; // the last time the output pin was toggled unsigned long debounceDelay = 250; // the debounce time; increase if the output flickers void setup() { pinMode(2, INPUT_PULLUP); pinMode(LED_BUILTIN, OUTPUT); attachInterrupt(digitalPinToInterrupt(2),buttonISR,FALLING); lastDebounceTime = millis(); lc.shutdown(0,false); lc.setIntensity(0,8); lc.clearDisplay(0); } void loop() { displayLed(); processButton(); displayCount(); } void displayLed() { int output = digitalRead(2); digitalWrite(LED_BUILTIN,output); } void displayCount() { lc.setDigit(0,3,(int)counter/1000,false); lc.setDigit(0,2,((int)counter/100*100-(int)counter/1000*1000)/100,false); lc.setDigit(0,1,((int)counter/10*10-(int)counter/100*100)/10,false); lc.setDigit(0,0,counter-(int)counter/10*10,false); } void processButton() { if (i != 0) { if ((millis() - lastDebounceTime) > debounceDelay) { counter++; lastDebounceTime = millis(); } i = 0; } } void buttonISR() //ISR function excutes when push button at pinD2 is pressed { i++; }
To wind the coils, a coil former was fitted to a Dremel sanding drum holder and clamped into the chuck of the mill. A spool of copper wire was mounted on a wooden spindle clamped in the vice and then the end was fixed to the former using tape. The mill was then set to a very low speed. After a successful run, I then had to do it all over again as I'd forgotten to leave the end of the wire sticking out so that it could be connected.
Note that it would be dangerous to operate this at higher speeds.
Top Comments