Hi I'm new to this Forum and to the Arduino world.
I'm trying to automate the dust collection in mi woodshop.
I have 5 machines and for each a blast gate.
I have an Arduino UNO board.
5 ACS 712 20A current sensors.
5 DM996 servo moters.
The goal is to detect if a machine is on and then open the correct blast gate ans close the rest.
I don't want the blast gate to close when the machine stops.
GND and 5V is wired to external power.
I have wired 1 sensor to GND and 5V and the output to A0
I have wired 1 servo to GND and 5V and the input to pin 9
I have found code to read sensor output ant print it to "Serial.print( Amps_TRMSS1 )"
I have made code to controle the servo using angel 0-180.
I have made an " if (Amps_TRMSS2 >11) " to trigger the servo to open.
This all works super with just one sensor and on servo.
I want to wire all 5 machines and 5 servos to one Arduino board.
sensor 1: ACS_PinS1 - A0
sensor 2 : ACS_PinS2 - A1
sensor 3: ACS_PinS3 - A2
sensor 4: ACS_PinS4 - A3
sensor 5: ACS_PinS5 - A4
Servo 1: Servo myservoG1 - pin 9
Servo 2: Servo myservoG2 - pin 10
Servo 3: Servo myservoG3 - pin 11
Servo 4: Servo myservoG4 - pin 12
Servo 5: Servo myservoG5 - pin 13
I have code fore the 2 first machines and the both run fine when i loade the independently to the Arduino ONE bord.
Machine and gate 1
Code:
// Code for the 1. mashine and gate
/* This code works with ACS712 current sensor, it permits the calculation of the signal TRMS
* Visit www.surtrtech.com for more details
*/
#include <Filters.h> //This library does a massive work check it's .cpp file
#define ACS_PinS1 A0 //Sensor data pin on A0 analog input
float ACS_ValueS1; //Here we keep the raw data valuess
float testFrequency = 50; // test signal frequency (Hz)
float windowLength = 40.0/testFrequency; // how long to average the signal, for statistist
float intercept = 0; // to be adjusted based on calibration testing
float slope = 0.0752; // to be adjusted based on calibration testing
//Please check the ACS712 Tutorial video by SurtrTech to see how to get them because it depends on your sensor, or look below
float Amps_TRMSS1; // estimated actual current in amps
unsigned long printPeriod = 1000; // in milliseconds
// Track time in milliseconds since last reading
unsigned long previousMillis = 0;
// servo setup
#include <Servo.h>
Servo myservoG1; // create servo object to control a servo
Servo myservoG2;
int Open = 84;
int Close = 0;
void setup()
{
Serial.begin( 9600 ); // Start the serial port
pinMode(ACS_PinS1,INPUT); //Define the pin mode
myservoG1.attach(9); // attaches the servo on pin 9 to the servo object
myservoG1.write(Close);
myservoG2.write(Close);
}
void loop()
{
RunningStatistics inputStats; // create statistics to look at the raw test signal
inputStats.setWindowSecs( windowLength ); //Set the window length
while( true )
{
ACS_ValueS1 = analogRead(ACS_PinS1); // read the analog in value:
inputStats.input(ACS_ValueS1); // log to Stats function
if((unsigned long)(millis() - previousMillis) >= printPeriod)
{ //every second we do the calculation
previousMillis = millis(); // update time
Amps_TRMSS1 = intercept + slope * inputStats.sigma();
Serial.print( "\ Amps: " );
Serial.print( Amps_TRMSS1 );
}
if (Amps_TRMSS1 >11)
{
myservoG1.write(Open);
myservoG2.write(Close);
}
}
}
Machine and gate 2
Code:
// Code for the 2. mashine and gate
/* This code works with ACS712 current sensor, it permits the calculation of the signal TRMS
* Visit www.surtrtech.com for more details
*/
#include <Filters.h> //This library does a massive work check it's .cpp file
#define ACS_PinS2 A1 //Sensor data pin on A0 analog input
float ACS_ValueS2; //Here we keep the raw data valuess
float testFrequency = 50; // test signal frequency (Hz)
float windowLength = 40.0/testFrequency; // how long to average the signal, for statistist
float intercept = 0; // to be adjusted based on calibration testing
float slope = 0.0752; // to be adjusted based on calibration testing
//Please check the ACS712 Tutorial video by SurtrTech to see how to get them because it depends on your sensor, or look below
float Amps_TRMSS2; // estimated actual current in amps
unsigned long printPeriod = 1000; // in milliseconds
// Track time in milliseconds since last reading
unsigned long previousMillis = 0;
// servo setup
#include <Servo.h>
Servo myservoG1;
Servo myservoG2; // create servo object to control a servo
int Open = 84;
int Close = 0;
void setup()
{
Serial.begin( 9600 ); // Start the serial port
pinMode(ACS_PinS2,INPUT); //Define the pin mode
myservoG1.attach(9);
myservoG2.attach(10); // attaches the servo on pin 9 to the servo object
myservoG1.write(Close);
myservoG2.write(Close);
}
void loop()
{
RunningStatistics inputStats; // create statistics to look at the raw test signal
inputStats.setWindowSecs( windowLength ); //Set the window length
while( true )
{
ACS_ValueS2 = analogRead(ACS_PinS2); // read the analog in value:
inputStats.input(ACS_ValueS2); // log to Stats function
if((unsigned long)(millis() - previousMillis) >= printPeriod)
{ //every second we do the calculation
previousMillis = millis(); // update time
Amps_TRMSS2 = intercept + slope * inputStats.sigma();
Serial.print( "\ Amps: " );
Serial.print( Amps_TRMSS2 );
}
if (Amps_TRMSS2 >11)
{
myservoG1.write(Close);
myservoG2.write(Open);
}
}
}
My problem is when I try to run them in the same code
Here is my attempt to make them run one after another:
Code:
// Code for the 2. mashine and gate
/* This code works with ACS712 current sensor, it permits the calculation of the signal TRMS
* Visit www.surtrtech.com for more details
*/
#include <Filters.h> //This library does a massive work check it's .cpp file
#define ACS_PinS2 A1 //Sensor data pin on A0 analog input
float ACS_ValueS2; //Here we keep the raw data valuess
float testFrequency = 50; // test signal frequency (Hz)
float windowLength = 40.0/testFrequency; // how long to average the signal, for statistist
float intercept = 0; // to be adjusted based on calibration testing
float slope = 0.0752; // to be adjusted based on calibration testing
//Please check the ACS712 Tutorial video by SurtrTech to see how to get them because it depends on your sensor, or look below
float Amps_TRMSS2; // estimated actual current in amps
unsigned long printPeriod = 1000; // in milliseconds
// Track time in milliseconds since last reading
unsigned long previousMillis = 0;
// servo setup
#include <Servo.h>
Servo myservoG1;
Servo myservoG2; // create servo object to control a servo
int Open = 84;
int Close = 0;
void setup()
{
Serial.begin( 9600 ); // Start the serial port
pinMode(ACS_PinS2,INPUT); //Define the pin mode
myservoG1.attach(9);
myservoG2.attach(10); // attaches the servo on pin 9 to the servo object
myservoG1.write(Close);
myservoG2.write(Close);
}
void loop()
{
RunningStatistics inputStats; // create statistics to look at the raw test signal
inputStats.setWindowSecs( windowLength ); //Set the window length
while( true )
{
ACS_ValueS2 = analogRead(ACS_PinS2); // read the analog in value:
inputStats.input(ACS_ValueS2); // log to Stats function
if((unsigned long)(millis() - previousMillis) >= printPeriod)
{ //every second we do the calculation
previousMillis = millis(); // update time
Amps_TRMSS2 = intercept + slope * inputStats.sigma();
Serial.print( "\ Amps: " );
Serial.print( Amps_TRMSS2 );
}
if (Amps_TRMSS2 >11)
{
myservoG1.write(Close);
myservoG2.write(Open);
}
}
}