#define E_STOP 3 // Connected to the Relay driving the E-STOP. #define ON_SWITCH 2 // Connected to the signal wires on the X-Carve. #define SMOKE_DETECTOR A0 // Connected to the Analog Out on the gas sensor #define VAC_OFF 10 // Channel 1 on the Vacuum Relay #define VAC_ON 9 // Channel 2 on the Vacuum Relay #define LED_PIN 12 // Super Bright LED to indicate that E-STOP has been triggered. void setup() { pinMode(VAC_ON, OUTPUT); pinMode(VAC_OFF, OUTPUT); pinMode(E_STOP, OUTPUT); // write LOW to power OFF digitalWrite(E_STOP, HIGH); // turn ON by default digitalWrite(VAC_OFF, HIGH); digitalWrite(VAC_ON, HIGH); pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); pinMode(ON_SWITCH, INPUT_PULLUP); } bool inputState = false; int smokeSensorValue = 0; void loop() { smokeSensorValue = analogRead(SMOKE_DETECTOR); delay(20); if(smokeSensorValue > 100) { digitalWrite(E_STOP, LOW); digitalWrite(LED_PIN, HIGH); // E-STOP! } bool switchOn = digitalRead(ON_SWITCH) == HIGH; if(inputState && !switchOn) { // Turn OFF for(int i = 0; i < 4; i++) { digitalWrite(VAC_OFF, LOW); delay(1000); digitalWrite(VAC_OFF, HIGH); delay(3000); } inputState = false; } else if(!inputState && switchOn) { // Turn ON for(int i = 0; i < 4; i++) { digitalWrite(VAC_ON, LOW); delay(1000); // hold the button down for 1 second. digitalWrite(VAC_ON, HIGH); delay(3000); // release the button and wait 3 seconds. } inputState = true; } }