Arduino Forum

Using Arduino => Project Guidance => Topic started by: gladewater2016 on May 17, 2018, 04:15 pm

Title: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 04:15 pm
I am copying a project I saw on youtube for my dust collection system. I have all of the components wired up, but when I turn the tool on, it isnt sending a signal to the relay to turn the dust collector on.


/*
 * This code is for the project at
 * http://www.ilimakestuff.com/how-to-automate-a-dust-collection-system-arduino
 * All of the components are list on the url above.
 *
This script was created by Bob Clagett for I Like To Make Stuff
For more projects, check out ilimakestuff.com

Includes Modified version of "Measuring AC Current Using ACS712"
http://henrysbench.capnfatz.com/henrys-bench/arduino-current-measurements/acs712-arduino-ac-current-tutorial/

Parts of this sketch were taken from the keypad and servo sample sketches that comes with the keypad and servo libraries.

Uses https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
 
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!

// our servo # counter
uint8_t servoCount = 6;
uint8_t servonum = 0;

const int OPEN_ALL = 100;
const int CLOSE_ALL = 99;

boolean buttonTriggered = 0;
boolean powerDetected = 0;
boolean collectorIsOn = 0;
int DC_spindown = 3000;

const int NUMBER_OF_TOOLS = 3;
const int NUMBER_OF_GATES = 6;

String tools[NUMBER_OF_TOOLS] = {"Miter Saw","Table Saw","Band Saw"}; //, "Floor Sweep"
int voltSensor[NUMBER_OF_TOOLS] = {A1,A2,A3};
long int voltBaseline[NUMBER_OF_TOOLS] = {0,0,0};

//DC right, Y, miter, bandsaw, saw Y, tablesaw, floor sweep
//Set the throw of each gate separately, if needed
int gateMinMax[NUMBER_OF_GATES][2] = {
  /*open, close*/
  {250,415},//DC right
  {230,405},//Y
  {230,405},//miter
  {285,425},//bandsaw
  {250,405},//saw y
  {250,415},//floor sweep
};

//keep track of gates to be toggled ON/OFF for each tool
int gates[NUMBER_OF_TOOLS][NUMBER_OF_GATES] = {
  {1,0,1,0,0,0},
  {1,1,0,0,1,1},
  {1,1,0,1,0,0},
};

const int dustCollectionRelayPin = 11;
const int manualSwitchPin = 12; //for button activated gate, currently NOT implemented

int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
double ampThreshold = .20;

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

//button debouncing
int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup(){
  Serial.begin(9600);
  pinMode(dustCollectionRelayPin,OUTPUT);
  pwm.begin();
  pwm.setPWMFreq(60);  // Default is 1000mS
 
 //record baseline sensor settings
 //currently unused, but could be used for voltage comparison if need be.
  delay(1000);
  for(int i=0;i<NUMBER_OF_TOOLS;i++){
    pinMode(voltSensor,INPUT);
    voltBaseline = analogRead(voltSensor);
  }
 
}

void loop(){
  // use later for button debouncing
  reading = digitalRead(manualSwitchPin);

  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH){
      state = LOW;
     buttonTriggered = false;
    } else{
      state = HIGH;
     buttonTriggered = true;
    time = millis();   
    }
  }
  previous = reading;
   Serial.println("----------");
   //loop through tools and check
   int activeTool = 50;// a number that will never happen
   for(int i=0;i<NUMBER_OF_TOOLS;i++){
      if( checkForAmperageChange(i)){
        activeTool = i;
        exit;
      }
      if( i!=0){
        if(checkForAmperageChange(0)){
          activeTool = 0;
          exit;
        }
      }
   }
  if(activeTool != 50){
    // use activeTool for gate processing
    if(collectorIsOn == false){
      //manage all gate positions
      for(int s=0;s<NUMBER_OF_GATES;s++){
        int pos = gates[activeTool];
        if(pos == 1){
          openGate(s);   
        } else {
          closeGate(s);
        }
      }
      turnOnDustCollection();
    }
  } else{
    if(collectorIsOn == true){
        delay(DC_spindown);
      turnOffDustCollection(); 
    }
  }
}
boolean checkForAmperageChange(int which){
   Voltage = getVPP(voltSensor[which]);
   VRMS = (Voltage/2.0) *0.707;
   AmpsRMS = (VRMS * 1000)/mVperAmp;
   Serial.print(tools[which]+": ");
   Serial.print(AmpsRMS);
   Serial.println(" Amps RMS");
   if(AmpsRMS>ampThreshold){
    return true;
   }else{
    return false;
   }
}
void turnOnDustCollection(){
  Serial.println("turnOnDustCollection");
  digitalWrite(dustCollectionRelayPin,1);
  collectorIsOn = true;
}
void turnOffDustCollection(){
  Serial.println("turnOffDustCollection");
  digitalWrite(dustCollectionRelayPin,0);
  collectorIsOn = false;
}
 
float getVPP(int sensor)
{
  float result;
 
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;          // store min value here
 
   uint32_t start_time = millis();
   while((millis()-start_time) < 500) //sample for 1 Sec
   {
       readValue = analogRead(sensor);
       // see if you have a new maxValue
       if (readValue > maxValue)
       {
           /*record the maximum sensor value*/
           maxValue = readValue;
       }
       if (readValue < minValue)
       {
           /*record the maximum sensor value*/
           minValue = readValue;
       }
   }
   
   // Subtract min from max
   result = ((maxValue - minValue) * 5.0)/1024.0;
     
   return result;
 }

void closeGate(uint8_t num){
  Serial.print("closeGate ");
  Serial.println(num);
  pwm.setPWM(num, 0, gateMinMax[num][1]);
}
void openGate(uint8_t num){
  Serial.print("openGate ");
  Serial.println(num);
    pwm.setPWM(num, 0, gateMinMax[num][0]);
    delay(100);
    pwm.setPWM(num, 0, gateMinMax[num][0]-5);
}
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 04:19 pm
I hope you see a problem with your post (ie., hard to read). Please take a few minutes to read through How to use this forum (http://forum.arduino.cc/index.php?topic=148996.0), especially the part on posting your code and using code tags. The latter will clean up your post.

We don't have you hardware, so we are not going to be able to test. You will have to tell us what hardware you have, how you have it wired (post a schematic), and what you have tried and the results.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 04:31 pm
I am using a acs712 to detect when a tool is turned on. I am using A0 pin to detect the signal and have the dust collector relay connected to digital pin 11
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 04:33 pm
How about fixing the OP so it can be read.

What signals are you getting from the ACS712? (I'm hoping you have a voltmeter)
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 04:38 pm
The serial plotter is showing the voltage increases from 3.5 volts to 5 when the tool is turned on. I am using a heat gun to similate a tool being turned on.
Title: Re: Automated Dust Collection
Post by: vffgaston on May 17, 2018, 04:41 pm
The serial plotter is showing the voltage increases from 3.5 volts to 5 when the tool is turned on. I am using a heat gun to similate a tool being turned on.
Looks threatening ...  ;)
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 04:45 pm
Code: [Select]
/*
 * This code is for the project at
 * http://www.ilimakestuff.com/how-to-automate-a-dust-collection-system-arduino
 * All of the components are list on the url above.
 *
This script was created by Bob Clagett for I Like To Make Stuff
For more projects, check out ilimakestuff.com

Includes Modified version of "Measuring AC Current Using ACS712"
http://henrysbench.capnfatz.com/henrys-bench/arduino-current-measurements/acs712-arduino-ac-current-tutorial/

Parts of this sketch were taken from the keypad and servo sample sketches that comes with the keypad and servo libraries.

Uses https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
 
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!

// our servo # counter
uint8_t servoCount = 6;
uint8_t servonum = 0;

const int OPEN_ALL = 100;
const int CLOSE_ALL = 99;

boolean buttonTriggered = 0;
boolean powerDetected = 0;
boolean collectorIsOn = 0;
int DC_spindown = 3000;

const int NUMBER_OF_TOOLS = 3;
const int NUMBER_OF_GATES = 6;

String tools[NUMBER_OF_TOOLS] = {"Miter Saw","Table Saw","Band Saw"}; //, "Floor Sweep"
int voltSensor[NUMBER_OF_TOOLS] = {A1,A2,A3};
long int voltBaseline[NUMBER_OF_TOOLS] = {0,0,0};

//DC right, Y, miter, bandsaw, saw Y, tablesaw, floor sweep
//Set the throw of each gate separately, if needed
int gateMinMax[NUMBER_OF_GATES][2] = {
  /*open, close*/
  {250,415},//DC right
  {230,405},//Y
  {230,405},//miter
  {285,425},//bandsaw
  {250,405},//saw y
  {250,415},//floor sweep
};

//keep track of gates to be toggled ON/OFF for each tool
int gates[NUMBER_OF_TOOLS][NUMBER_OF_GATES] = {
  {1,0,1,0,0,0},
  {1,1,0,0,1,1},
  {1,1,0,1,0,0},
};

const int dustCollectionRelayPin = 11;
const int manualSwitchPin = 12; //for button activated gate, currently NOT implemented

int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
double ampThreshold = .20;

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

//button debouncing
int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup(){
  Serial.begin(9600);
  pinMode(dustCollectionRelayPin,OUTPUT);
  pwm.begin();
  pwm.setPWMFreq(60);  // Default is 1000mS
 
 //record baseline sensor settings
 //currently unused, but could be used for voltage comparison if need be.
  delay(1000);
  for(int i=0;i<NUMBER_OF_TOOLS;i++){
    pinMode(voltSensor[i],INPUT);
    voltBaseline[i] = analogRead(voltSensor[i]);
  }
 
}

void loop(){
  // use later for button debouncing
  reading = digitalRead(manualSwitchPin);

  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH){
      state = LOW;
     buttonTriggered = false;
    } else{
      state = HIGH;
     buttonTriggered = true;
    time = millis();   
    }
  }
  previous = reading;
   Serial.println("----------");
   //loop through tools and check
   int activeTool = 50;// a number that will never happen
   for(int i=0;i<NUMBER_OF_TOOLS;i++){
      if( checkForAmperageChange(i)){
        activeTool = i;
        exit;
      }
      if( i!=0){
        if(checkForAmperageChange(0)){
          activeTool = 0;
          exit;
        }
      }
   }
  if(activeTool != 50){
    // use activeTool for gate processing
    if(collectorIsOn == false){
      //manage all gate positions
      for(int s=0;s<NUMBER_OF_GATES;s++){
        int pos = gates[activeTool][s];
        if(pos == 1){
          openGate(s);   
        } else {
          closeGate(s);
        }
      }
      turnOnDustCollection();
    }
  } else{
    if(collectorIsOn == true){
        delay(DC_spindown);
      turnOffDustCollection(); 
    }
  }
}
boolean checkForAmperageChange(int which){
   Voltage = getVPP(voltSensor[which]);
   VRMS = (Voltage/2.0) *0.707;
   AmpsRMS = (VRMS * 1000)/mVperAmp;
   Serial.print(tools[which]+": ");
   Serial.print(AmpsRMS);
   Serial.println(" Amps RMS");
   if(AmpsRMS>ampThreshold){
    return true;
   }else{
    return false;
   }
}
void turnOnDustCollection(){
  Serial.println("turnOnDustCollection");
  digitalWrite(dustCollectionRelayPin,1);
  collectorIsOn = true;
}
void turnOffDustCollection(){
  Serial.println("turnOffDustCollection");
  digitalWrite(dustCollectionRelayPin,0);
  collectorIsOn = false;
}
 
float getVPP(int sensor)
{
  float result;
 
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;          // store min value here
 
   uint32_t start_time = millis();
   while((millis()-start_time) < 500) //sample for 1 Sec
   {
       readValue = analogRead(sensor);
       // see if you have a new maxValue
       if (readValue > maxValue)
       {
           /*record the maximum sensor value*/
           maxValue = readValue;
       }
       if (readValue < minValue)
       {
           /*record the maximum sensor value*/
           minValue = readValue;
       }
   }
   
   // Subtract min from max
   result = ((maxValue - minValue) * 5.0)/1024.0;
     
   return result;
 }

void closeGate(uint8_t num){
  Serial.print("closeGate ");
  Serial.println(num);
  pwm.setPWM(num, 0, gateMinMax[num][1]);
}
void openGate(uint8_t num){
  Serial.print("openGate ");
  Serial.println(num);
    pwm.setPWM(num, 0, gateMinMax[num][0]);
    delay(100);
    pwm.setPWM(num, 0, gateMinMax[num][0]-5);
}
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 04:55 pm
@gladewater2016, how much experience do you have with the Arduinos?

Which Arduino do you have?

How many ACS712 do you have?

As I read the code, you need at least 2 (actually will need 4).
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 04:58 pm
I am using the arduino uno and a adafruit 16x12 bit servo shield. If and when I get the project finished, It will be udes on 6 different tools, so there will be 6, acs712,.
My arduino knowledge is very limited
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 05:03 pm
How many ACS712 do you have now?

These two lines

String tools[NUMBER_OF_TOOLS] = {"Miter Saw","Table Saw","Band Saw"}; //, "Floor Sweep"
int voltSensor[NUMBER_OF_TOOLS] = {A1,A2,A3};

Show which sensor is assigned to each tool.

These lines:

for(int i=0;i<NUMBER_OF_TOOLS;i++)
{
 if( checkForAmperageChange(i))
 {
   activeTool = i;
   exit;
 }
 if( i!=0)
  {
   if(checkForAmperageChange(0))
   {
     activeTool = 0;
     exit;
   }
 }

check for the tool to be turned on.

If the one ACS712 you have is wired to A0, it will not cause the DC to turn on. Try plugging it into A1.


The program also has lots of output to the serial monitor. Can you post some using code tags.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 05:11 pm
I plugged it into A1. The serial plotter is showing a voltage increase when I turn the heat gun on. I am using a heat gun to similate the tool being turned on. I am not getting a signal to turn the dust collector relay on
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 05:13 pm
Does the serial monitor show the arduino is trying to turn on the DC?

void turnOnDustCollection(){
  Serial.println("turnOnDustCollection");
  digitalWrite(dustCollectionRelayPin,1);
  collectorIsOn = true;
}
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 05:18 pm
When I turn the heat gun on, the amps change from 0.07 to 5.40. So I guess the answer is yes..?
Title: Re: Automated Dust Collection
Post by: groundFungus on May 17, 2018, 05:21 pm
Code: [Select]
for(int i=0;i<NUMBER_OF_TOOLS;i++)
{
 if( checkForAmperageChange(i))
 {
   activeTool = i;
   exit;
 }
 if( i!=0)
  {
   if(checkForAmperageChange(0))
   {
     activeTool = 0;
     exit;
   }
 }

What do you think that the exit statements do in this snippet?
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 05:23 pm
There should not be a guess. The text listed in post #11 will be printed in the serial monitor. The serial monitor is in the same menu and right above the Serial Plotter.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 05:27 pm
The serial monitor is where I am seeing the amp increase when I turn the heat gun on. It is showing a amp increase on the miter saw from 0.07 to 5.40
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 05:28 pm
You never see it print "turnOnDustCollection"?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 05:32 pm
no
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 05:33 pm
Code: [Select]
for(int i=0;i<NUMBER_OF_TOOLS;i++)
{
 if( checkForAmperageChange(i))
 {
   activeTool = i;
   exit;
 }
 if( i!=0)
  {
   if(checkForAmperageChange(0))
   {
     activeTool = 0;
     exit;
   }
 }

What do you think that the exit statements do in this snippet?
Find tool and exit loop(). Cute function. I'm thinking this doesn't work very well.

Luckily I can admit that I didn't write it.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 05:38 pm
I guess the million dollar question is, how do I fix it so it will turn on the dust collector and open a servo for the blast gate for the miter saw?
Title: Re: Automated Dust Collection
Post by: groundFungus on May 17, 2018, 05:39 pm
Actually the exit; does nothing but throw this warning.   

Code: [Select]
...\arduino_modified_sketch_800891\sketch_may17b.ino: In function 'void setup()':

C:\Users\DaD\AppData\Local\Temp\arduino_modified_sketch_800891\sketch_may17b.ino:9:11: warning: statement is a reference, not call, to function 'exit' [-Waddress]
       exit;
           ^
...\arduino_modified_sketch_800891\sketch_may17b.ino:9:11: warning: statement has no effect [-Wunused-value]



The exit(0) function would exit loop, disable interrupts and freeze.
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 05:42 pm
Actually the exit; does nothing but throw this warning.    

Code: [Select]
...\arduino_modified_sketch_800891\sketch_may17b.ino: In function 'void setup()':

C:\Users\DaD\AppData\Local\Temp\arduino_modified_sketch_800891\sketch_may17b.ino:9:11: warning: statement is a reference, not call, to function 'exit' [-Waddress]
       exit;
           ^
...\arduino_modified_sketch_800891\sketch_may17b.ino:9:11: warning: statement has no effect [-Wunused-value]



The exit(0) function would exit loop, disable interrupts and freeze.
That code is in loop(), not in setup(). Why does the compiler think it is in setup()?


I installed the Adafruit PWM Servo library (against my better judgement) and do not get any errors:

Code: [Select]

Build options changed, rebuilding all
Sketch uses 9122 bytes (3%) of program storage space. Maximum is 253952 bytes.
Global variables use 659 bytes (8%) of dynamic memory, leaving 7533 bytes for local variables. Maximum is 8192 bytes.
Title: Re: Automated Dust Collection
Post by: groundFungus on May 17, 2018, 05:49 pm
I did not say error.

Do you have all warnings turned on in Preferences?  I installed the Adafruit library and compiled his code and got the same warning.
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 05:50 pm
Warnings. Errors. I don't care. I don't release code with warnings.

Show verbose output during compilation is checked and Compiler warnings is set to ALL.

Why would it freeze? Exit() would just bail from loop() back to main(). It does not sound like it is freezing as the OP is reporting seeing the Serial monitor providing data.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 05:52 pm
I am using the same code that the original builder of the system used. His system is identical to mine. The only exception is, I will be adding more tools than he did.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 06:06 pm
Any suggestions on how to fix it and make it work?
Title: Re: Automated Dust Collection
Post by: groundFungus on May 17, 2018, 06:08 pm
Arduino and exit(0) (http://forum.arduino.cc/index.php?topic=216073.0)
I tried to point out a potential problem.  The program flow may not be as desired if the exit (whatever it is supposed to do) is ignored.  I'm done.
Title: Re: Automated Dust Collection
Post by: adwsystems on May 17, 2018, 06:12 pm
You make a good point, unfortunately you are not speaking with the creator of the program so it is landing on partially deaf ears.

On another note, I don't think I have ever used exit.

As for me helping fix it. I can, later. It is becoming a larger issue. Perhaps the OP can contact the author for direct assistance?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 06:22 pm
I attempted to contact the original author a couple of months ago. He hasnt replied. The only way to contact him is by twitter.
This is probably he only project I will do with the arduino.
 I wouldnt mind paying someone to rewrite the code or what ever is necessary to make this work. Can you point me in the direction of someone who can do that?
Title: Re: Automated Dust Collection
Post by: groundFungus on May 17, 2018, 06:31 pm
First try replacing the exit statements with break statements.  The intent seems to be to break out of the for loop at those points.  Worth a try.

Code: [Select]
for(int i=0;i<NUMBER_OF_TOOLS;i++)
{
 if( checkForAmperageChange(i))
 {
   activeTool = i;
   break;
 }
 if( i!=0)
  {
   if(checkForAmperageChange(0))
   {
     activeTool = 0;
     break;
   }
 }
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 06:38 pm
I tried that, didnt work
Title: Re: Automated Dust Collection
Post by: wvmarle on May 17, 2018, 06:45 pm
Then how about following the suggestion from quite a few posts ago to post the output you see on the Serial monitor (between CODE tags!) around the time you switch on the tool. That could be quite helpful in trying to follow what's happening in that code.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 17, 2018, 06:52 pm
How do I do that?
Title: Re: Automated Dust Collection
Post by: wvmarle on May 17, 2018, 08:09 pm
Just copy/paste from the Serial monitor.
Title: Re: Automated Dust Collection
Post by: dave-in-nj on May 18, 2018, 02:37 am
I have to hit the scroll box to stop scrolling, then hit 'crtl a' to select then 'ctrl c' to copy
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 18, 2018, 02:40 pm
 ----------
Miter Saw: 0.07 Amps RMS
Table Saw: 4.02 Amps RMS
Miter Saw: 0.07 Amps RMS
Band Saw: 4.24 Amps RMS
Miter Saw: 0.07 Amps RMS
openGate 0
openGate 1
closeGate 2
openGate 3
closeGate 4
closeGate 5
turnOnDustCollection
----------
Miter Saw: 0.07 Amps RMS
Table Saw: 3.83 Amps RMS
Miter Saw: 0.07 Amps RMS
Band Saw: 4.05 Amps RMS
Miter Saw: 0.07 Amps RMS
----------
Miter Saw: 5.43 Amps RMS
Table Saw: 4.19 Amps RMS
Miter Saw: 5.40 Amps RMS
Band Saw: 4.62 Amps RMS
Miter Saw: 5.36 Amps RMS
----------
Miter Saw: 5.36 Amps RMS
Table Saw: 4.37 Amps RMS
Miter Saw: 5.36 Amps RMS
Band Saw: 4.11 Amps RMS
Miter Saw: 5.36 Amps RMS
----------
Miter Saw: 5.36 Amps RMS
Table Saw: 4.38 Amps RMS
Miter Saw: 5.36 Amps RMS
Band Saw: 4.15 Amps RMS
Title: Re: Automated Dust Collection
Post by: groundFungus on May 18, 2018, 03:32 pm
Quote
it isnt sending a signal to the relay to turn the dust collector on.
Is this still the issue?

I wired up a test circuit on my Uno and ran the code from post #6.  I used a LED on pin 11 to watch the dust collector relay output.  When one of the analog inputs goes high the LED does turn on and then LED turns off, after a delay, when the  input is brought low.  So, the code seems to be working.  If the relay is not turning on it is looking like a hardware problem.  

Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 18, 2018, 05:14 pm
Ok. Stupid question. Does the led go on pin 11 and ground
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 18, 2018, 05:28 pm
I connected a led to pin 11 and ground. The led came on as soon as I connected it
Title: Re: Automated Dust Collection
Post by: groundFungus on May 18, 2018, 08:04 pm
Are all of the analog inputs that you are using at near 0V?  If any are floating (or high) that could turn on the LED.
Title: Re: Automated Dust Collection
Post by: adwsystems on May 18, 2018, 08:08 pm
@gladewater2016, any chance of posting pictures of your setup?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 03:07 pm
I added a picture of my setup.
Title: Re: Automated Dust Collection
Post by: wvmarle on May 20, 2018, 03:15 pm
Why no power for the Arduino? They don't tend to work well without.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 03:17 pm
woops. Power now
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 03:25 pm
sorry. uploaded wrong pic
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 03:30 pm
The analog inputs A2 and A3 are floating so may be reading high enough to be mistaken for a tool on condition,  Ground the unused analog inputs and try your code.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 03:37 pm
I grounded A2 and A3. Now I am getting a signal to 11 before I turn the tool on. When I turn the tool on, the relay stays on
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 03:43 pm
a2 and a3 grounded
Title: Re: Automated Dust Collection
Post by: wvmarle on May 20, 2018, 03:49 pm
I grounded A2 and A3. Now I am getting a signal to 11 before I turn the tool on. When I turn the tool on, the relay stays on
That's as it should be, isn't it?
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 03:55 pm
Can you show a sample of the serial monitor output as you power a tool on and off? 
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 04:08 pm
It is switching the relay now. It is just working backwards from what I expected. But that is fine.. Now the next problem is the servo. When the tool is turned on, I am not getting a signal to open the servo. I added a 5vt power supply to the adafruit  servo board
Title: Re: Automated Dust Collection
Post by: wvmarle on May 20, 2018, 04:12 pm
It is switching the relay now. It is just working backwards from what I expected. But that is fine..
That may be simply your relay working in reverse. Some are active high, others active low, and then there's the NO side and the NC side.
Anyway it's a matter of changing those states in your code and you should be good to go.

For the servo part, do you have the servo working with basic servo example scripts, like sweep? Always good to use those to test your components. If that doesn't work it's wiring; if it does work it's in your code.

After making those changes please do post the latest version of your code (properly formatted, in a new message).
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 04:23 pm
I have a small simple servo and a more expensive digital servo.The small servo is working with the sweep code when connected to pin 9, but the digital servo isnt working. Also neither one will work when connected to the servo pins on the adafruit board.
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 04:56 pm
You might want to run an I2C scanner to confirm the device address (SB 0x40) and that the device is communicating on the I2C bus.   

Code: [Select]
// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

  // Leonardo: wait for serial port to connect
  while (!Serial)
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}




Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 05:05 pm
This is what I got.
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 05:14 pm
I thought that I saw a solder blob on the A0 address selection jumper.   Change the I2C address in the sketch to 0x41.

Make it look like this:
Code: [Select]
// called this way, it uses the default address 0x40
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 05:26 pm
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41

This is what my code looks like. Should the solder blob not be there?
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 05:41 pm
I know that is how your code looks.  The solder blob changes the address from the default (0x40) that is in your code to 0x41.  You can either change your code to what I posted (set the address to 0x41) or un-solder the address jumper and leave the coded address at 0x40.  Up to you.  I would just change the address in the code.

Please post the latest version of your code if you make any changes.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 05:44 pm
I changed the code to match what you said. Still doesnt work
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 05:56 pm
Please post the latest version of your code if you make any changes..



Does the dust collector relay operate when it should?  Does the serial output show the gate positions when a tool is turned on?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 06:01 pm
/*
 * This code is for the project at
 * http://www.ilimakestuff.com/how-to-automate-a-dust-collection-system-arduino
 * All of the components are list on the url above.
 *
This script was created by Bob Clagett for I Like To Make Stuff
For more projects, check out ilimakestuff.com

Includes Modified version of "Measuring AC Current Using ACS712"
http://henrysbench.capnfatz.com/henrys-bench/arduino-current-measurements/acs712-arduino-ac-current-tutorial/

Parts of this sketch were taken from the keypad and servo sample sketches that comes with the keypad and servo libraries.

Uses https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
 
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!

// our servo # counter
uint8_t servoCount = 6;
uint8_t servonum = 0;

const int OPEN_ALL = 100;
const int CLOSE_ALL = 99;

boolean buttonTriggered = 0;
boolean powerDetected = 0;
boolean collectorIsOn = 0;
int DC_spindown = 3000;

const int NUMBER_OF_TOOLS = 3;
const int NUMBER_OF_GATES = 6;

String tools[NUMBER_OF_TOOLS] = {"Miter Saw","Table Saw","Band Saw"}; //, "Floor Sweep"
int voltSensor[NUMBER_OF_TOOLS] = {A1,A2,A3};
long int voltBaseline[NUMBER_OF_TOOLS] = {0,0,0};

//DC right, Y, miter, bandsaw, saw Y, tablesaw, floor sweep
//Set the throw of each gate separately, if needed
int gateMinMax[NUMBER_OF_GATES][2] = {
  /*open, close*/
  {250,415},//DC right
  {230,405},//Y
  {230,405},//miter
  {285,425},//bandsaw
  {250,405},//saw y
  {250,415},//floor sweep
};

//keep track of gates to be toggled ON/OFF for each tool
int gates[NUMBER_OF_TOOLS][NUMBER_OF_GATES] = {
  {1,0,1,0,0,0},
  {1,1,0,0,1,1},
  {1,1,0,1,0,0},
};

const int dustCollectionRelayPin = 11;
const int manualSwitchPin = 12; //for button activated gate, currently NOT implemented

int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module
double ampThreshold = .20;

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

//button debouncing
int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup(){
  Serial.begin(9600);
  pinMode(dustCollectionRelayPin,OUTPUT);
  pwm.begin();
  pwm.setPWMFreq(60);  // Default is 1000mS
 
 //record baseline sensor settings
 //currently unused, but could be used for voltage comparison if need be.
  delay(1000);
  for(int i=0;i<NUMBER_OF_TOOLS;i++){
    pinMode(voltSensor,INPUT);
    voltBaseline = analogRead(voltSensor);
  }
 
}

void loop(){
  // use later for button debouncing
  reading = digitalRead(manualSwitchPin);

  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH){
      state = LOW;
     buttonTriggered = false;
    } else{
      state = HIGH;
     buttonTriggered = true;
    time = millis();   
    }
  }
  previous = reading;
   Serial.println("----------");
   //loop through tools and check
   int activeTool = 50;// a number that will never happen
   for(int i=0;i<NUMBER_OF_TOOLS;i++){
      if( checkForAmperageChange(i)){
        activeTool = i;
        exit;
      }
      if( i!=0){
        if(checkForAmperageChange(0)){
          activeTool = 0;
          exit;
        }
      }
   }
  if(activeTool != 50){
    // use activeTool for gate processing
    if(collectorIsOn == false){
      //manage all gate positions
      for(int s=0;s<NUMBER_OF_GATES;s++){
        int pos = gates[activeTool];
        if(pos == 1){
          openGate(s);   
        } else {
          closeGate(s);
        }
      }
      turnOnDustCollection();
    }
  } else{
    if(collectorIsOn == true){
        delay(DC_spindown);
      turnOffDustCollection(); 
    }
  }
}
boolean checkForAmperageChange(int which){
   Voltage = getVPP(voltSensor[which]);
   VRMS = (Voltage/2.0) *0.707;
   AmpsRMS = (VRMS * 1000)/mVperAmp;
   Serial.print(tools[which]+": ");
   Serial.print(AmpsRMS);
   Serial.println(" Amps RMS");
   if(AmpsRMS>ampThreshold){
    return true;
   }else{
    return false;
   }
}
void turnOnDustCollection(){
  Serial.println("turnOnDustCollection");
  digitalWrite(dustCollectionRelayPin,1);
  collectorIsOn = true;
}
void turnOffDustCollection(){
  Serial.println("turnOffDustCollection");
  digitalWrite(dustCollectionRelayPin,0);
  collectorIsOn = false;
}
 
float getVPP(int sensor)
{
  float result;
 
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;          // store min value here
 
   uint32_t start_time = millis();
   while((millis()-start_time) < 500) //sample for 1 Sec
   {
       readValue = analogRead(sensor);
       // see if you have a new maxValue
       if (readValue > maxValue)
       {
           /*record the maximum sensor value*/
           maxValue = readValue;
       }
       if (readValue < minValue)
       {
           /*record the maximum sensor value*/
           minValue = readValue;
       }
   }
   
   // Subtract min from max
   result = ((maxValue - minValue) * 5.0)/1024.0;
     
   return result;
 }

void closeGate(uint8_t num){
  Serial.print("closeGate ");
  Serial.println(num);
  pwm.setPWM(num, 0, gateMinMax[num][1]);
}
void openGate(uint8_t num){
  Serial.print("openGate ");
  Serial.println(num);
    pwm.setPWM(num, 0, gateMinMax[num][0]);
    delay(100);
    pwm.setPWM(num, 0, gateMinMax[num][0]-5);
}
The monitor is showing the dust collector coming on and going off but not the gates opening
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 06:08 pm
Miter Saw: 9.60 Amps RMS
Table Saw: 0.02 Amps RMS
Miter Saw: 9.55 Amps RMS
Band Saw: 0.02 Amps RMS
Miter Saw: 9.51 Amps RMS
openGate 0
closeGate 1
openGate 2
closeGate 3
closeGate 4
closeGate 5
turnOnDustCollection
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 06:14 pm
It is showing it is opening the gate
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 06:52 pm
Code: [Select]
// called this way, it uses the default address 0x40
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

The above was what I posted to change the I2C address.

Code: [Select]
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

Your code is not the same.  You have used the default constructor which uses the default address, 0x40.

Please post code in code tags.  Do you look at your posts after you send them?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 09:13 pm
Im missing something. I dont see the difference.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 09:53 pm
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);

I couldnt figure out what you are talking about so I unsoldered the jumper.
Is this right?
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 10:19 pm
To set the address to the default, yes.
Did it work?  Did you run the I2C scanner again to see if the address changed?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 10:22 pm
Yes. I ran the scanner again, but it still doesnt work
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 10:27 pm
I2C scanner. Scanning ...
Found address: 65 (0x41)
Found address: 112 (0x70)
Done.
Found 2 device(s).
 This is what it shows now
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 20, 2018, 11:08 pm
I ran the adafruit servo test program and none of the servos are working
Title: Re: Automated Dust Collection
Post by: groundFungus on May 20, 2018, 11:19 pm
Quote
Found address: 65 (0x41)
The address of the servo shield is still 0x41.  It appears the the blob removal was not effective.

Until you get the address in the code to match the address of the shield it won't work. 
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 21, 2018, 12:01 am
I put the blob back on.Then I ran the scan again.This is what I got.
I2C scanner. Scanning ...
Found address: 65 (0x41)
Found address: 112 (0x70)
Done.
Found 2 device(s).
Why is it showing two different devices?


// called this way, it uses the default address 0x41
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

Im sorry Im not understanding what I need to do. Is this how it is suopposed to be?
I really do appreciate you help!!
Title: Re: Automated Dust Collection
Post by: groundFungus on May 21, 2018, 12:26 am
Code: [Select]
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);


The double slashes (//) in front of a line tells the compiler to ignore that line.  The line is a comment and is said to be commented out.  In your rcode all of the lines except
Code: [Select]
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
are commented out. The line that is not commented is the the default constructor and assigns the default address (0x40) because there is no parameter for Adafruit_PWMServoDriver().


This is the code that I posted
Code: [Select]
// called this way, it uses the default address 0x40
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

The first 3 lines are commentd out (ignored).  The only line that is not commented out is the last line.
Code: [Select]
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
That constructor includes a parameter for Adafruit_PWMServoDriver(0x41) to set the address to 0x41.

Idon't know what the other device address is for.  What else is connected to your project?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 21, 2018, 12:43 am
The only other thing connected is the acs712 and the relay
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 21, 2018, 12:53 am
// called this way, it uses the default address 0x40
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);   

Is this how it is supposed to be?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 21, 2018, 12:59 am
Now that I changed the code, only one device is showing.
I2C scanner. Scanning ...
Found address: 65 (0x41)
Done.
Found 1 device(s).


But it still isnt working
Title: Re: Automated Dust Collection
Post by: adwsystems on May 21, 2018, 01:01 am
I put the blob back on.Then I ran the scan again.This is what I got.
I2C scanner. Scanning ...
Found address: 65 (0x41)
Found address: 112 (0x70)
Done.
Found 2 device(s).
Summary is that you have the Arduino, Servo driver, ACS712, and the relay board. Nothing else. Only one of those uses I2C and uses one address. Something doesn't make sense. Take off the servo driver we suspect is at 0x41 and report the results.

Title: Re: Automated Dust Collection
Post by: adwsystems on May 21, 2018, 01:01 am
Now that I changed the code, only one device is showing.
I2C scanner. Scanning ...
Found address: 65 (0x41)
Done.
Found 1 device(s).


But it still isnt working
Changed what code? Did you change something in the I2C Scanner code?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 21, 2018, 02:30 am
I got everything working now except for the timing of the servos. Thats another day after I do more research.
I changed the address  in the scanner and the second device went away
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 21, 2018, 02:40 am
Should I start another post for help with the servos?
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 21, 2018, 05:17 pm
I have everything working except for the servo timing. Can someone help me with that?
Title: Re: Automated Dust Collection
Post by: groundFungus on May 21, 2018, 05:24 pm
Please post your latest code and describe what it is doing and how that differs from what you want.
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 22, 2018, 03:55 am
{250,415},//DC right
  {230,405},//Y
  {230,405},//miter
  {285,425},//bandsaw
  {250,405},//saw y
  {250,415},//floor sweep

This the part of the code I have a question about. It tells the servos what position to go to,Right? What do the numbers represent? Voltage, angle?
The servos that I am going to use are DS3218MG digital servos.
I will have 6 servos when I get done. They will have different names
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 22, 2018, 04:01 am
//keep track of gates to be toggled ON/OFF for each tool
int gates[NUMBER_OF_TOOLS][NUMBER_OF_GATES] = {
{1,0,1,0,0,0},
 {1,1,0,0,1,1},
 {1,1,0,1,0,0},
Can you also please explain this part of the code
Title: Re: Automated Dust Collection
Post by: gladewater2016 on May 25, 2018, 11:57 am
Code: [Select]

/*
 * This code is for the project at
 * http://www.ilimakestuff.com/how-to-automate-a-dust-collection-system-arduino
 * All of the components are list on the url above.
 *
This script was created by Bob Clagett for I Like To Make Stuff
For more projects, check out ilimakestuff.com and modified by Terry Neal

Includes Modified version of "Measuring AC Current Using ACS712"
http://henrysbench.capnfatz.com/henrys-bench/arduino-current-measurements/acs712-arduino-ac-current-tutorial/

Parts of this sketch were taken from the keypad and servo sample sketches that comes with the keypad and servo libraries.

Uses https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
 
// called this way, it uses the default address 0x40
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
//servos used DS3218mg
// our servo # counter
uint8_t servoCount = 6;
uint8_t servonum = 0;

const int OPEN_ALL = 100;
const int CLOSE_ALL = 99;

boolean buttonTriggered = 0;
boolean powerDetected = 0;
boolean collectorIsOn = 0;
int DC_spindown = 3000;
//allow vacuum system to run after tool is turned off
const int NUMBER_OF_TOOLS = 3;
const int NUMBER_OF_GATES = 3;

String tools[NUMBER_OF_TOOLS] = {"#1","#2","#3"};
int voltSensor[NUMBER_OF_TOOLS] = {A0,A1,A2};
long int voltBaseline[NUMBER_OF_TOOLS] = {0,0,0};

 
//Set the throw of each gate separately, if needed
int gateMinMax[NUMBER_OF_GATES][2] = {
 
  /*close, open*/
 
  {230,375},//#1
  {195,410},//#2
  {250,400},//#3
 
 
};

//keep track of gates to be toggled ON/OFF for each tool
int gates[NUMBER_OF_TOOLS][NUMBER_OF_GATES] = {

 {1,0,0},
 {0,1,0},
 {0,0,1},   
};

const int dustCollectionRelayPin = 11;
const int manualSwitchPin = 12; //for button activated gate, currently NOT implemented

int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module
double ampThreshold = .20;

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

//button debouncing
int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup(){
  Serial.begin(9600);
  pinMode(dustCollectionRelayPin,OUTPUT);
  pwm.begin();
  pwm.setPWMFreq(60);  // Default is 1000mS
 
 //record baseline sensor settings
 //currently unused, but could be used for voltage comparison if need be.
  delay(1000);
  for(int i=0;i<NUMBER_OF_TOOLS;i++){
    pinMode(voltSensor[i],INPUT);
    voltBaseline[i] = analogRead(voltSensor[i]);
  }
 
}

void loop(){
  // use later for button debouncing
  reading = digitalRead(manualSwitchPin);

  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH){
      state = LOW;
     buttonTriggered = false;
    } else{
      state = HIGH;
     buttonTriggered = true;
    time = millis();   
    }
  }
  previous = reading;
   Serial.println("----------");
   //loop through tools and check
   int activeTool = 50;// a number that will never happen
   for(int i=0;i<NUMBER_OF_TOOLS;i++){
      if( checkForAmperageChange(i)){
        activeTool = i;
        exit;
      }
      if( i!=0){
        if(checkForAmperageChange(0)){
          activeTool = 0;
          exit;
        }
      }
   }
  if(activeTool != 50){
    // use activeTool for gate processing
    if(collectorIsOn == false){
      //manage all gate positions
      for(int s=0;s<NUMBER_OF_GATES;s++){
        int pos = gates[activeTool][s];
        if(pos == 1){
          openGate(s);   
        } else {
          closeGate(s);
        }
      }
      delay(2500);
 //delay added to allow gates to open before vacuum system comes on
      turnOnDustCollection();
    }
  } else{
    if(collectorIsOn == true){
        delay(DC_spindown);
      turnOffDustCollection(); 
    }
  }
}
boolean checkForAmperageChange(int which){
   Voltage = getVPP(voltSensor[which]);
   VRMS = (Voltage/2.0) *0.707;
   AmpsRMS = (VRMS * 1000)/mVperAmp;
   Serial.print(tools[which]+": ");
   Serial.print(AmpsRMS);
   Serial.println(" Amps RMS");
   if(AmpsRMS>ampThreshold){
    return true;
   }else{
    return false;
   }
}
void turnOnDustCollection(){
  Serial.println("turnOnDustCollection");
  digitalWrite(dustCollectionRelayPin,1);
  collectorIsOn = true;
}
void turnOffDustCollection(){
  Serial.println("turnOffDustCollection");
  digitalWrite(dustCollectionRelayPin,0);
  collectorIsOn = false;
}
 
float getVPP(int sensor)
{
  float result;
 
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;          // store min value here
 
   uint32_t start_time = millis();
   while((millis()-start_time) < 500) //sample for 1 Sec
   {
       readValue = analogRead(sensor);
       // see if you have a new maxValue
       if (readValue > maxValue)
       {
           /*record the maximum sensor value*/
           maxValue = readValue;
       }
       if (readValue < minValue)
       {
           /*record the maximum sensor value*/
           minValue = readValue;
       }
   }
   
   // Subtract min from max
   result = ((maxValue - minValue) * 5.0)/1024.0;
     
   return result;
 }

void closeGate(uint8_t num){
  Serial.print("closeGate ");
  Serial.println(num);
  pwm.setPWM(num, 0, gateMinMax[num][1]);
}
void openGate(uint8_t num){
  Serial.print("openGate ");
  Serial.println(num);
    pwm.setPWM(num, 0, gateMinMax[num][0]);
    delay(100);
    pwm.setPWM(num, 0, gateMinMax[num][0]-5);
}


On the line that says set the throw of the gate separately,if needed, What do the numbers actually represent? I have the servos working by using the original code and just changing the numbers. I know it isnt exactly right because one of the servos is getting hot. When I get done with the project, it will have 8 servos.I started doing the wiring yesterday. I have the brackets made for the servos. The only thing I need to finish is a little time and a explanation of the numbers for the servo position.
Hopefully I posted the code correctly this time.