Hello folks, I'm fresh new on the forum so please forgive if not properly using it. I used to code in C++ about 10 years ago, so I just realize I'm veeeeeery rusty.
I'm unsuccessfully trying to automate my dust collection blast gates integrated with dust collection system based on the following conditions:
- Blast gate after open(ON) and receives a close signal (OFF) should stay on for 15 seconds
- If the the power switched is on during the off countdown interval the signal pin (2) have to ON immediately.
I'm using milils function since delay won't meet condition #2
I'm looking for suggestions here even if have to take a total different approach.
This code is to read the state of an analog input and turns on output pin (2) to HIGH if the sensor voltage is more than 0.5V and delay for 15 seconds blast gates closing (off) when sensor senses less than 0.5V.
This controls pneumatic accutuators cilinders to open and close blast gates.
The Dust Collection engine has a contactor with delay off built-in which is set to delay 15 seconds after receiving a signal off (0V) on the contactor control pin which comes straight from the power tools with a current sensing relay which is the same one sending the 0.5V(ON) or 0V (off) signal or the (A0) on Arduino.
Arduino is only controling the blast gates. After (ON) if the voltage is lower than 0.5V, the Dust collection will run for 15 seconds and the blast gates have to stay open (on) for the same time.
Below is the code I'm using.
// Constants
const int tSawsense = A0; // pin that will sense the voltage from respective tool current sensing device
const int TableSaw = 2; // pin that signal to open (ON) or close (OFF) saw blast gate via BC-548 transistor
void setup() {
// initialize the pin 2 as an output:
pinMode(TableSaw, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the current sensing device:
int sensorValue = analogRead(tSawsense);
int currentMillis = millis();
int delaytime = 15000;
// Convert the analog reading
float voltage = sensorValue * (5.0 / 1023.0);
// if the analog value is bigger than 0.5V, open (ON) TableSaw blast gate.
if (voltage > 0.5) {
digitalWrite(TableSaw, HIGH);
} else {
currentMillis = millis();
delaytime = 15000;
if ( (millis() > ( currentMillis + delaytime))) {
digitalWrite(TableSaw, LOW);
}
}
// print out the voltage for monitoring purposes.Will be removed after code is working as expected.
Serial.println(voltage);
}