/* Halloween prop coded for Arduino Nano Every This is the pop-Up Prop Uses a PIR sensor to trigger the Halloween prop Input Pin 0 It has input for external GUI start from Photon Input Pin 3 It has a manual disable from a switch Input Pin 4 Relay 1 = Relay to initiate pneumatic piston Output Pin 6 Relay 2 = Relay to start the animation Output Pin 5 Modified 08 Feb 2021 */ /* Pin definitions */ int ledPin = 13; // LED connected to digital pin 13 int sensePin = 2; // Input pin D2 (for PIR sensor) int manualStart = 3; // Photon input to pin D3 for manual start int enablePin = 4; // input pin to disable prop code int relayPin1 = 6; // Output to Relay1 connected to digital pin 6 int relayPin2 = 5; // Output to Relay2 connected to digital pin 5 // Variable definitions int popup = 0; // variable to store the remote Start pin // We start, setting remote start disabled int sensed = 0; // variable to store if the PIR sensor 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 piston to start before initiating the prop animation const int event_done = 12250; //constant value for the delay to complete the entire animation sequence void setup() { pinMode(ledPin, OUTPUT); // sets the digital output pinMode(sensePin, INPUT); // declare sensePin as input pinMode(manualStart, INPUT); // sets the digital input pinMode(enablePin, INPUT); // sets the digital input pinMode(relayPin1, OUTPUT); // sets the digital output pinMode(relayPin2, OUTPUT); // sets the digital output Serial.begin(9600); } //*******************Initiate animation pnumatics********************* void animate() { digitalWrite(ledPin, HIGH); // LED on when sequence initiated digitalWrite(relayPin1, LOW); // Closes relay 1 to start pneumatic piston Serial.println("Relay 1 Closed"); Serial.println("Initiating Piston"); delay(hold); // delay to allow the piston to start before initiating the prop animation digitalWrite(relayPin2, LOW); // closes circuit to start the prop animation delay(100); // short delay to allow momentary relay closure Serial.println("Relay 2 Closed"); Serial.println("Initiating Prop Animation"); digitalWrite(relayPin2, HIGH); // Opens relay to assure only one animation cycle delay(event_done); // Wait for animation to complete // Finish sequence and reset prop digitalWrite(relayPin2, HIGH); // Make sure relay 2 is open - no animation Serial.println("Done"); delay(10); // delay for stability digitalWrite(relayPin1, HIGH); // Make sure relay 1 is open - piston retracted digitalWrite(ledPin, LOW); // LED off when sequence completed delay(100); //Let relay settle } //*******************Primary Loop********************* void loop() { enableOn = digitalRead(enablePin); // Read the disable switch sensed = digitalRead(sensePin); // Read the PIR sensor popup = digitalRead(manualStart); // read the manual start input pin 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"); animate(); } else if (popup == LOW) { // Check to see if manual sequence start initiated Serial.println("Manual start popup"); animate(); } /* Either sequence completed or no event detected and make sure relays are disabled */ digitalWrite(relayPin2, HIGH); // Make sure relay 2 is open - no animation Serial.println("None"); delay(10); // delay for stability digitalWrite(relayPin1, HIGH); // Make sure relay 1 is open - piston retracted digitalWrite(ledPin, LOW); // LED off when sequence completed delay(50); }