Coding arduino to control 3 pneumatic solenoids

Hello all!

First time poster here. Brand new to coding and can use some guidance on how to control 3 pneumatic solenoids. I built a machine and now I need to give it a brain and spent all day trying to learn coding on my own and think I should ask for some help.

I have 3 one-way pneumatic solenoids and need them to fire when I press a 12v switch in a specific order: 1) press momentary 12v switch 2) solenoid #1 fires for 4 seconds then retreats. 2) solenoid #2 waits 1 second after solenoid #1 fires, then it fires. 3) solenoid #3 waits 5 seconds after the switch is pressed then it fires for 1 second and retracts. 4) The entire process starts over again when the switch is pressed again.

Thank you much,
David

Also, why doesn't the upload button work? I'd like to attach a few photos. Thanks

One-way solenoids, does that mean spring return ?

For general guidance, look at controlling relays.

Yes, the solenoids are spring return. I should've mentioned that. Thanks


Bread board and Nano V3

Solenoids

Machine

Hello davida916

Post your sketch, well formated, with comments and in so called code tags "</>" and a none-Fritzing schematic to see how we can help.

Have a nice day and enjoy programming in C++ and learning.
MIND THE GAP

Hi Paul Paulson,

Thank you for replying.

If I'm being completely honest, I have no idea how to do any of that or what it even means. Can you point me to a tutorial so I can learn? I know how to control both strokes of the pneumatic cylinder with the solenoid but do not know how to write a code to control the timing. My initial post details the timing. I do not know how to write a sketch or schematic that includes the timing.

Thanks,
David

Hello David
Take a view here to get some ideas to have a kickoff for your project.

Keep it simple and stupid.
Run some tutorials to the hardware selected.
If you are happy with the results of the tutorials you can merge these to the project by using control structures.

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

Hi David:
It's great that you're trying to learn, but there's not much general purpose programming that can be learned in one day outside "how to do this one specific thing and never change it."

Have you considered using something like a Click PLC that can be programmed using ladder logic? PLCs were pretty much purpose designed for the kind of task that you're doing.

Alternately, there are some Arduino projects that do the same thing (ladder logic programming) but I don't have experience with them.

I'm not trying to be discouraging: if you want some pointers on what you're doing, we'd all be happy to help. But I feel that I should emphasize that learning to write useful programs isn't something that most people pick up quickly.

e.g., the sequence (not actual code) that you're programming goes something like

Wait for button press
Solenoid 1 on
delay(solenoid1 on time time);
Solenoid  1 off
delay(solenoid 2 time);
Solenoid 2 on
delay(solenoid 3 time)
Solenoid  3 on
delay(solenoid 3 on time)
Solenoid 3 off

You never mentioned when solenoid 2 goes off, BTW. There are better, general purpose ways of writing a sequence like this but the above is probably the simplest pattern to understand.

For actual code with a solenoid connected to a driver on pin 2 (you do have solenoid drivers connected, right?), and your pushbutton on pin 3 connected between pin 3 and GND, code might look like this to extend a solenoid for 4 seconds then retract:

void setup()
{
  pinMode(3, INPUT_PULLUP);
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);
}

void loop()
{
  while(digitalRead(3) == HIGH);
  digitalWrite(2, HIGH);
  delay(4000);
  digitalWrite(2, LOW);
}

Are the 12V solenoids AC or DC? How much current do the solenoids draw?
Post a datasheet or brand name & exact part number for the solenoids. Which Arduino will you use?

I wasn't able to find a data sheet on the generic solenoid but the model # is 4V210-08 DC 12V.

The solenoid is 12vdc and draws 300ma. I purchased a 12v 500ma (closest I could find) wall transformer and as soon as I connect the positive and negative wires to the solenoid's positive and negative terminals, it will redirect the pneumatic air to the opposite port, or in my case, fire the pneumatic cylinder. When I disconect the electrical signal, the pneumatic solenoid (spring return) automatically redirects the air to the opposite port and the pneumatic cylinder retracts.

So basically I just need to control the timing of the electrical signal that is sent to the solenoid for the pneumatic cylinder to fire and if I want the pneumatic cylinder to return to the closed position, the electrical signal would need to be interrupted.

I have an Arduino Nano v3. Would it work or should I purchase a newer model? The breadboard is quite large and I would like something that is compact and has a protective case so I don't accidentally damage it in my shop.

Thank you so much for the detailed reply.

I made a mistake and meant to say solenoid #2 retracts, not fires.

I've never heard of a Click PLC but will look into it right now.

I only have one momentary 12v electrical switch that will be connected to the entire board. Is that ok? This is the switch:

I haven't connected any pins yet but can certainly give it a go and let you know what happens.

That switch and your Nano will be fine. Your solenoids will need drivers since the Arduino isn't capable of supplying that much voltage or current. I used to sell driver modules along with solenoid valves, but I'm pretty much out of that business now.

Basically there two simple ways to approach driving the solenoids: wire up a driver chip on a perfboard or use an arduino relay board.

Some people will say that a relay board is overkill. I don't care: my time is worth more than the $7 difference between the two and the relay board is both easy to connect to the arduino and to the solenoids.

I also find that these screw terminal breakout boards for the Nano make things easier to connect. The terminals aren't the best quality, but it gets the job done.

HTH :slight_smile:

[edit]
An enclosure like this should fit everything: https://www.digikey.com/en/products/detail/bud-industries/PN-1324/387041

Digi-Key carries a lot of Arduino modules, so it's worth searching around to see if you can buy everything from them.

The relay board and breakout boards are a great idea and I will buy them now!

Quick question, the relay board says 5v and my solenoids need 12v 300ma, will this be compatible? Sorry, but I know absolutely nothing about electronics.

Dave

The enclosure from Digikey is perfect.

I get injured all the time in the shop and can only imagine how long an unprotected module would last. :smile:

relay board says 5v and my solenoids need 12v 300ma

That's fine. The 5V is the coil voltage that the relays need to actuate. They will be OK with your solenoid.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.