Go Down

Topic: Automated Dust Collection (Read 4679 times) previous topic - next topic


Now that I changed the code, only one device is showing.
I2C scanner. Scanning ...
Found address: 65 (0x41)
Found 1 device(s).

But it still isnt working


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)
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.


Now that I changed the code, only one device is showing.
I2C scanner. Scanning ...
Found address: 65 (0x41)
Found 1 device(s).

But it still isnt working
Changed what code? Did you change something in the I2C Scanner code?


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


Should I start another post for help with the servos?


I have everything working except for the servo timing. Can someone help me with that?


Please post your latest code and describe what it is doing and how that differs from what you want.


{250,415},//DC right
  {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


//keep track of gates to be toggled ON/OFF for each tool
Can you also please explain this part of the code


Code: [Select]

 * This code is for the project at
 * http://www.iliketomakestuff.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 iliketomakestuff.com and modified by Terry Neal

Includes Modified version of "Measuring AC Current Using ACS712"

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*/

//keep track of gates to be toggled ON/OFF for each tool


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(){
  pwm.setPWMFreq(60);  // Default is 1000mS
 //record baseline sensor settings
 //currently unused, but could be used for voltage comparison if need be.
  for(int i=0;i<NUMBER_OF_TOOLS;i++){
    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;
   //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;
      if( i!=0){
          activeTool = 0;
  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){
        } else {
 //delay added to allow gates to open before vacuum system comes on
  } else{
    if(collectorIsOn == true){
boolean checkForAmperageChange(int which){
   Voltage = getVPP(voltSensor[which]);
   VRMS = (Voltage/2.0) *0.707;
   AmpsRMS = (VRMS * 1000)/mVperAmp;
   Serial.print(tools[which]+": ");
   Serial.println(" Amps RMS");
    return true;
    return false;
void turnOnDustCollection(){
  collectorIsOn = true;
void turnOffDustCollection(){
  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 ");
  pwm.setPWM(num, 0, gateMinMax[num][1]);
void openGate(uint8_t num){
  Serial.print("openGate ");
    pwm.setPWM(num, 0, gateMinMax[num][0]);
    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.

Go Up