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
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
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?
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.
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?
OK, so I had a few free minutes and wanted an excuse to exercise my "Arduino PLC" setup
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.