Need help adding proximity switch protection to hydraulic cylinder actuation

Hello everybody,

Can somebody help me with the code below please?
It's a small program to control a hydrolic cilinder to operate it in and out.
1 Potmeter i use for the time/distance out,if the time/distance is reached it goes back in.
1 Potmeter for giving waitingtime to do the next cycle and so on.
I have done allot of reading forum's and projects to find out what i want.
Maybe its too difficult for a arduino starter like me......
The code below works but, what i want to do is put somekind of securety in with use of a proximity switch.
Like a reference too "see" when the cilinder is in.

Here the code
Regards everybody

int potPin1 = A0;      // select pin liftheight potmeter                               
int potPin2 = A1;      // select  pin wait potmeter                                
int potValue1 = 0;     // variable 
int relaisPin = 12;    // select pin  relais 12                                   
// int proxpin =10;       // select pin for proximity sensor       NEW
// int startbutton = 9;    // select pin to startup                    NEW


void setup() {
  
  pinMode(relaisPin, OUTPUT);     // declare relaispin OUTPUT
  pinMode(potPin1,    INPUT);     // declare 1 potmeter INPUT
  pinMode(potPin2,    INPUT);     // declare 2 potmeter INPUT
//  pinMode(proxpin,    INPUT);     //declare proxpin input       NEW
//  pinmode(startbutton, INPUT);    //declare startbutton         NEW
}

void loop() {
  
  potValue1 = analogRead(potPin1);   // 
  digitalWrite(relaisPin, HIGH);     // 
  delay(potValue1+50);               // 
  digitalWrite(relaisPin, LOW);      // 
  potValue1 = analogRead(potPin2);   // 
  delay(potValue1+150);              //  
}

Moderator edit: Real tags added

Moderator edit: Title made more meaningful (Nick Gammon)

1 Potmeter i use for the time/distance out,if the time/distance is reached it goes back in.

Is the potentiometer defining time or distance? Time and distance and not the same thing.

what i want to do is put somekind of securety in with use of a proximity switch.

And the problem is?

What is going to trigger the proximity switch? What is supposed to happen when that proximity switch is triggered?

For safety, these:
delay(potValue1+50); //
delay(potValue1+150); //
have got to go. You won't be able to read the proximity switch while the doNothingButHandleInterruptsForAWhile() call is happening.

Look at the blink without delay example.

Thank you for your replay,

It is the blink without delay example were i started with.
What i want with the prox switch is give a reference when the cilinder is in for the wait time potmeter to delay the next cycle.
I ám not sure if i must use a startbutton to startup the whole program.

regards

I suggest starting a simple sketch that uses the proximity switch to control an LED, then combining the proximity switch logic with what you have working.

A while ago I saw an Arduino sketch that uses Hall-effect sensors to control a pair of hydraulic rams in a compressed earth brick-making machine. The link I saved is CEB Press/Research Development/Controller Design - Open Source Ecology and you should be able to navigate from there to the source code. It may be helpful to see how someone else did that job successfully.

Edit: I just found the code. See http://opensourceecology.org/w/images/3/3a/CEBControl.ino

Thank you Morris,

I will studie again, if it's not clear to me you see me back here..

Regards

PaulS:

1 Potmeter i use for the time/distance out,if the time/distance is reached it goes back in.

Is the potentiometer defining time or distance? Time and distance and not the same thing.

The potmeter is defining time.

what i want to do is put somekind of securety in with use of a proximity switch.

And the problem is?

What is going to trigger the proximity switch? What is supposed to happen when that proximity switch is triggered?

For safety, these:
delay(potValue1+50); //
delay(potValue1+150); //
have got to go. You won't be able to read the proximity switch while the doNothingButHandleInterruptsForAWhile() call is happening.

Look at the blink without delay example.

please don't use title like "Real help asked!!!" or the forum will became less easy to consult

please don't use title like "Real help asked!!!"

Perhaps s/he is a member of the Spanish monarchy. :smiley:

Sorry,

Still looking for help....

Still looking for help....

With what?

I ám not sure if i must use a startbutton to startup the whole program.

If you're not sure what your requirements are, we can't impose them on you.

What i want is simple for me to discribe but very difficult to program.

I will control 1 hydraulic cilinder to go out and in.
1 potmeter i would use to control the time for steering the cilinder out.
afther this function the cilinder goes back in.
From that point when the cilinder is in, i will use the second potmeter for the delay/waiting time for the next cycle. And so on.

So far it works fine with the base program.

But i want to build in a i kind of securety with the proximity switch to know that the cilinder is in.
Afther that point de delay/wait potmeter has to do his work and start the cycle again.
And that's for me difficult to programm...

I hope that everybody understands what i want.

And that's for me difficult to programm...

Which part of that is difficult to program? Reading a switch state couldn't be simpler:

int switchVal = digitalRead(switchPin);

Depending on how you have wired the switch, the value is switchVal could be HIGH or LOW when the switch is pressed, and the opposite when not pressed.

You haven't told us diddly about how the switch is wired.

Doing something with the switch state is simple, too. All that is needed is an if statement and some curly braces.

The switchpin makes pin 10 high when it's pressed, or low when released.

You aren't providing enough information, so I'm going to make some assumptions about your design:
The hardware environment

  • relay-controlled electric hydraulic pump
  • relay-controlled hydraulic valve to control extend/retract
  • double-acting hydraulic cylinder
  • limit switches at both ends of cylinder travel

Given that context, the basic code structure can look like this:

#define InSw ?
#define OutSw ?    // Replace '?' with pin numbers
#define CylDir ?
#define CylPmp ?

#define RUN HIGH    // Pump motor relay
#define STOP LOW

#define EXTEND HIGH    // Valve relay control values
#define RETRACT LOW

void retract(void)
{  if (!digitalRead(InSw))
   {  digitalWrite(CylDir,RETRACT);
      digitalWrite(CylPmp,RUN);
      while (!digitalRead(InSw));
      digitalWrite(CylPmp,STOP);
   }
}

void extend(void)
{  if (!digitalRead(OutSw))
   {  digitalWrite(CylDir,EXTEND);
      digitalWrite(CylPmp,RUN);
      while (!digitalRead(OutSw));
      digitalWrite(CylPmp,STOP);
   }
}

void setup(void)
{  pinMode(InSw,INPUT);
   pinMode(OutSw,INPUT);

   pinMode(CylDir,OUTPUT);
   pinMode(CylPmp,OUTPUT);

   retract();
}

void loop(void)
{  extend();
   retract();
}

•relay-controlled electric hydraulic pump
•relay-controlled hydraulic valve to control extend/retract
•double-acting hydraulic cylinder
•limit switches at both ends of cylinder travel

First thanks for thinking with me!

The hydaulic pump pumps all the time.
So i don't need a relay to activate the pump this is regulated besides the arduino.
I only need the relay to activate the cilinder.
The cilinder goes automatical back in, because the cilinder is hanging vertical and lifts a weight that retracts the cilinder.
The reason that i need a proxswitch is to avoid dammage in the hydraulics.
The fuction of the proxswitch is to indicate that the cilinder is out/weight is down
from that point i will adjust the second potmeter for giving the time that the cilinder stays down just for some milliseconds.
the machine i will use for hammering steel sheetplates.

more questions replay please.

Ok - my final replay (best I can do with the info you've provided and the code you've shown):

#define InSw ?
#define OutSw ?
#define CylAct ?

#define ACTIVATE HIGH
#define DEACTIVATE LOW

void retract(void)
{  digitalWrite(CylAct,DEACTIVATE);    // Deactivate the cylinder
   if (!digitalRead(InSw))             // Nothing to do if already retracted
   {  
      // Code to allow reverse flow of hydraulic fluid from cylinder
      // so weight can retract cylinder by gravity while pump running (?)

      while (!digitalRead(InSw));      // Wait for retraction to complete
   }                                   //  end: If retraction needed
}                                      //  end: retract()

void extend(void)
{  if (!digitalRead(OutSw))            // Nothing to do if already extended
   {  digitalWrite(CylAct,ACTIVATE);   // Activate the cylinder
      while (!digitalRead(OutSw));     // Wait for full extension
      digitalWrite(CylAct,DEACTIVATE); // De-activate cylinder to allow retract
   }                                   //  end: If extension needed
}                                      //  end: extend()

void setup(void)
{  pinMode(InSw,INPUT);                // Retract limit switch
   pinMode(OutSw,INPUT);               // Extend limit switch
   pinMode(CylAct,OUTPUT);             // Cylinder activation (HIGH to extend)
   retract();                          // Prepare for operation
}                                      //  end: setup()

void loop(void)
{  extend();                           // Drive hammer to sheetplate
   
   // Code to perform actual hammering process (TBD)
   
   retract();                          // Retract hammer
}                                      //  end: loop()

cantore:
please don't use title like "Real help asked!!!" or the forum will became less easy to consult

Thread title amended.