/* Halloween prop coded for Arduino Nano Every This is the Knight Prop with the Master Controller Uses a PIR sensor to trigger the Halloween prop (sensePin) It has input for external GUI start from Photon (manualStart) It has a manual disable from a switch (enablePin) Relay 1 = Relay to initiate pneumatic piston (relayPin) There is an output to knight prop to start it's animation sequence (startProp) There is an input that tell when the Knight animation has completed (propendPin) */ //Pin definitions int ledPin = 13; // LED connected to digital pin 13 int sensePin = 2; // Input pin (for PIR sensor) int relayPin = 5; // Output to Relay1 digital pin int startProp = 6; // Output to signal knights to start int manualStart = 3; // input from Photon for manual start int enablePin = 4; // input pin to enable prop code int propendPin = 7; // input signal when prop animation is done // Variable definitions int animate = 0; // variable to store the remote Start pin // We start, setting remote start disabled int sensed = 0; // variable to store if the PIR sensor (sensePin)detected. // We start, assuming no motion detected for sensor int enableOn = 0; // variable to store if the prop is enabled // We start, assuming prop is enabled // define some constants in the sequences const int hold = 400; //constant value delay to allow the arm motion //to finish void setup() { pinMode(ledPin, OUTPUT); // sets the digital output pinMode(relayPin, OUTPUT); // sets the digital output pinMode(startProp, OUTPUT); // sets the digital output pinMode(manualStart, INPUT_PULLUP); // sets the digital input pinMode(enablePin, INPUT); // sets the digital input pinMode(sensePin, INPUT); // declare sensePin as input Serial.begin(9600); } //*******************Initiate Arm pnumatics********************* void armMove() { digitalWrite(ledPin, HIGH); // Nano LED on when sequence initiated digitalWrite(startProp, LOW); // Send signal to knights to start the prop animation Serial.println("******** Initiating Prop Animation *********"); delay(100); // short delay to allow momentary relay closure digitalWrite(startProp, HIGH); // reset start pulse to knights delay(100); // short delay to allow knights to say Halt digitalWrite(relayPin, LOW); // Closes relay 1 to start pneumatic piston Serial.println("Relay Closed"); Serial.println("******** Initiating Piston *********"); delay(hold); // delay to allow the swords to finish while (digitalRead(propendPin) == LOW); {} // wait until knight animations are complete Serial.println("******** Prop Animation Completed *********"); /* Finish sequence and reset prop */ resetProp(); } //******************Prop Reset*************************** void resetProp() { digitalWrite(startProp, HIGH); // Make sure start output is reset - no animation Serial.println("********** Done ***********"); delay(10); // delay for stability digitalWrite(relayPin, HIGH); // Make sure relay is open - piston retracted digitalWrite(ledPin, LOW); // LED off when sequence completed delay(100); //Let relay settle } // ****************Main Loop************************** void loop() { enableOn = digitalRead(enablePin); // Read the disable switch sensed = digitalRead(sensePin ); // Read the PIR sensor animate = digitalRead(manualStart); // read the manual start input pin Serial.print("Manuale Start Pin state: "); Serial.println(animate); if (enableOn == HIGH) { // Check to see if we want to disable the prop Serial.println("************ STOP! *************"); delay(50); } else if (sensed == HIGH) { // Check to see if we detected someone Serial.println("Sensor Detection"); armMove(); } else if (animate == LOW) // Check to see if manual sequence start initiated { Serial.println("Manual start armMove"); armMove(); } /* Either sequence completed or no event detected and make sure relays are disabled */ resetProp(); }