Pneumatic press and limit switches

Hi i am trying to code my pad press machine that i have built with 2 cylinders. The first cylinder attached at 90 degree angle push the second cylinder attached with the pad back and forth, i have placed a limit switch on the closed position of cylinder 1 and limit switch 2 at the fully extended position of cylinder 1.

I basically want cylinder 2 to press down for 5 seconds at limit switch 1, then do another t seconds at limit switch 2

Hello jordysteinbach

Post a timing diagram to see what shall happens and a picture of the hardware setup.



Hi Paul

Thank you for your quick reply, i basically want the 'pad press' to press the pad on the plate for 5 seconds and then retract for 2 seconds, the second cylinder attached with the 2 limit switches needs to push the cylinder 1(the cylinder that presses down with the pad) to limit switch 2 and HOLD in this position, once in this position then cylinder 1 must press for 5 seconds, cylinder 1 retracts back for 2 seconds, and cylinder returns back to limit switch 1, repeat cycle

Hello jordysteinbach

Post your current program and a schematic too.

// define the pins for the limit switches
// let's use 6 and 7
# define lim_sw1 6
# define lim_sw2 7

int t; 

void setup() 
{
  pinMode(lim_sw1, INPUT_PULLUP);
  pinMode(lim_sw2, INPUT_PULLUP);
  
  if ((lim_sw1 == HIGH) && (lim_sw2 == HIGH))
  {
    // move cylinder 1 forward    
  }
  // stop moving cylinder 1
}

void loop() 
{
  if (lim_sw1 == HIGH)
  {
    // move cylinder 1 forward
  }
  
  // stop moving cylinder 1
  // move cylinder 2 down
  delay (5000); // wait 5 seconds
  // move cylinder 2 up

  if (lim_sw2 == HIGH)
  {
    // move cylinder 1 backwards
  }
  
  // stop moving cylinder 1
  // move cylinder 2 down
  delay (t); // wait t seconds
  // move cylinder 2 up

  delay (5000); // wait 5 second before repeating
}

Thank you, i have uploaded the code but its not doing anything, i see you have allocated pin 6 and 7 to limit swit hes, how do i now add in the pins for the cylinders?

What are the elecrical connections for the cylinders?


I basically need the code added to control the moment of the cylinders

This what chat gpt says

I know nothing about your cylinders or how to move them

Iasked chat gpt to add in the cylinder movements and this what it created, does this look right?

Arduino cannot directly drive valves, what is the valve's voltage (AC or DC) and current rating? Which Arduino output pins are switching the valves?

Sorry, @jordysteinbach, I can't use your words and photos to make any sense of the mechanism nor the mechanical process you wish to perform.

And I gotta say, chatGPT is not your friend. Unless you can meet it way more than halfway with specifications for the outcome you seek, it will waste more of your time and ours than just figuring it out with help here from regular humans.

Lastly, no screen shots, please!

Use the <CODE> tool in the message composition window. You will get this

type or paste code here

and you should cut and paste your code there where it says.

a7

You apparently gave chat more information about the cylinders than you gave me, so I have no way of knowing.

Also I have a hard time reading a photo of a display

Okay thank you, will do

Hi, @jordysteinbach

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Have you written code JUST to prove you have control of your cyclinders?

Thanks... Tom... :smiley: :+1: :coffee: :australia:

OK, so I had a few free minutes and wanted an excuse to exercise my "Arduino PLC" setup :slight_smile:
These things are basically an Uno clone with built in relays/FETs and optically isolated inputs. Perfect for what you're doing (although you already have hardware).

I did not use the limit switches since this is a quick fun program and I don't want to go rummaging around for air cylinders and solenoid valves, plus deal with hooking up my compressor.

So that excuse out of the way...


#include <Wire.h> 
//#include <LiquidCrystal_I2C.h>

// set the LCD address to 0x27 for a 16 chars and 2 line display
//LiquidCrystal_I2C lcd(0x27,16,2);  

// *********************************** U S E R  A D J U S T M E N T S **************************
// One shot time in milliseconds
const int DELAY_MS = 6000;
// *********************************************************************************************

const int INTERVAL_MS = 100;
const int TIME1_MS = 5000;
const int TIME2_MS = 2000;

const bool OUTPUT_ON = false;
const bool OUTPUT_OFF = true;

// X0 is input
const int TRIGGER_PIN = 8;

const int LIMIT1_PIN = 6;
const int LIMIT2_PIN = 7;

// Y0 is output
const int CYLINDER1_PIN = 9 ;
const int CYLINDER2_PIN = 10 ;


void setup() 
{
    pinMode(TRIGGER_PIN, INPUT_PULLUP);
    pinMode(LIMIT1_PIN, INPUT_PULLUP);
    pinMode(LIMIT2_PIN, INPUT_PULLUP);
    
    pinMode(CYLINDER1_PIN, OUTPUT);
    digitalWrite(CYLINDER1_PIN, OUTPUT_OFF);

    pinMode(CYLINDER2_PIN, OUTPUT);
    digitalWrite(CYLINDER2_PIN, OUTPUT_OFF);

    //lcd.init();
    // Print a message to the LCD.
    //lcd.backlight();
    //printStatus("Cylinders UP", 0);
}

void loop() 
{
    // One shot triggers on high->low transition of TRIGGER pin
    while (digitalRead(TRIGGER_PIN) == HIGH)
    {
        // Hold while pin not pressed
    } 

    // Activate output and start timing
    // Retract cylinder 1
    digitalWrite(CYLINDER1_PIN, OUTPUT_OFF);   
    // Give it time to retract
    delay(100);
    // Check input
      while(digitalRead(LIMIT1_PIN) == HIGH);

    // Print
    CyclePad(TIME1_MS);

    // Extend cylinder 1
    digitalWrite(CYLINDER1_PIN, OUTPUT_ON);   
    // Give it time
    delay(200);
    // Should probably do this to read limit
     while(digitalRead(LIMIT2_PIN) == HIGH);
    
    // Print
    CyclePad(TIME2_MS);
}

void CyclePad(int timeout)
{
    // Extend cylinder 2
    digitalWrite(CYLINDER2_PIN, OUTPUT_ON);   
    
    // Hold output High until timeout 
    while ((timeout-= INTERVAL_MS) > 0)
    {
        //printStatus("Cylinder 2 down", timeout);
        delay(INTERVAL_MS);
    }
    //printStatus("Cylinder 2 up  ", 0);

    // Retract cyclinder2
    digitalWrite(CYLINDER2_PIN, OUTPUT_OFF);   
    // Give it time to retract
    delay(200);
    // Update display
    //printStatus("Cycle done", 0);
}

I actually made a video and now I can't sign into YouTube to upload it...

Anyway, HTH. I had to remove all references to the LCD display since you don't have one, but hopefully this is helpful.

[update]
Here's the video: z cylinder - YouTube