Linear Actuator run time

Hi Newbie Question

Does anyone know the correct way to set a linear actuator to run for a set time in seconds?

I hope to use a relay and mainly understand the code to set the relay between high and low but most examples shown are using a delay where as I want the actuator to run for a set time.

void loop()
{
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(2000); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off

digitalWrite(RELAY2,LOW); // Turns ON Relays 2
delay(2000); // Wait 2 seconds
digitalWrite(RELAY2,HIGH); // Turns Relay Off

digitalWrite(RELAY3,LOW); // Turns ON Relays 3
delay(2000); // Wait 2 seconds
digitalWrite(RELAY3,HIGH); // Turns Relay Off

digitalWrite(RELAY4,LOW); // Turns ON Relays 4
delay(2000); // Wait 2 seconds
digitalWrite(RELAY4,HIGH); // Turns Relay Off
}

Thanks
Andy

most examples shown are using a delay where as I want the actuator to run for a set time.

Using delay() will cause the program to pause for the delay period but will not affect the state of any outputs so what happens when you run your program ?

If the program must do other things whilst the actuator runs there are other techniques available. Have a look atUsing millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Hi

What I would like to do is run 5 linear actuators (already have a 16 relay board) when I press a button on a Nextion screen (not a physical button)for example

Actuator 1.Run for 6 seconds
Actuator 2.Run for 6 seconds
Actuator 3.Run for 3 seconds
Actuator 4.Run for 3 seconds
Actuator 5.Run for 3 seconds

I should be able to set up the pin connections from the arduino to the relay board and declare the pin values, then set them to outputs but because the actuators will only have a fully extended and fully retracted limit switches I would like to control the distance they move by time(seconds)

Thanks
Andy

You have not answered the question.
Do you want several motors to be turning at once or are you happy for only one to run and nothing respond to any key press until it has finished running.

most examples shown are using a delay where as I want the actuator to run for a set time.

You start the motor running, you delay for 1 second, then you stop the motor.

Hi Sorry

I would like all actuators to run at the same time.

Thanks
Andy

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

I hope to use a relay and mainly understand the code to set the relay between high and low but most examples shown are using a delay where as I want the actuator to run for a set time.

I think you are misreading the code you supplied.

 digitalWrite(RELAY1,LOW);           // Turns ON Relays 1
 delay(2000);                        // Wait 2 seconds
 digitalWrite(RELAY1,HIGH);          // Turns Relay Off

For example this section.

  • Turns the relay ON
  • Stops the code for 2000mS, the relay STAYS ON.
  • After 2000mS lets the code run.
  • Turns the relay OFF.

So the relay stays ON for 2000mS.

The problem with using delay() is that it STOPS the code, so NOTHING gets done.
Using millis as UKheliBob has linked for you, you can still get the same output, but the code keeps running, so it can do other processes.

Have you setup a controller, relay and tried some code?

Tom… :slight_smile:

Hi Tom

Thanks for the reply, I have just received my mega and relay board today so haven't tried anything yet I was just wanting to understand how to achieve this and then try writing some code so I would be ready when the rest of the equipment arrives (separate power supply for relay board and linear actuator).
The reason I want all actuators to work at the same time is I am going to try to control a platform which will tilt at angles.

Thanks
Andy

Hi Tom

Just looked over your post again, am I right in thinking then that the below code would run actuators 1 & 2 for 6 seconds but would on run actuators 3,4, 5 & 6 after actuators 1 & 2 have completed?.

digitalWrite(RELAY1,LOW); // Turns ON Relays 1
digitalWrite(RELAY2,LOW); // Turns ON Relays 2

delay(6000); // Wait 6 seconds

digitalWrite(RELAY1,HIGH); // Turns Relay Off
digitalWrite(RELAY2,HIGH); // Turns Relay Off

digitalWrite(RELAY3,LOW); // Turns ON Relays 3
digitalWrite(RELAY4,LOW); // Turns ON Relays 4
digitalWrite(RELAY5,LOW); // Turns ON Relays 5
digitalWrite(RELAY5,LOW); // Turns ON Relays 6

delay(3000); // Wait 3 seconds

digitalWrite(RELAY3,HIGH); // Turns Relay Off
digitalWrite(RELAY3,HIGH); // Turns Relay Off
digitalWrite(RELAY5,HIGH); // Turns Relay Off
digitalWrite(RELAY6,HIGH); // Turns Relay Off

Thanks
Andy

am I right in thinking then that the below code would run actuators 1 & 2 for 6 seconds but would on run actuators 3,4, 5 & 6 after actuators 1 & 2 have completed?.

Yes

If you want them all to start at the same time why not start them all, delay for 3 seconds then stop some, then delay another 3 seconds and stop the last two? It's crude but it might work.

OTOH using millis() is the proper way of doing this sort of thing. At some point you're almost bound to realise that you wanted the Arduino to be doing something or paying attention to something while the delays were forcing it to do nothing.

Steve

Hi Steve

Thanks for the suggestion

"If you want them all to start at the same time why not start them all, delay for 3 seconds then stop some, then delay another 3 seconds and stop the last two? It's crude but it might work."

I'm just a bit confused looking at using millis() as the platform will have 8 linear actuators and at last count about 14 different positions (each position will involve at least 3 actuators and maximum 5 actuators) so would this mean I would have to declare all the times(millis) needed for each position?.

Thanks
Andy

Hi,
How are you going to know the positions of the actuators?

What linear actuators are you getting and do you have a driver for them?

Tom.... :slight_smile:

Hi,
Are you making a Stewart platform?

Tom.. :slight_smile:

Hi Tom

I am going to use 12v high force linear actuators (no driver and only top and bottom limit switches) I am going to attempt to make a adjustable indoor putting green (google zen putting green). I thought once built I could time the actuators under load and use the results to alter the program. To get an initial reading I am going to take a 12' x 6' ply board and set at varying heights(angles)then record the % relative to height.
It all sounded so simple when I had the idea!!!!!!!!!

Oh by the way I believe the Zen green cost's circa 40k I was looking under 2k to build.

Thanks
Andy

To get an initial reading I am going to take a 12' x 6' ply board and set at varying heights(angles)then record the % relative to height.

And you want to do this every time you apply power to it?

I thought once built I could time the actuators under load and use the results to alter the program.

That will not work because you will not be able to measure the time / position accurately enough. Also you will find that the displacement of the actuators vs the time they are on is not a liner relationship.

Hi Tom

Plenty for me to think about, open to any suggestions/help on offer?

Thanks
Andy