Some time back you helped with my project (saw dust collector). Trying to update the mechanical part to improve the vacuum seal in the rotating part. Quick description about the project. Using ACS712 sensor to detect which power tool is in use. That drives the stepper to move the disc to the correct opening. Intermittently, when turning a tool on, the disc jumps the wrong direction (about a quarter inch) then moves in correct direction to the opening. At that position it is not lined up completely. It's off by the amount of the backwards jump. Like it moved the correct number of steps from where the jump ended.
I have played with the Debounce time with no help. I have manually applied 5v to the ACS712 outputs in a variety of sequence and it appears to always work correctly, Never any jumps.
The new disc that's turning is lighter than the older disc. I don't know if this is a coding issue or hardware?
Code below
Greg
```cpp
//4/10/2025
/*Auto Blast gate project: for dust collection in wood shop.
Arduino Nano
ACS712 current sensor
DRV8825 stepper driver with expansion card
Nema 23 stepper/ STEPPERONLINE Low Current Nema 23 CNC Stepper Motor 1.8A 340oz.in/2.4Nm
Halls effect homing sensor
Homing routine is run at startup or reset to establish stepper position
Each tool will be monitor by a current sensor and when that analog port exceeds a given threshold
1. Rotate the stepper to a predetermined position to align ports for that tool.
2. After the gate is align a digital pin will drive relay to turn on Vacuum system.
Vacuum will stay on as long as sensor exceeds the threshold while tool is running.
When tool stops, vacuum will continue for 4 (adjustable) seconds to clear remaining dust.
3. If the same tool is used next, the Stepper will remain in its current position.
But the vacuum system should still operate the same.
4. Rotating disk is 18" diameter with 8 position, 6 control by the ACS712 detecting Tool in use,
2 control by buttons for non-Tool use.*/
#define MAX8BUTTONS
#include <MobaTools.h>
#include <Arduino.h>
const int stepRev = 6400; // steps per revolution
const byte dirPin = 4; // adjust stepper pins to your needs
const byte stepPin = 5; //
const byte enablePin = 8;
const int vacPin = 7; // Drives relay to turn on Vacuum
const byte halPin = 11; // homing sensor
MoToTimer vacTimer; // for delayed switch off
const long runOnTime = 3000; // time for vac delay adjustable
// create stepper object
MoToStepper myStepper( stepRev, STEPDIR );
//......CREATE BUTTON OBJECTS ......
// A0/Sweep/90° A1/Hose/135° A2/Down Draft/270° A3/Miter/315° A4/Drill/180° A5/Sander/225° A6/Bandsaw/45° A7/Tablesaw(home)/0°
const byte buttonPins[] = {A0,A1,A2,A3,A4,A5,A6,A7}; // All inputs for tools or positions with out tools
const long stepperPositions[] = {90, 135, 270, 315, 180, 225, 45, 0}; // in degrees, must be same number of elements as buttonPins
const byte buttonCnt = (8); // read analogue inputs und return states for MoToButtons
const int threshold [] = {520,520,520,520,520,520,520,520}; // A0, A1 are buttons, A2....A7 Adjustable for tools ACS712
int noCurrent = 520; //or specific value per sensor from array
byte difference = 10;
button_t readInputs()
{
button_t states = 0;
for ( byte i = 0; i < 8; i++ ) {
// read input and set according bit if value is greater than threshold
analogRead(buttonPins[i]);
//throw the first away, average the next two
if ((analogRead(buttonPins[i]) + analogRead(buttonPins[i])) / 2 > threshold[i]) states |= (1 << i);
}
return states;
}
MoToButtons myButtons( readInputs, 40, 500); // number of buttons/positions Debounce 20, 500
// ******* Home Function *****
void homing() {
digitalWrite(vacPin, 1);
myStepper.rotate(1); // myStepper.doSteps( stepsPerRev );//Should work also, at least after one revolution the sensor should be hit.
while ( digitalRead(halPin) ); // wait until we pass the sensor
myStepper.doSteps(15); //Adjust number to fine tune zero. Changes to speed and ramp can effect this
while( myStepper.moving() ); // wait until movement is finished
myStepper.setZero();
}
void setup() {
Serial.begin(9600);
myStepper.attach(stepPin, dirPin);
myStepper.setSpeed( 800 ); // X10 500-800
myStepper.setRampLen(1500 ); // 1500 steps to achive set speed -- 1250
myStepper.attachEnable( enablePin, 100, LOW ); // if you want to switch off power when stepper reached position
pinMode(vacPin, OUTPUT);
homing(); // CALL HOMING FUNCTION
}
void loop() {
Monitor(); // Function in a TAB
myButtons.processButtons(); // Check buttonstates
static int32_t lastPos = 0;
static int32_t newPos =0;
static int32_t offset = 0;
for ( byte pos = 0; pos < buttonCnt; pos ++ ) {
// check all tools
if ( myButtons.pressed(pos) ) {
lastPos=myStepper.read();
newPos = stepperPositions[pos]+offset; //deciding shortest direction
if ( (newPos-lastPos) >180 ) offset -= 360; //CW
if ( (newPos-lastPos) <-180 ) offset += 360; //CCW
newPos = stepperPositions[pos]+offset;
myStepper.write( newPos ); // Button was pressed, move stepper to the according position
newPos=true;
}
//**Vac control section**//
// Tool is still switched on, and stepper has reached its position -> start vac
if ( myButtons.state(pos) && myStepper.moving() == 0 ) {
digitalWrite(vacPin, 0); // Turn Vac on
}
// Tool has been switched off, start timer to switch off vac
if (myButtons.released(pos) ) {
vacTimer.setTime( runOnTime );
}
}
//Turn vac off after timer expires
if (vacTimer.expired() ) {
digitalWrite(vacPin, 1); //TURN VAC OFF
}
}




