I have been having some trouble with EMI in my setup caused by a variable frequency drive running. In an attempt to alleviate this issue I have tried to implement a debounce for the inputs.
I have a couple issues, first, when I first power up the arduino one of the output turns on with no button pressed (specifically the TS function runs as if TSI is LOW) after a couple of resets of the arduino the debounce seems to run correctly (I currently have it set to 1000ms so that I can confirm it is working)
Here is my code I removed all functions but 1 to stay in the limit
#include <Bounce2.h>
Bounce debouncerTSI = Bounce();
Bounce debouncerPLI = Bounce();
Bounce debouncerDPI = Bounce();
Bounce debouncerJLI = Bounce();
Bounce debouncerCBI = Bounce();
Bounce debouncerBI = Bounce();
Bounce debouncerSHI = Bounce();
// Initialize Inputs:
const int DPI = 22; //Drill Press
const int PLI = 23; //Planer
const int JLI = 24; //Jointer
const int CBI = 25; //Crescent Bandsaw
const int BI = 26; //Oliver Bandsaw
const int DCI = 27; //Dust collection
const int ACPI = 28; //Air Compressor
const int TI = 29; //No longer doing transformer on the arduino pin 29 is available
const int SHI = 30; // Oliver Shaper
const int TSI = 31; // Oliver Table Saw
// Intialize Outputs:
const int AC = 35; // Relay 1 Air Compressor
const int DC = 37; // Relay 2 Dust Collection
const int DP = 39; // Relay 3 Drill Press
const int PL = 41; // Relay 4 Planer
const int JL = 43; // Relay 5 Jointer
const int CB = 45; // Relay 6 Crescent Bandsaw
const int B = 47; // Relay 7 Oliver Bandsaw
const int VFD = 49; // Relay 8 VFD end switch
const int SH = 36; // Relay 9 Oliver Shaper
const int TS = 38; // Relay 10 Oliver Table Saw
const int T = 40; // No longer doing transformer on the arduino pin 40 available for output
const int EStop = 42; // Estop to VFD
const int SLed = 13; // stop function LED
// Variables that will change:
int DPIState = 0; // drill press switch state
int PLIState = 0; // planer switch state
int JLIState = 0; // jointer switch state
int CBIState = 0; // crescent bandsaw switch state
int BIState = 0; // oliver bandsaw switch state
int DCIState = 0; //manual dust collection button
int ACPIState = 0; // unsure of the use for this integer
//int TIState = 0; // Tranformer no longer needed so this variable is not needed
int ACState = 0; //air compressor input
int SHIState = 0; // shaper input state
int TSIState = 0; // Table Saw input state
unsigned long TimerDPON = 0;
unsigned long TimerDPOFF = 0;
unsigned long TimerPLON = 0;
unsigned long TimerPLOFF = 0;
unsigned long TimerJLON = 0;
unsigned long TimerJLOFF = 0;
unsigned long TimerCBON = 0;
unsigned long TimerCBOFF = 0;
unsigned long TimerBON = 0;
unsigned long TimerBOFF = 0;
unsigned long TimerSHON = 0;
unsigned long TimerSHOFF = 0;
unsigned long TimerTSON = 0;
unsigned long TimerTSOFF = 0;
//Intialize analog signals
unsigned long previousMillis = 0;
unsigned long interval = 10000;
void setup(){
//Drive all relays to High to begin
digitalWrite(T, HIGH);
digitalWrite(DC, HIGH);
digitalWrite(AC, HIGH);
digitalWrite(DP, HIGH);
digitalWrite(PL, HIGH);
digitalWrite(JL, HIGH);
digitalWrite(CB, HIGH);
digitalWrite(B, HIGH);
digitalWrite(VFD, HIGH);
digitalWrite(SH, HIGH);
digitalWrite(TS, HIGH);
digitalWrite(SLed, LOW); //Make sure the LED is turned off
// Pin Outputs to Ouputs
pinMode(T, OUTPUT);
pinMode(DC, OUTPUT);
pinMode(AC, OUTPUT);
pinMode(DP, OUTPUT);
pinMode(PL, OUTPUT);
pinMode(JL, OUTPUT);
pinMode(CB, OUTPUT);
pinMode(B, OUTPUT);
pinMode(VFD, OUTPUT);
pinMode(SH, OUTPUT);
pinMode(TS, OUTPUT);
pinMode(SLed, OUTPUT);
// Pin Inputs to Inputs:
pinMode(DPI, INPUT_PULLUP);
pinMode(PLI, INPUT_PULLUP);
pinMode(JLI, INPUT_PULLUP);
pinMode(CBI, INPUT_PULLUP);
pinMode(BI, INPUT_PULLUP);
pinMode(DCI, INPUT_PULLUP);
pinMode(ACPI, INPUT_PULLUP);
pinMode(TI, INPUT_PULLUP); // transformer input no longer needed for use on the arduino
pinMode(SHI, INPUT_PULLUP);
pinMode(TSI, INPUT_PULLUP);
debouncerTSI.attach(TSI);
debouncerTSI.interval(1000);
debouncerPLI.attach(PLI);
debouncerPLI.interval(1000);
debouncerDPI.attach(DPI);
debouncerDPI.interval(1000);
debouncerJLI.attach(JLI);
debouncerJLI.interval(1000);
debouncerCBI.attach(CBI);
debouncerCBI.interval(1000);
debouncerBI.attach(BI);
debouncerBI.interval(1000);
debouncerSHI.attach(SHI);
debouncerSHI.interval(1000);
}
void loop() {
debouncerTSI.update();
debouncerPLI.update();
debouncerDPI.update();
debouncerJLI.update();
debouncerCBI.update();
debouncerBI.update();
debouncerSHI.update();
TSIState = debouncerTSI.read();
PLIState = debouncerPLI.read();
DPIState = debouncerDPI.read();
JLIState = debouncerJLI.read();
CBIState = debouncerCBI.read();
BIState = debouncerBI.read();
SHIState = debouncerSHI.read();
DCIState = digitalRead(DCI);
ACPIState = digitalRead(ACPI);
ACState = digitalRead(AC);
drillpres();
planer();
jointer();
cbandsaw();
obandsaw();
shaper();
tablesaw();
}
void tablesaw(){
if (TSIState == LOW && BIState == HIGH && CBIState == HIGH && JLIState == HIGH && PLIState == HIGH && DPIState == HIGH && SHIState == HIGH) {
// turn Planer relay on and Turn on Inverter
unsigned long currentTSMillis = millis();
digitalWrite(DC, LOW);
digitalWrite(TS, LOW);
if (currentTSMillis - TimerTSON >= 1000){
digitalWrite(VFD, LOW);
TimerTSOFF = millis();
}
}
else if (DPIState == LOW || PLIState == LOW || JLIState == LOW || CBIState == LOW || BIState == LOW || SHIState == LOW){
}
else {
digitalWrite(VFD, HIGH);
unsigned long currentTSMillis = millis();
if (currentTSMillis - TimerTSOFF >= 20000){
digitalWrite(TS, HIGH);
digitalWrite(DC, HIGH);
TimerTSON = millis();
}
}
}
The second issue that I have (and I had this issue before putting in the debounce) is that when I shutdown one of the switches for instance TS my program should turn off VFD it should wait 20 secs then turn off the TS output and then the DC output. What actually happens is that the VFD turns off and the DC turns off right away and the program waits 20 secs and turns off TS output. I just can no figure out why/how this is happening.
Thanks in advance
Scott