Linear Actuator program

Hi, I’m working on a little project. I’m using a Linear Actuator. On the internet I found already a working program but I want the program starting if I push a button( a if command). I already tried to adjust to program but I can’t get it done. The program:

/* Sweep
by BARRAGAN <http://barraganstudio.com> 
This example code is in the public domain.

modified 8 Nov 2013
by Scott Fitzgerald
http://arduino.cc/en/Tutorial/Sweep
*/ 

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
               // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position 

void setup() 
{ 
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 

void loop() 
{ 
 for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees 
 {                                  // in steps of 1 degree 
   myservo.write(pos);              // tell servo to go to position in variable 'pos' 
   delay(15);                       // waits 15ms for the servo to reach the position 
 } 
 for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 
 {                                
   myservo.write(pos);              // tell servo to go to position in variable 'pos' 
   delay(15);                       // waits 15ms for the servo to reach the position 
 } 
}

I hope you can tell me how to make it work, thanks!
Data sheet: https://s3-us-west-1.amazonaws.com/firgellidownloads/PQ12+Datasheet.pdf
I’m using the servo version.

welcome !

we request that you read the post how to use this forum. it can be found as a post at the top of every forum.
real #7 about code tags.
then come back here, modify your post. bottom right of your post is the modify option.

also, post a link to the motor or anything you know about the motor like model number.

what type of motor is important. you selected a servo library. if the motor is not a servo, you might need something else.

many linear actuators use high voltage, and require relays. we need to understand what you have before we can offer any help.

Decide what should happen when you push the button. Should the actuator move while the button is pressed, or fully extend, or what else? Most probably you'll need more than one button.

You also need a 6V power supply. 5V may work as well, but the Arduino Vcc cannot provide enough current for driving the servo.

Thanks for your reply. If I push the button and let go, the loop needs to start. At almost full stroke and go back.

I already tested it with the 5V of the Arduino Vcc this works fine. I'm only need to add the if command.

See the StateChangeDetection example for handling buttons.

Simon_vs:
Thanks for your reply. If I push the button and let go, the loop needs to start. At almost full stroke and go back.

I already tested it with the 5V of the Arduino Vcc this works fine. I'm only need to add the if command.

Now you have added another condition. "At almost full stroke". How do you intend to discover this condition?

Paul

Hi,

Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

We need to see how you have wired your switches and configured you power supply.

Thanks.. Tom... :slight_smile:

TomGeorge:
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

We need to see how you have wired your switches and configured you power supply.

Here is the wire circuit:

Hi,
How are you powering the actuator.

Can you show all your wiring please, and ladel your wires as to what they are thanks.

Tom... :slight_smile:

Hi,
pinouts.jpg
A picture of your project would help to.
Tom… :slight_smile:

Hi, I only have a three wires,
1: the +, connected to the 5V output of the Arduino
2: the ground, connected to the ground of the Arduino
3: signal, connected to pin 9 of the Arduino

Hi,

Option R – RC Linear Servo WIRING: (see last page for pin numbering) 1 ‐ RC input signal (RC‐servo compatible) 2 ‐ Power (+6 VDC) 3 ‐ Ground Note: Reversing polarity on pins 2 and 3 may cause damage ‐R actuators are ideally suited to use in robotics and radio control models. The –R actuators or ‘linear servos’ are a direct replacement for regular radio controlled hobby servos. The desired actuator position is input to the actuator on lead 1 as a positive 5 Volt pulse width signal. A 2.0 ms pulse commands the controller to fully retract the actuator, and a 1.0 ms pulse signals it to fully extend. If the motion of the actuator, or of other servos in your system, seems erratic, place a 1–4Ω resistor in series with the actuator’s red V+ lead wire. The PQ12–R Linear Servos are designed to work with typical RC receivers and battery packs. Consequently they also are compatible with Arduino control boards, VEX Microcontrollers and many other similar boards designed for robotics.

What is the FULL part number of your actuator, do you have option R?

How are you powering the actuator.

Can you show all your wiring please, and label your wires as to what they are thanks.

It is not wise to use the 5V output of the arduino, it cannot supply the current needed, especially when you load the actuator up.

Tom... :slight_smile:
PS, Sorry I missed the Servo Version at the bottom of your original post.

TomGeorge:
Hi,What is the FULL part number of your actuator, do you have option R?
Yes I have the R-option: http://www.firgelli.com/Firgelli_Technologies_PQ12_R_p/pq12-r.htm

How are you powering the actuator.
I powering it with the 5V arduino. But I also bought a DC-DC Buck converter - Step-down(https://iprototype.nl/products/accessoires/power/dc-dc-boost-converter-step-down) But for me it works fine with the 5V arduino.

Can you show all your wiring please, and label your wires as to what they are thanks.

Hi,

But for me it works fine with the 5V arduino.

It will not be for the adruino, the on board linear 5V regulator is close to or being overloaded.
If you run your finger over some of the UNO components while running the actuator, you may feel it getting hot.

Did the program in its original version, before editing, work?

Tom... :slight_smile:

TomGeorge:
Did the program in its original version, before editing, work?
The program works fine, I only want to add a pushbutton.

What exactly is the pushbutton supposed to do?

aarg:
What exactly is the pushbutton supposed to do?

If the button is low, the loop needs to start

Something like this at the end of setup():

pinMode(buttonPin, INPUT_PULLUP);
while (digitalRead(buttonPin) == HIGH) {}

Yes, like that only the 'while' has to be 'if'. I already tried it but I can't get it worked.

Simon_vs:
Yes, like that only the 'while' has to be 'if'. I already tried it but I can't get it worked.

It works. It has worked for thousands of people. Post all your code inside code tags so we can see where you went wrong. An if statement will never work.