Halloween Forum banner

1 - 6 of 6 Posts

·
Registered
Joined
·
49 Posts
Discussion Starter #1
Hello all,
Ive built an Air Cannon using a CO2 Fire extinguisher and air/water solenoid valve to control the release of compressed air. Using an Arduino, I want to trigger the solenoid for maybe 1 second ON then 1 Second off, for 3 bursts, then wait for 5 Mins, then start all over again.
I've found a code using millis for an LED without using the delay function, but how can I add the 5 Min wait at the end of the loop. Ive never programmed before using millis, Here is what I have come up with so far:

Code:
unsigned long interval = 1000; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long. 

bool ledState = false; // state variable for the LED 

void setup() { 
pinMode(13, OUTPUT); 
digitalWrite(13, ledState);
} 

void loop() { 
  unsigned long currentMillis = millis(); // grab current time 
   
  // check if "interval" time has passed (1000 milliseconds) 
  if ((unsigned long)(currentMillis - previousMillis) >= interval) {     
    ledState = !ledState; // "toggles" the state   
    digitalWrite(13, ledState); // sets the LED based on ledState   
// save the "current" time   previousMillis = millis();
unsigned long currentMillis = millis(); // grab current time 
   
  // check if "interval" time has passed (1000 milliseconds) 
  if ((unsigned long)(currentMillis - previousMillis) >= interval) {     
    ledState = !ledState; // "toggles" the state   
    digitalWrite(13, ledState); // sets the LED based on ledState   
// save the "current" time   previousMillis = millis();
unsigned long currentMillis = millis(); // grab current time 
   
  // check if "interval" time has passed (1000 milliseconds) 
  if ((unsigned long)(currentMillis - previousMillis) >= interval) {     
    ledState = !ledState; // "toggles" the state   
    digitalWrite(13, ledState); // sets the LED based on ledState   
// save the "current" time   previousMillis = millis();
 
  }
  }
  }
}
I WANT A 5 MIN WAIT AT THE END OF THIS LOOP, WHAT CODE LINE GETS WRITTEN ???????????????
Any ideas and help would be gratefully received.
 

·
Registered
Joined
·
318 Posts
You can just use the standard delay command like this delay(number of milliseconds). So if you want a 5 sec delay you would use delay(5000).
 

·
Registered
Joined
·
49 Posts
Discussion Starter #3 (Edited)
I have just written this code using delay, what do you think about the timing, too short or too long, every time the solenoid operates a burst of air is released. And I have an LED flood lamp connected in parallel so this will flash at the same time.


Code:
////////////////////////////////////////////////////////////////////////////////////


void setup()

{
  pinMode (3, OUTPUT); //Solenoid 1
  digitalWrite(3, HIGH); //turns solenoid ON
}
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
  //---( Turn solenoid ON in sequence)---
 
  digitalWrite(3, HIGH);// set the Solenoid ON
  delay(70); // wait for 0.07seconds
  digitalWrite(3, LOW);// set the Solenoid OFF
  delay(70); // wait for 0.07 seconds
  digitalWrite(3, HIGH);// set the Solenoid ON
  delay(70); // wait 0.07 Seconds
  digitalWrite(3, LOW);// set the Solenoid OFF
  delay(70); // wait for 0.07 seconds
  digitalWrite(3, HIGH);// set the Solenoid ON
  delay(70); // wait 0.07 Seconds
  digitalWrite(3, LOW);// set the Solenoid OFF
  delay(300000); // wait 5 Minutes see all relays OFF

}//--(end main loop )---

//*********( THE END )***********
Any feed back or thoughts will be greatly received. :D
 

·
Registered
Joined
·
74 Posts
I use an Arduino to control a pop up skull in a box. Same concept - surprise and startle em!

I have two suggestions. First, you need a trigger. A simple PIR will do it. Otherwise, the air cannon goes off when no one is around and doesn't go off when they are. Second, make the delay at the end random - say from one minute to three or four. Because it's random no one knows when it will re-arm and go off.

Search the forums for my posts. I posted complete code to do this last year. If you can't find it let me know.
 

·
Registered
Joined
·
49 Posts
Discussion Starter #5
Thanks for your input,
I can't use a PIR or any form of switch as it will be a Front Garden event, with the public standing on the Pavement (walkway) and admiring from a safe distance.
If I were to swop the last code line :

delay(300000); // wait 5 Minutes see all relays OFF

with this one

delay(random(180000, 360000)); // wait 3Min to 6Min random time, see all Solenoids OFF
will it have the desired effect? random time before re-firing and strobing would be anything between 3mins and 6mins. More importantly will it work?
 

·
Registered
Joined
·
74 Posts
That will give you a random delay.

While the controller may be set back from the sidewalk, why not run the PIR on a long cable? I do this for one of my props. The prop being controlled is 15' from the sidewalk. I run a long CAT 6 cable from the prop to the sensor. This is raw cable, used to wire jack in an office for example, not a patch cord. Any 3 conductor cable would work.
 
1 - 6 of 6 Posts
Top