Halloween Prop controller

Reading everything I can to learn to program Arduino UNO 3, but still find very confusing. I am a retired mechanical engineer 70 year old, so, ugh!, figuring out the language is difficult.
I want a simple Halloween prop. Arduino is to control 3 air pistons thru separate 12v solenoid valves. I will use relays from the arduino for the valves. Each valve programmed to open and close at different times. Also, it will start MP3 player, and one light. Needs only one trigger, either photo cell or PIR. I already have the software ready to start a sketch. Pretty simple. Or so it seems. Any advice?

Welcome to the community!

Say more about how the trigger enters into the picture.

Do you mean times of day, or durations? Are these to be random times (either way), do they start and stop other than the trigger?

Can multiple solenoids be on at once? Any relation between them?

What if trigger signals come piling in, are they ignored because you already started the MP3 or turned on the light?

I know, I know, a thousand questions.

There is nothing too hard about what it sounds like you are going for, but now is the time to get very detailed about exactly how this thing is to function.

You say you've made a start at the code, go ahead and fearlessly post it here, use the IDE Autoformat tool, copy the sketch and press the <CODE/> button in the message composition window tool bar and paste it where it says to do.

You will also benefit by making the software nearly perfect before you add any hardware. All the output devices can be coded with proxies. Use LEDs (or even just serial printing) instead of solenoids and other bits. Use a pushbutton at first what will become replaced by the sensor you choose. This will allow you to treat all the hardware issues you will have (!) separately, so you won't have many places to look for problems when doing each half.

As for the sensor, plan on using a simple example program you find, or write, that does nothing but read and report the sensor, so you can develop a feel for how it works. PIR, e.g., can really be frustrating if you don't realize how it is reporting, and what any adjustments it affords do to that reporting. Sometimes the sesnor can be just what you need, other times it will need a bit of software help to deliver the kind of trigger you want.

The solenoids will best be controlled using a logic level MOSFET transistor and a few other parts. There are ready built modules that are fine and save time and fiddling. Again, that can be done as a simple sketch first that just exercises the circuitry (or moduke) and gives you confidence that when transplanted to the big sketch, it will give you what you want in terms of switching them on and off.

Divide and conquer, work in steps, build from blocks you know are good.

You will need to provide power - it is best to plan on not taking power from the Arduino board at all, except maybe a few LEDs anyways. Don't forget your series current limiting resistors on the LEDs.

Have you worked through any of the examples on offer in the IDE? They start at a very basic level and it is a good idea to try a few things that have already been written, just to get your feet wet as is said.

This is the second Halloween project I've seen recently - usually ppl come here in a panic late in October, so good for you. We got plenty of time to get this going without too much stress.

a7

2 Likes

Why not control the solenoid valves with logic level MOSFETs instead of mechanical relays. Much more efficient and reliable.


MOSFET solenoid driver.

Pick a logic level MOSFET based on the current needed by the solenoid.

Thanks for your swift response. A lot of questions for me to answer, however I'm very busy getting ready to go to the NC mountains for a long weekend. I will provide more details when I get back Monday or Tuesday. While away, I hope I can find some time to study more.

If learning the C++-language is difficult or not depends on the explanation.
95% of all "learn to program explanations" on the internet are difficult to understand just because the quality of the explanations is so poor. In most cases caused by what I call the

experts blindness for beginner-difficulties.

Especially language references are really hard to understand. They just quote the definition.

To make an analogy with something mechanical:

Try to understand how a gearpump works by looking at the housing while still mounted on the electric motor.

So --- ... --- ... ehm what?

This is what programming language-references show. way too less information about the details.

This tutorial is easier to understand. Though depending on the knowledge you already have it might still be difficult.
Give it this tutorial a try and post your experience.

Arduino Programming Course

Depending on your answer if this tutorial was hard to understand or easy to understand or anything inbetween a well suited one can be chosen.

Another approach is to ask whatever questions about a single line of code here in the forum. Together with information about your knowledge-level an easy to understand explanation can be given.

With asking such questions such a thread can be the very special taylored to your needs tutorial to learn.

best regards Stefan

red1899

Welcome to the worldbest Arduino forum ever.

As an engineer, the first thing you should or can do is make a structured analysis of the task.

Take a piece of paper, a pencil and design, based on the IPO model, a program structure plan before start coding.
Identify functions and their depencies. Now start with coding and testing, function by function.
At the end merge all tested function together to get the final sketch.
The basics for coding the project are to be found in the IDE as examples.

Have a nice day and enjoy coding in C++.

p.s.

A picture is worth a thousand words.

grafik

Back from the NC Mountains, and I'm beat. Vacations are supposed to be relaxing, but the way I vacation, even in retirement, wears me out because we do so much crazy stuff!! But love it. Now, back to planning for Halloween. I have been doing Halloween "Wicked Woods" on my 6 acre property for several years for friends and friends of friends. The kids love it. Each year gets more complex. In the past I have used simple photo cells and PIR's to trigger air solenoid valves for air cylinders to move "things". With some, I had lights and sound tied into the trigger, but everything would trigger at the same time. I made all props work pretty well, but now looking to create something that will have "timed' movement.

Example: Zombie kneeling down eating brain. When someone walks near, they pass a photo cell (trigger/switch). Zombie raises up at the waist while a small light to illuminate is turned on. Then torso turns 90 degrees, then head turns about 90 degrees to look at the group. Then zombie voice says something. Then goes in reverse order back to kneeling. All movements, three, using air cylinders. There will be 2 to 5 people to go through the trail together. The first person will trigger the zombie. All in the group will be gone in about 10 to 20 seconds to continue walking through the trail. Each group goes through about 2 minutes apart. So, the program can reset after 45 seconds.

Power supply: 12v 5 amp (Amazon)

Solenoid valve: 230mA to 540mA depending on manufacturer. (You suggested mosfet for valve. I like the idea. How about IRLZ44N? Easily accessible, and inexpensive)

MP3: Cheap greeting card type (Amazon) that I can record whatever I want. I cut the push button switch off and use the arduino to switch on. I also cut the speaker off and use a small amp (Amazon) with larger speaker, 8 ohm, for more volume and better sound powered with the 12v power supply. Already tried that and works very well. I just need the arduino to turn it on.

Air cylinders: I make those from PVC pipe. With a small machine shop, lathe, etc., I can make plenty double acting cylinders.

Zombie: I will make the mechanical parts from mostly wood. I have some girls to help "decorate" the rest of the zombie.

Timing??
To keep programming easy, I am thinking I can time every action. I'll use seconds and not milliseconds for now. Fine tune later if needed.

  1. 0 seconds - Photo cell triggered: Light on - valve 1 opens
  2. 3 seconds - valve 2 (torso) opens
  3. 5 seconds - valve 3 (head) opens
  4. 6 seconds - voice activated ( I am eating!! Go away!!)
  5. 11 seconds - valve 3 closes
  6. 13 seconds - valve 2 closes
  7. 16 seconds - valve 1 closes (so mosfet will need to be on for 16 seconds)
  8. 18 seconds - light off
  9. 45 seconds - sequence reset, ready for next group

This should be relatively simple, but I need a good start since I am so new to this. I know it can be programmed to let one action complete, then go to the next action, but I am all about the kiss principle to keep things simple. If anything goes wrong, for me, it would be easier to ID the problem. Don't forget, I am an old school retired Mechanical engineer (worked at a Nuclear Station my whole career).

BTW, the cylinders have flow control valves where I can adjust the piston speed individually open and closed, so I can actually make the movements of the zombie overlap so it doesn't look too mechanical in its movements.

Good choice of logic level MOSFET.

Avoid using the delay() function for timing, especially if there are more than one thing going on at a time. Here are some tutorials on using millis() for timing.
Blink without delay().
Blink without delay detailed explanation
Beginner's guide to millis().
Several things at a time.

This may be a good place to use a state machine for programming the sequence and sequences within the sequence.

Haha, I was going to say with a brain-dead sequence of events like this, you could literally write the code line by line and use dealy() to make all the timing correct.

But yes, if @red1899 gets ambitious, that approach will some,y not work, and he will need to learn the correct way to handle timed events that remain smart and responsive.

a7

Great links you provided. Looks like I need to really understand State Machine. The example of garage door opener is somewhat helpful, but still confusing. I have a feeling I am going to have an "ah ha" moment at some point, but certainly not there yet. I hope I am not over-thinking this.

So, if I try to use the delay() function, that will not work because I have overlapping times for on-off commands, right? I
t looks like delay() will block other commands until the first one is finished. Right? or sort of right? Either way, looks like I need blink w/o delay.

While a delay() call is executing, the processor is not executing instructions, it is effectively stopped. It won't respond to inputs nor change outputs.

Are you aware of the Arduino reference for the Arduino specific functions?

You have a bunch of actions, never mind that some openings overlap some closings or whatever.

List the actions.Oh, yeah, already done!

Now figure out how much time it needs to wait between each action and the next. Like

Photo cell triggered:

  Light on - valve 1 opens
  wait 3 seconds - valve 2 (torso) opens
  wait 2 seconds - valve 3 (head) opens
  wait 1 seconds - voice activated ( I am eating!! Go away!!)
  wait 5 seconds - valve 3 closes
  wait 2 seconds - valve 2 closes
  wait 3 seconds - valve 1 closes (so mosfet will need to be on for 16 seconds). *Check*!
  wait 2 seconds - light off
  wait 27 seconds - ready for next group

Now it isn't hard to imagine when this literal approach won't work. The least deviation from a sequence of pre-planned fixed steps and times would tax this coding style beyond breaking.

Even just noticing that the group that triggered the sequence has moved on and prematuraly restetting for a more interested group to come would be a challenge.

I def encourage you to look into BWOD, and FSMs finite state machines, but this can be done with srsly dumb code.

Then all kindsa things that are not simple sequential fixed "shows" would be possible.

TBC I don't meant to say ppl would move on before you'd like. It sounds like you have a great deal of fun with this, and from my perspective you seem to be a master of the harder hardware part outside my pay area.

a7

Well, I am getting more confused. Just when I think I am on the right track, boom!!! It gets more complicated. I have viewed quite a number of YouTube videos (hours) for developing state machines / FSMs. Each time I watch one, it gets even more confusing. The language is something I have never seen. BTW, what is srsly dumb code? I tried to look it up but can't find anything, or is it obvious except to a mechanical engineer? I am leaning toward providing a single action from tripping the photo cell, and enter a time of 45 seconds so the photo cell will not re-trigger until the 45 seconds is up. Maybe hook up air to the cylinders in series from just one valve so that cylinders number 2 and 3 will actuate with a little delay.

Is code that does nothing more than digitalWrite()s to control stuff, and delay()s between them to time a sequence of events.

Here's turning on an LED, turning on another after two seconds, then turning them both off three seconds later, repeating every ten seconds. Tested!

# define theLED   6
# define theOtherLED  7
 
void setup()
{
  pinMode(theLED, OUTPUT);
  pinMode(theOtherLED, OUTPUT);
}

void loop()
{
  digitalWrite(theLED, HIGH);       // turn on the LED
  delay(2000);

  digitalWrite(theOtherLED, HIGH);  // turn on the other LED
  delay(3000);

  digitalWrite(theLED, LOW);        // turn off both LEDs
  digitalWrite(theOtherLED, LOW);
  delay(5000);
}

Place an LED with series limiting resistor between ground and pin 6.
Place an LED with series limiting resistor between ground and pin 7.

Totally dumb, totally inflexible and not a point of departure for anything fancier. Crude but effective if all you are doing is turning things on and off or whatever on a fixed schedule.

Put the entire sequence in an if statment that runs it if it sees PIR motion detect. For example.

HTH

a7

WOW!! It works! You made my day!! Worked on it in the middle of the night last night and got it working. Modified the sketch to include 5 LED's and timed each one the way I stated for the Halloween prop and they all go on and off timed the way I want. But, of course it repeats in the loop, so I am going to try the "if" like you suggested to see if I can trigger it on with a switch (photo cell or PIR). Plus stop it until the switch is triggered again. Need to stop it from going into the loop unless the "if" will prevent that. I hope I can figure "if" out.

I assume if I use a photo cell or PIR, it is equivalent to a simple on/off switch. I just want one cell / PIR to close contacts to start the sequence for all 5 LED's.

More or less. A good idea with any sensor like a PIR unit is to hook it up to simply report what it is telling you. Then you can tinker with any modes or adjustments the particular device you've chosen affords. While you have it in circumstances similar to, if not actually the, final intended deployment.

Do you have a PIR sensor? Post a part number or link to where you got it.

You may be able to adjust

  • delayTime, the number of seconds OUT pin will stay HIGH

  • inhibitTime, the number of seconds the sensor will ignore motion when OUT returns to LOW

and

  • retriggering, whether continuing motion will extend the HIGH.

Here, tested
# define sensorPin  3

void setup()
{
  Serial.begin(115200);
  Serial.print("\nhello world.\n");

  pinMode(sensorPin, INPUT);  // may need INPUT_PULLUP mode
}

void loop()
{
  if (digitalRead(sensorPin))
    Serial.println("               sensor reporting HIGH");
  else
    Serial.println("sensor reporting LOW");

  delay(250); // 4 times a second is plenty too much
}

You will maybe find that going blind with a delay at the end of the sequence for the remaining 27 seconds, or whatever it was, is fine. It just depends on when you think the next group might be coming by.

More clever code would reset itself after seeing a period where there was no motion. Then you'll begin to appreciate the need for"smarter" code.

a7

Been reviewing IF functions. In my case for the Halloween prop, looks a PIR will be the way to go. If I use a photo cell, it will act like a momentary on/off switch which will cause the 5 LEDs to go on on contact then off as soon as the contacts open. If using a PIR, the "if" coding will be relatively simple (I hope!!!). I think have some PIRs that can be adjusted from 10 seconds to 120 seconds... if I remember right. All I need is about 45 seconds closed contacts. Am I making any sense? I think I'm slowly beginning to have that ah ha moment, but don't want to get over my head. BTW, when I mention the 5 LED's, as you probably know, will be replaced with one light, 3 solenoid valves (thru mosfets), and one mp3 player. I'm just using LED's for now. I suppose that's a typical way of testing.

Once any motion is sensed, the body of the if statement guarding controlling the execution of your programmed sequence will cause that sequence to start.

Which, because it is very simple code, will pay absolutely no attention to the sensor for the entirety of the action/delay pattern you design.

The PIR signal could last as little as 0.1 seconds, less even, and it would work as a trigger just fine. no need for it to continue asserting anything, it is being ignored.

By the time the brain dead sequence has blindly finished, your group will have moved on, the sensor will (long) be back to reporting no motion, ready to detect the motion of the next guests.

Test this with a pushbutton you can read and use as the condition part of an if statement.

I think you can probably figure that out, if not, it is time to start where we all did, knowing little, and learn about pushbuttons, how to wire them and use the values you digitslRead() on the pins they are connected to.

There are some examples code in the IDE, and most any tutorial sequence or videos start with things like that.

I have to say again it is good that you are planning in August…

a7